im too tired to remember what i did

This commit is contained in:
2024-11-21 22:12:25 +01:00
parent 2c7a2dcad3
commit 94075b92f1
5 changed files with 34 additions and 151 deletions
@@ -59,8 +59,8 @@ class Bde_particles : ModInitializer {
fun init() { fun init() {
addToEmitterRegister("DEFAULT", ParticleEmitterParams.DEFAULT) addToEmitterRegister("DEFAULT", EmitterParams.DEFAULT)
addToEmitterRegister("FIRE_GEYSER", ParticleEmitterParams.FIRE_GEYSER) addToEmitterRegister("FIRE_GEYSER", EmitterParams.FIRE_GEYSER)
} }
@@ -95,7 +95,7 @@ fun onRightClick(player: PlayerEntity, world: ServerWorld, hand: Hand) : TypedAc
} }
fun emitterParamsToJson(params: ParticleEmitterParams) : Map<String, Any> { fun emitterParamsToJson(params: EmitterParams) : Map<String, Any> {
val allParticleParamsJSON: MutableList<Map<String, Any?>> = mutableListOf() val allParticleParamsJSON: MutableList<Map<String, Any?>> = mutableListOf()
for (particle in params.particleTypes) { for (particle in params.particleTypes) {
@@ -132,7 +132,7 @@ fun emitterParamsToJson(params: ParticleEmitterParams) : Map<String, Any> {
} }
fun jsonToEmitterParams(json: Map<String, Any>): ParticleEmitterParams { fun jsonToEmitterParams(json: Map<String, Any>): EmitterParams {
val particleTypes = json["particleTypes"] as? List<*> val particleTypes = json["particleTypes"] as? List<*>
?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams") ?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams")
@@ -161,12 +161,12 @@ fun jsonToEmitterParams(json: Map<String, Any>): ParticleEmitterParams {
allParticleTypes.add(updatedParticle) allParticleTypes.add(updatedParticle)
} }
val params = ParticleEmitterParams( val params = EmitterParams(
maxCount = (json["maxCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.maxCount, maxCount = (json["maxCount"] as? Int) ?: EmitterParams.DEFAULT.maxCount,
spawnsPerTick = (json["spawnsPerTick"] as? Int) ?: ParticleEmitterParams.DEFAULT.spawnsPerTick, spawnsPerTick = (json["spawnsPerTick"] as? Int) ?: EmitterParams.DEFAULT.spawnsPerTick,
loopDur = (json["loopDur"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDur, loopDur = (json["loopDur"] as? Int) ?: EmitterParams.DEFAULT.loopDur,
loopDelay = (json["loopDelay"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDelay, loopDelay = (json["loopDelay"] as? Int) ?: EmitterParams.DEFAULT.loopDelay,
loopCount = (json["loopCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopCount, loopCount = (json["loopCount"] as? Int) ?: EmitterParams.DEFAULT.loopCount,
particleTypes = allParticleTypes.toTypedArray() particleTypes = allParticleTypes.toTypedArray()
) )
@@ -6,6 +6,11 @@ import com.bytedice.bde_particles.particle.*
import com.bytedice.bde_particles.stringToMap import com.bytedice.bde_particles.stringToMap
import com.mojang.brigadier.Command import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.ArgumentType
import com.mojang.brigadier.arguments.BoolArgumentType
import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.arguments.IntegerArgumentType
import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.LiteralArgumentBuilder
import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder
@@ -21,8 +26,13 @@ import net.minecraft.text.MutableText
import net.minecraft.text.Style import net.minecraft.text.Style
import net.minecraft.text.Text import net.minecraft.text.Text
import net.minecraft.text.TextColor import net.minecraft.text.TextColor
import org.joml.Vector2f
import org.joml.Vector3f
import java.awt.Color import java.awt.Color
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import kotlin.reflect.KProperty1
import kotlin.reflect.KType
import kotlin.reflect.full.memberProperties
// ManageEmitters // ManageEmitters
@@ -36,20 +46,15 @@ import java.util.concurrent.CompletableFuture
// [emitter id] // [emitter id]
// output -> removes the particle with that id // output -> removes the particle with that id
// config // config // TODO: find a way to make this remotely feasible
// [emitter id] // [emitter id]
// <[particle index] / EMITTER> // <[particle index] / EMITTER>
// <single param / JSON> // single param (if EMITTER, use emitter params instead)
// single param (if EMITTER, use emitter params instead) // TODO
// [param key] // [param key]
// [new param value] // [new param value]
// output -> update the selected parameter of the selected emitter id to the new value // output -> update the selected parameter of the selected emitter id to the new value
// JSON
// [new params] (unspecified values is treated as current)
// output -> parse the JSON and update all params
// list // list
// output -> all registered emitters // output -> all registered emitters
@@ -68,7 +73,6 @@ object ManageEmitters {
// <create / remove / config / list / copy> // <create / remove / config / list / copy>
.then(argCreate()) .then(argCreate())
.then(argRemove()) .then(argRemove())
.then(argConfig())
.then(argList()) .then(argList())
.then(argCopy()) .then(argCopy())
) )
@@ -155,68 +159,6 @@ fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
} }
// config
// [emitter id]
// <[particle index] / EMITTER>
// <single param / JSON>
// single param (if EMITTER, use emitter params instead)
// [param key]
// [new param value]
// output -> update the selected parameter of the selected emitter id to the new value
// JSON
// [new params] (unspecified values is treated as current)
// output -> parse the JSON and update all params
fun argConfig() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("config")
.then(
// [emitter id]
emitterIdSuggestion
.then(
// <[particle index] / EMITTER>
makeIndexSuggestion()
// <single param / JSON>
//.then(argSingleParam())
.then(argJson())
)
)
}
/*
fun argSingleParam() {
CommandManager.literal("SingleParam")
.then(
// [param key]
)
}
*/
fun argJson() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("JSON")
.then(
// [new params]
CommandManager.argument("JSON Value", StringArgumentType.string())
.executes { context ->
val jsonString = StringArgumentType.getString(context, "JSON Value")
val jsonMap = stringToMap(jsonString)
val jsonParams = jsonToEmitterParams(jsonMap)
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID")
updateEmitterParams(emitterIdVal, jsonParams)
val feedback = Text.literal("BPS - Updated parameters of Emitter ID \"$emitterIdVal\"!\n")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb)))
Command.SINGLE_SUCCESS
}
)
}
fun argList() : LiteralArgumentBuilder<ServerCommandSource> { fun argList() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("list") return CommandManager.literal("list")
.executes { context -> .executes { context ->
@@ -293,60 +235,3 @@ fun makeCommandBlock(emitterData: Map<String, Any>): ItemStack {
return i return i
} }
fun makeIndexSuggestion() : RequiredArgumentBuilder<ServerCommandSource, String> {
return CommandManager.argument("Particle Index", StringArgumentType.string())
.suggests { context, builder ->
val emitterParams = getEmitterParams(StringArgumentType.getString(context, "Registered Emitter ID"))!!
val suggestionsBuilder = SuggestionsBuilder(builder.remaining, 0)
emitterParams.particleTypes.indices.forEach { i ->
suggestionsBuilder.suggest(i.toString())
}
suggestionsBuilder.suggest("EMITTER")
CompletableFuture.completedFuture(suggestionsBuilder.build())
}
}
/*
fun paramSuggestion(particleIndex: Int, emitterId: String) : RequiredArgumentBuilder<ServerCommandSource, String> {
val emitterParams = getParticleEmitterParams(emitterId)
val particleParams = if (emitterParams?.particleTypes!!.isNotEmpty()) {
emitterParams.particleTypes[particleIndex]
}
else { null }
val emitterProperties = emitterParams::class.memberProperties
val emitterPropertyNames: MutableList<String> = mutableListOf()
val emitterPropertyTypes: MutableList<KType> = mutableListOf()
var particleProperties: Collection<KProperty1<out ParticleParams, *>>? = null
if (particleParams != null) {
particleProperties = particleParams::class.memberProperties
}
if (particleIndex != -1) {
for (property in emitterProperties) {
emitterPropertyNames.add(property.name)
emitterPropertyTypes.add(property.returnType)
}
}
else if (particleProperties != null) {
for (property in particleProperties) {}
}
//
return CommandManager.argument("Param Key", StringArgumentType.string())
.suggests { context, builder ->
val suggestionsBuilder = SuggestionsBuilder(builder.remaining, 0)
CompletableFuture.completedFuture(suggestionsBuilder.build())
}
}
*/
@@ -1,9 +1,7 @@
package com.bytedice.bde_particles.particle package com.bytedice.bde_particles.particle
import org.joml.Vector3f
/** /**
* ParticleEmitterParams defines the parameters for controlling how particles are emitted, * EmitterParams defines the parameters for controlling how particles are emitted,
* including settings for looping, spawn frequency, and maximum particle count. * including settings for looping, spawn frequency, and maximum particle count.
* *
* @param maxCount The maximum number of particles that can exist. If set to 0 or below, no particles will spawn. * @param maxCount The maximum number of particles that can exist. If set to 0 or below, no particles will spawn.
@@ -13,7 +11,7 @@ import org.joml.Vector3f
* @param loopCount The number of times the loop will repeat. 0 means it will shoot a single burst of particles. A value below 0 means it will repeat indefinitely. * @param loopCount The number of times the loop will repeat. 0 means it will shoot a single burst of particles. A value below 0 means it will repeat indefinitely.
* @param particleTypes An array of `ParticleParams` defining the types of particles to spawn. If empty, no particles will spawn. * @param particleTypes An array of `ParticleParams` defining the types of particles to spawn. If empty, no particles will spawn.
*/ */
data class ParticleEmitterParams ( data class EmitterParams (
val maxCount: Int = 200, val maxCount: Int = 200,
val spawnsPerTick: Int = 2, val spawnsPerTick: Int = 2,
val loopDur: Int = 25, val loopDur: Int = 25,
@@ -23,8 +21,8 @@ data class ParticleEmitterParams (
) )
{ {
companion object Presets { companion object Presets {
val DEFAULT = ParticleEmitterParams() val DEFAULT = EmitterParams()
val FIRE_GEYSER = ParticleEmitterParams( val FIRE_GEYSER = EmitterParams(
200, 200,
1, 1,
25, 25,
@@ -3,7 +3,7 @@ package com.bytedice.bde_particles.particle
import net.minecraft.server.world.ServerWorld import net.minecraft.server.world.ServerWorld
import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3d
class ParticleEmitter(private val emitterPos: Vec3d, private val emitterWorld: ServerWorld, private val emitterParams: ParticleEmitterParams) { class ParticleEmitter(private val emitterPos: Vec3d, private val emitterWorld: ServerWorld, private val emitterParams: EmitterParams) {
private var allParticles: Array<Particle> = emptyArray() private var allParticles: Array<Particle> = emptyArray()
@@ -1,10 +1,10 @@
package com.bytedice.bde_particles.particle package com.bytedice.bde_particles.particle
val emitterIdRegister: MutableMap<String, ParticleEmitterParams> = mutableMapOf() val emitterIdRegister: MutableMap<String, EmitterParams> = mutableMapOf()
val forbiddenIds = arrayOf("", "DEFAULT", "NULL") val forbiddenIds = arrayOf("", "DEFAULT", "NULL")
fun addToEmitterRegister(id: String, params: ParticleEmitterParams) : Pair<String, Boolean> { fun addToEmitterRegister(id: String, params: EmitterParams) : Pair<String, Boolean> {
val newId = id.replace(" ", "_") val newId = id.replace(" ", "_")
if (newId in forbiddenIds && newId != "DEFAULT") {return Pair(newId, false) } if (newId in forbiddenIds && newId != "DEFAULT") {return Pair(newId, false) }
@@ -24,11 +24,11 @@ fun removeFromEmitterRegister(id: String) : Boolean {
} }
fun getEmitterParams(id: String) : ParticleEmitterParams? { fun getEmitterParams(id: String) : EmitterParams? {
return emitterIdRegister[id] return emitterIdRegister[id]
} }
fun updateEmitterParams(id: String, newParams: ParticleEmitterParams) { fun updateEmitterParams(id: String, newParams: EmitterParams) {
emitterIdRegister[id] = newParams emitterIdRegister[id] = newParams
} }