From 94075b92f14c933ce8c1a187fc55dca0dfef3f1b Mon Sep 17 00:00:00 2001 From: ByteDice Date: Thu, 21 Nov 2024 22:12:25 +0100 Subject: [PATCH] im too tired to remember what i did --- .../bytedice/bde_particles/Bde_particles.kt | 20 +-- .../bde_particles/commands/ManageEmitters.kt | 145 ++---------------- ...ticleEmitterParams.kt => EmitterParams.kt} | 10 +- .../bde_particles/particle/ParticleEmitter.kt | 2 +- .../particle/particleIdRegister.kt | 8 +- 5 files changed, 34 insertions(+), 151 deletions(-) rename src/main/kotlin/com/bytedice/bde_particles/particle/{ParticleEmitterParams.kt => EmitterParams.kt} (85%) diff --git a/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt b/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt index b0f9601..960db86 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt @@ -59,8 +59,8 @@ class Bde_particles : ModInitializer { fun init() { - addToEmitterRegister("DEFAULT", ParticleEmitterParams.DEFAULT) - addToEmitterRegister("FIRE_GEYSER", ParticleEmitterParams.FIRE_GEYSER) + addToEmitterRegister("DEFAULT", EmitterParams.DEFAULT) + addToEmitterRegister("FIRE_GEYSER", EmitterParams.FIRE_GEYSER) } @@ -95,7 +95,7 @@ fun onRightClick(player: PlayerEntity, world: ServerWorld, hand: Hand) : TypedAc } -fun emitterParamsToJson(params: ParticleEmitterParams) : Map { +fun emitterParamsToJson(params: EmitterParams) : Map { val allParticleParamsJSON: MutableList> = mutableListOf() for (particle in params.particleTypes) { @@ -132,7 +132,7 @@ fun emitterParamsToJson(params: ParticleEmitterParams) : Map { } -fun jsonToEmitterParams(json: Map): ParticleEmitterParams { +fun jsonToEmitterParams(json: Map): EmitterParams { val particleTypes = json["particleTypes"] as? List<*> ?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams") @@ -161,12 +161,12 @@ fun jsonToEmitterParams(json: Map): ParticleEmitterParams { allParticleTypes.add(updatedParticle) } - val params = ParticleEmitterParams( - maxCount = (json["maxCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.maxCount, - spawnsPerTick = (json["spawnsPerTick"] as? Int) ?: ParticleEmitterParams.DEFAULT.spawnsPerTick, - loopDur = (json["loopDur"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDur, - loopDelay = (json["loopDelay"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDelay, - loopCount = (json["loopCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopCount, + val params = EmitterParams( + maxCount = (json["maxCount"] as? Int) ?: EmitterParams.DEFAULT.maxCount, + spawnsPerTick = (json["spawnsPerTick"] as? Int) ?: EmitterParams.DEFAULT.spawnsPerTick, + loopDur = (json["loopDur"] as? Int) ?: EmitterParams.DEFAULT.loopDur, + loopDelay = (json["loopDelay"] as? Int) ?: EmitterParams.DEFAULT.loopDelay, + loopCount = (json["loopCount"] as? Int) ?: EmitterParams.DEFAULT.loopCount, particleTypes = allParticleTypes.toTypedArray() ) diff --git a/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt index 7266fae..d27223b 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt @@ -6,6 +6,11 @@ import com.bytedice.bde_particles.particle.* import com.bytedice.bde_particles.stringToMap import com.mojang.brigadier.Command 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.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder @@ -21,8 +26,13 @@ import net.minecraft.text.MutableText import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.text.TextColor +import org.joml.Vector2f +import org.joml.Vector3f import java.awt.Color import java.util.concurrent.CompletableFuture +import kotlin.reflect.KProperty1 +import kotlin.reflect.KType +import kotlin.reflect.full.memberProperties // ManageEmitters @@ -36,19 +46,14 @@ import java.util.concurrent.CompletableFuture // [emitter id] // output -> removes the particle with that id - // config + // config // TODO: find a way to make this remotely feasible // [emitter id] // <[particle index] / EMITTER> - // - // single param (if EMITTER, use emitter params instead) // TODO - // [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 + // 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 // list // output -> all registered emitters @@ -68,7 +73,6 @@ object ManageEmitters { // .then(argCreate()) .then(argRemove()) - .then(argConfig()) .then(argList()) .then(argCopy()) ) @@ -155,68 +159,6 @@ fun argRemove() : LiteralArgumentBuilder { } -// config - // [emitter id] - // <[particle index] / EMITTER> - - // - // 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 { - return CommandManager.literal("config") - .then( - // [emitter id] - emitterIdSuggestion - .then( - // <[particle index] / EMITTER> - makeIndexSuggestion() - // - //.then(argSingleParam()) - .then(argJson()) - ) - ) -} - -/* -fun argSingleParam() { - CommandManager.literal("SingleParam") - .then( - // [param key] - ) -} -*/ - -fun argJson() : LiteralArgumentBuilder { - 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 { return CommandManager.literal("list") .executes { context -> @@ -293,60 +235,3 @@ fun makeCommandBlock(emitterData: Map): ItemStack { return i } - - -fun makeIndexSuggestion() : RequiredArgumentBuilder { - 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 { - val emitterParams = getParticleEmitterParams(emitterId) - - val particleParams = if (emitterParams?.particleTypes!!.isNotEmpty()) { - emitterParams.particleTypes[particleIndex] - } - else { null } - - val emitterProperties = emitterParams::class.memberProperties - val emitterPropertyNames: MutableList = mutableListOf() - val emitterPropertyTypes: MutableList = mutableListOf() - - var particleProperties: Collection>? = 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()) - } -} -*/ \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitterParams.kt b/src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt similarity index 85% rename from src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitterParams.kt rename to src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt index 7ac20f9..c4c029e 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitterParams.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt @@ -1,9 +1,7 @@ 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. * * @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 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 spawnsPerTick: Int = 2, val loopDur: Int = 25, @@ -23,8 +21,8 @@ data class ParticleEmitterParams ( ) { companion object Presets { - val DEFAULT = ParticleEmitterParams() - val FIRE_GEYSER = ParticleEmitterParams( + val DEFAULT = EmitterParams() + val FIRE_GEYSER = EmitterParams( 200, 1, 25, diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt b/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt index 475320b..e498f04 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt @@ -3,7 +3,7 @@ package com.bytedice.bde_particles.particle import net.minecraft.server.world.ServerWorld 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 = emptyArray() diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt b/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt index 804710e..e6e9f10 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt @@ -1,10 +1,10 @@ package com.bytedice.bde_particles.particle -val emitterIdRegister: MutableMap = mutableMapOf() +val emitterIdRegister: MutableMap = mutableMapOf() val forbiddenIds = arrayOf("", "DEFAULT", "NULL") -fun addToEmitterRegister(id: String, params: ParticleEmitterParams) : Pair { +fun addToEmitterRegister(id: String, params: EmitterParams) : Pair { val newId = id.replace(" ", "_") 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] } -fun updateEmitterParams(id: String, newParams: ParticleEmitterParams) { +fun updateEmitterParams(id: String, newParams: EmitterParams) { emitterIdRegister[id] = newParams } \ No newline at end of file