From 90fc0decab4e92ec77b04e0b04f8235282e1b9e3 Mon Sep 17 00:00:00 2001 From: ByteDice Date: Fri, 22 Nov 2024 18:38:25 +0100 Subject: [PATCH] re-added config subcommand, this time better than ever! --- .../bytedice/bde_particles/Bde_particles.kt | 58 +------- .../bde_particles/{math/main.kt => Math.kt} | 2 +- .../bde_particles/commands/GiveEmitterTool.kt | 4 +- .../bde_particles/commands/ManageEmitters.kt | 46 ++++-- .../commands/ManageEmittersConfigArgs.kt | 47 ++++++ .../items/ParticleEmitterTool.kt | 2 +- .../particle/particleIdRegister.kt | 34 ----- .../EmitterParams.kt | 16 +-- .../ForceFields.kt | 2 +- .../Particle.kt | 6 +- .../ParticleEmitter.kt | 2 +- .../particleIdRegister/ParticleIdRegister.kt | 136 ++++++++++++++++++ .../ParticleParams.kt | 30 ++-- .../Shapes.kt | 2 +- 14 files changed, 254 insertions(+), 133 deletions(-) rename src/main/kotlin/com/bytedice/bde_particles/{math/main.kt => Math.kt} (99%) create mode 100644 src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmittersConfigArgs.kt delete mode 100644 src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/EmitterParams.kt (75%) rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/ForceFields.kt (84%) rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/Particle.kt (96%) rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/ParticleEmitter.kt (98%) create mode 100644 src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleIdRegister.kt rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/ParticleParams.kt (76%) rename src/main/kotlin/com/bytedice/bde_particles/{particle => particleIdRegister}/Shapes.kt (93%) 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 d562ea9..3eb899a 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt @@ -1,12 +1,9 @@ -@file:Suppress("UNCHECKED_CAST") - package com.bytedice.bde_particles import com.bytedice.bde_particles.commands.GiveEmitterTool import com.bytedice.bde_particles.commands.ManageEmitters import com.bytedice.bde_particles.items.ParticleEmitterTool -import com.bytedice.bde_particles.math.raycastFromPlayer -import com.bytedice.bde_particles.particle.* +import com.bytedice.bde_particles.particleIdRegister.* import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents @@ -20,7 +17,6 @@ import net.minecraft.util.ActionResult import net.minecraft.util.Hand import net.minecraft.util.TypedActionResult import net.minecraft.world.World -import org.joml.Vector3f // TODO: finish the particle ticking @@ -131,54 +127,4 @@ fun emitterParamsToJson(params: EmitterParams) : Map { ) return emitterParamsJSON -} - - -fun jsonToEmitterParams(json: Map): EmitterParams { - val particleTypes = json["particleTypes"] as? List<*> - ?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams") - - val allParticleTypes: MutableList = mutableListOf() - - for (particle in particleTypes.iterator()) { - val particleParams = particle as? ParticleParams ?: ParticleParams.DEFAULT - - val updatedParticle = ParticleParams( - shape = (particleParams.shape ?: ParticleParams.DEFAULT.shape), - blockCurve = (json["blockCurve"] as? Array) ?: particleParams.blockCurve, - rotRandom = (json["rotRandom"] as? Pair) ?: particleParams.rotRandom, - rotVelRandom = (json["rotVelRandom"] as? Pair) ?: particleParams.rotVelRandom, - rotVelCurve = (json["rotVelCurve"] as? Array) ?: particleParams.rotVelCurve, - sizeRandom = (json["sizeRandom"] as? Pair) ?: particleParams.sizeRandom, - uniformSize = (json["uniformSize"] as? Boolean) ?: particleParams.uniformSize, - sizeCurve = (json["sizeCurve"] as? Array) ?: particleParams.sizeCurve, - velRandom = (json["velRandom"] as? Pair) ?: particleParams.velRandom, - forceFields = (json["forceFields"] as? Array) ?: particleParams.forceFields, - gravity = (json["gravity"] as? Vector3f) ?: particleParams.gravity, - drag = (json["drag"] as? Float) ?: particleParams.drag, - minVel = (json["minVel"] as? Float) ?: particleParams.minVel, - lifeTime = (json["lifeTime"] as? Pair) ?: particleParams.lifeTime - ) - - allParticleTypes.add(updatedParticle) - } - - 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() - ) - - return params -} - - - -fun stringToMap(input: String): Map { - return input.split(",") - .map { it.split("=") } - .associate { it[0].trim() to it[1].trim() } -} +} \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/math/main.kt b/src/main/kotlin/com/bytedice/bde_particles/Math.kt similarity index 99% rename from src/main/kotlin/com/bytedice/bde_particles/math/main.kt rename to src/main/kotlin/com/bytedice/bde_particles/Math.kt index 1e7b5f5..0481339 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/math/main.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/Math.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.math +package com.bytedice.bde_particles import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.util.hit.HitResult diff --git a/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt b/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt index b718446..d691a9c 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt @@ -1,7 +1,7 @@ package com.bytedice.bde_particles.commands import com.bytedice.bde_particles.items.ParticleEmitterTool -import com.bytedice.bde_particles.particle.emitterIdRegister +import com.bytedice.bde_particles.particleIdRegister.emitterIdRegister import com.mojang.brigadier.Command import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.arguments.StringArgumentType @@ -45,7 +45,7 @@ object GiveEmitterTool { val emitterId = StringArgumentType.getString(context, "Emitter ID") val feedback = Text.literal("BPS - You like fancy particles. Don't you?\nBPS - gave particle emitter, bound to ID: \"${emitterId}\".") - .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)).withItalic(true)) + .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb))) context.source.player?.inventory?.insertStack(ParticleEmitterTool.makeData(item.item, name, emitterId)) context.source.sendFeedback({ feedback }, false) 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 4a5310f..c23e060 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt @@ -1,7 +1,7 @@ package com.bytedice.bde_particles.commands import com.bytedice.bde_particles.emitterParamsToJson -import com.bytedice.bde_particles.particle.* +import com.bytedice.bde_particles.particleIdRegister.* import com.mojang.brigadier.Command import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.arguments.StringArgumentType @@ -26,26 +26,26 @@ import java.util.concurrent.CompletableFuture // ManageEmitters // // create - // [emitter id] - // [preset emitter id] + // + // // output -> register new emitter with a preset // remove - // [emitter id] + // // output -> removes the particle with that id // config // TODO - // [emitter id] + // // <[particle index] / EMITTER> - // [param key] // HARDCODED KEYS, if EMITTER use emitter params. - // [new param value] // HARDCODED TYPES + // // HARDCODED KEYS, if EMITTER use emitter params. + // // HARDCODED TYPES // output -> update the selected parameter of the selected emitter id to the new value // list // output -> all registered emitters // copy - // [emitter id] + // // output -> give player a command block with the particle params (should be paste-able in kotlin) @@ -59,6 +59,7 @@ object ManageEmitters { // .then(argCreate()) .then(argRemove()) + .then(argConfig()) .then(argList()) .then(argCopy()) ) @@ -68,6 +69,7 @@ object ManageEmitters { val allEmitterIds = emitterIdRegister.keys +// TODO: maybe make this a Command.literal() val emitterIdSuggestion: RequiredArgumentBuilder = CommandManager.argument("Registered Emitter ID", StringArgumentType.string()) .suggests { _, builder -> val suggestionsBuilder = SuggestionsBuilder(builder.remaining, 0) @@ -78,6 +80,7 @@ val emitterIdSuggestion: RequiredArgumentBuilder = } +// TODO: fix "new emitter id" error fun argCreate() : LiteralArgumentBuilder { return CommandManager.literal("create") .then( @@ -105,8 +108,13 @@ fun argCreate() : LiteralArgumentBuilder { "BPS - This emitter will be removed on server restart! Use \"/ManageEmitters copy\" to save the data to your clipboard!") .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb))) } + else if (newEmitterId !in allEmitterIds) { + Text.literal("BPS - Preset Emitter ID \"$emitterPresetVal\" doesn't exist!\n" + + "BPS - Use \"/ManageEmitters list\" to view all Emitter ID's.") + .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb))) + } else { - Text.literal("BPS - Emitter ID \"$newEmitterId\" already exists!\n" + + Text.literal("BPS - Emitter ID \"$newEmitterId\" already exists\n" + "BPS - Use \"/ManageEmitters list\" to view all Emitter ID's.") .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb))) } @@ -200,6 +208,26 @@ fun argCopy() : LiteralArgumentBuilder { ) } +// config // TODO + // + // <[particle index] / EMITTER> + // // HARDCODED KEYS, if EMITTER use emitter params. + // // HARDCODED TYPES + // output -> update the selected parameter of the selected emitter id to the new value +fun argConfig() : LiteralArgumentBuilder { + return CommandManager.literal("config") + .then( + emitterIdSuggestion + .then(argConfigEmitter()) + ) +} + + +fun argConfigEmitter() : LiteralArgumentBuilder { + return CommandManager.literal("EMITTER") + .then(ArgConfigEmitterKeys().maxCount()) +} + fun makeCommandBlock(emitterData: Map): ItemStack { val i = ItemStack(Items.COMMAND_BLOCK) diff --git a/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmittersConfigArgs.kt b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmittersConfigArgs.kt new file mode 100644 index 0000000..fea938e --- /dev/null +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmittersConfigArgs.kt @@ -0,0 +1,47 @@ +package com.bytedice.bde_particles.commands +import com.bytedice.bde_particles.particleIdRegister.updateSingleParam +import com.mojang.brigadier.Command +import com.mojang.brigadier.arguments.IntegerArgumentType +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.context.CommandContext +import net.minecraft.server.command.CommandManager +import net.minecraft.server.command.ServerCommandSource +import net.minecraft.text.MutableText +import net.minecraft.text.Style +import net.minecraft.text.Text +import java.awt.Color + + +fun argUpdateEmitterParam(context: CommandContext, paramName: String, typeValue: Any) : MutableText { + val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID") + + val success = updateSingleParam(emitterIdVal, -1, "maxCount", typeValue) + + val feedback = if (success) { + Text.literal("BPS - Successfully updated Emitter ID \"$emitterIdVal\" parameter \"$paramName\" to value \"$typeValue\"") + .setStyle(Style.EMPTY.withColor(Color(0, 200, 0).rgb)) + } + else { + Text.literal("BPS - Failed to update Emitter ID \"$emitterIdVal\" parameter \"$paramName\" to value \"$typeValue\": Unknown Error") + .setStyle(Style.EMPTY.withColor(Color(200, 0, 0).rgb)) + } + + return feedback +} + + +class ArgConfigEmitterKeys { + fun maxCount() : LiteralArgumentBuilder { + return CommandManager.literal("maxCount") + .then( + CommandManager.argument("Int", IntegerArgumentType.integer()) + .executes { context -> + val typeValue = IntegerArgumentType.getInteger(context, "Int") + val feedback = argUpdateEmitterParam(context, "maxCount", typeValue) + context.source.sendFeedback({ feedback }, false) + Command.SINGLE_SUCCESS + } + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/items/ParticleEmitterTool.kt b/src/main/kotlin/com/bytedice/bde_particles/items/ParticleEmitterTool.kt index 707c8bb..82d3ebd 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/items/ParticleEmitterTool.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/items/ParticleEmitterTool.kt @@ -25,7 +25,7 @@ object ParticleEmitterTool { val displayName = Text.literal(name) .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)).withItalic(true)) - val loreLines = Text.literal("BPS - Bound to ID \"$emitterId\".") + val loreLines = Text.literal("BPS - Bound to Emitter ID \"$emitterId\".") .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)).withItalic(true)) val lore = LoreComponent(listOf(loreLines)) diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt b/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt deleted file mode 100644 index e6e9f10..0000000 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/particleIdRegister.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.bytedice.bde_particles.particle - -val emitterIdRegister: MutableMap = mutableMapOf() -val forbiddenIds = arrayOf("", "DEFAULT", "NULL") - - -fun addToEmitterRegister(id: String, params: EmitterParams) : Pair { - val newId = id.replace(" ", "_") - - if (newId in forbiddenIds && newId != "DEFAULT") {return Pair(newId, false) } - if (emitterIdRegister.containsKey(newId)) {return Pair(newId, false) } - - emitterIdRegister[id] = params - return Pair(newId, true) -} - - -fun removeFromEmitterRegister(id: String) : Boolean { - if (id in forbiddenIds) { return false } - if (!emitterIdRegister.containsKey(id)) { return false } - - emitterIdRegister.remove(id) - return true -} - - -fun getEmitterParams(id: String) : EmitterParams? { - return emitterIdRegister[id] -} - - -fun updateEmitterParams(id: String, newParams: EmitterParams) { - emitterIdRegister[id] = newParams -} \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/EmitterParams.kt similarity index 75% rename from src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/EmitterParams.kt index c4c029e..9e228f3 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/EmitterParams.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/EmitterParams.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister /** * EmitterParams defines the parameters for controlling how particles are emitted, @@ -12,12 +12,12 @@ package com.bytedice.bde_particles.particle * @param particleTypes An array of `ParticleParams` defining the types of particles to spawn. If empty, no particles will spawn. */ data class EmitterParams ( - val maxCount: Int = 200, - val spawnsPerTick: Int = 2, - val loopDur: Int = 25, - val loopDelay: Int = 10, - val loopCount: Int = 3, - val particleTypes: Array = arrayOf(ParticleParams()), + var maxCount: Int = 200, + var spawnsPerTick: Int = 2, + var loopDur: Int = 25, + var loopDelay: Int = 10, + var loopCount: Int = 3, + var particleTypes: Array = arrayOf(ParticleParams()), ) { companion object Presets { @@ -28,7 +28,7 @@ data class EmitterParams ( 25, 0, 0, - arrayOf(ParticleParams.FIRE_GEYSER) + arrayOf(ParticleParams.DEFAULT) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/ForceFields.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ForceFields.kt similarity index 84% rename from src/main/kotlin/com/bytedice/bde_particles/particle/ForceFields.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ForceFields.kt index f129307..ae093e0 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/ForceFields.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ForceFields.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister data class ForceField ( val x: Float = 0.0f, diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/Particle.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Particle.kt similarity index 96% rename from src/main/kotlin/com/bytedice/bde_particles/particle/Particle.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Particle.kt index 91396b0..06ab492 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/Particle.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Particle.kt @@ -1,8 +1,6 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister -import com.bytedice.bde_particles.DisplayEntity -import com.bytedice.bde_particles.DisplayEntityProperties -import com.bytedice.bde_particles.math.* +import com.bytedice.bde_particles.* import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.Vec3d import org.joml.Vector3f diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleEmitter.kt similarity index 98% rename from src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleEmitter.kt index e498f04..ca009e6 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleEmitter.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleEmitter.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.Vec3d diff --git a/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleIdRegister.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleIdRegister.kt new file mode 100644 index 0000000..d660f19 --- /dev/null +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleIdRegister.kt @@ -0,0 +1,136 @@ +@file:Suppress("UNCHECKED_CAST") + +package com.bytedice.bde_particles.particleIdRegister + +import org.joml.Vector3f + + +val emitterIdRegister: MutableMap = mutableMapOf() +val forbiddenIds = arrayOf("", "DEFAULT", "NULL") + + +fun addToEmitterRegister(id: String, params: EmitterParams) : Pair { + val newId = id.replace(" ", "_") + + if (newId in forbiddenIds && newId != "DEFAULT") { return Pair(newId, false) } + if (emitterIdRegister.containsKey(newId)) { return Pair(newId, false) } + + emitterIdRegister[id] = params + return Pair(newId, true) +} + + +fun removeFromEmitterRegister(id: String) : Boolean { + if (id in forbiddenIds) { return false } + if (!emitterIdRegister.containsKey(id)) { return false } + + emitterIdRegister.remove(id) + return true +} + + +fun getEmitterParams(id: String) : EmitterParams? { + return emitterIdRegister[id] +} + + +fun updateEmitterParams(id: String, newParams: EmitterParams) { + emitterIdRegister[id] = newParams +} + + +fun updateSingleParam(id: String, particleIndex: Int, paramName: String, paramValue: Any) : Boolean { + val emitter = getEmitterParams(id) ?: return false + + if (particleIndex == -1) { + val updatedValues = updateSingleEmitterParam(emitter, paramName, paramValue) + updateEmitterParams(id, updatedValues.first) + + return updatedValues.second + } + else if (emitter.particleTypes.isNotEmpty()) { + val particle = emitter.particleTypes[particleIndex] + + val updatedValues = updateSingleParticleParam(particle, paramName, paramValue) + + emitter.particleTypes[particleIndex] = updatedValues.first + updateEmitterParams(id, emitter) + + return updatedValues.second + } + else { + return false + } +} + + +fun updateSingleEmitterParam(params: EmitterParams, paramName: String, paramValue: Any) : Pair { + val value: Any? = when (paramName) { + "maxCount" -> paramValue as Int + "spawnsPerTick" -> paramValue as Int + "loopDur" -> paramValue as Int + "loopDelay" -> paramValue as Int + "loopCount" -> paramValue as Int + else -> null + } + + if (value == null) { return Pair(params, false) } + + val newParams = params.copy() + + when (paramName) { + "maxCount" -> newParams.maxCount = value as Int + "spawnsPerTick" -> newParams.spawnsPerTick = value as Int + "loopDur" -> newParams.loopDur = value as Int + "loopDelay" -> newParams.loopDelay = value as Int + "loopCount" -> newParams.loopCount = value as Int + else -> return Pair(params, false) + } + + return Pair(newParams, true) +} + + +fun updateSingleParticleParam(params: ParticleParams, paramName: String, paramValue: Any) : Pair { + val value: Any? = when (paramName) { + "shape" -> paramValue as SpawningShape? + "blockCurve" -> paramValue as Array + "rotRandom" -> paramValue as Pair + "rotVelRandom" -> paramValue as Pair + "rotVelCurve" -> paramValue as Array + "sizeRandom" -> paramValue as Pair + "uniformSize" -> paramValue as Boolean + "sizeCurve" -> paramValue as Array + "velRandom" -> paramValue as Pair + "forceFields" -> paramValue as Array + "gravity" -> paramValue as Vector3f + "drag" -> paramValue as Float + "minVel" -> paramValue as Float + "lifeTime" -> paramValue as Pair + else -> null + } + + if (value == null) { return Pair(params, false) } + + val newParams = params.copy() + + when (paramName) { + "shape" -> newParams.shape = value as SpawningShape? + "blockCurve" -> newParams.blockCurve = value as Array + "rotRandom" -> newParams.rotRandom = value as Pair + "rotVelRandom" -> newParams.rotVelRandom = value as Pair + "rotVelCurve" -> newParams.rotVelCurve = value as Array + "sizeRandom" -> newParams.sizeRandom = value as Pair + "uniformSize" -> newParams.uniformSize = value as Boolean + "sizeCurve" -> newParams.sizeCurve = value as Array + "velRandom" -> newParams.velRandom = value as Pair + "forceFields" -> newParams.forceFields = value as Array + "gravity" -> newParams.gravity = value as Vector3f + "drag" -> newParams.drag = value as Float + "minVel" -> newParams.minVel = value as Float + "lifeTime" -> newParams.lifeTime = value as Pair + else -> return Pair(params, false) + } + + return Pair(newParams, true) +} \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleParams.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleParams.kt similarity index 76% rename from src/main/kotlin/com/bytedice/bde_particles/particle/ParticleParams.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleParams.kt index 183f860..0fe179f 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/ParticleParams.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/ParticleParams.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister import org.joml.Vector3f @@ -21,20 +21,20 @@ import org.joml.Vector3f * @param lifeTime A range for the particle's lifetime in ticks. A value below 1 will result in the particle not spawning. */ data class ParticleParams ( - val shape: SpawningShape? = SpawningShape.Circle(3.0f), - val blockCurve: Array = arrayOf("minecraft:shroomlight", "minecraft:orange_concrete", "minecraft:orange_stained_glass", "minecraft:gray_stained_glass", "minecraft:light_gray_stained_glass"), - val rotRandom: Pair = Pair(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(360.0f, 360.0f, 360.0f)), - val rotVelRandom: Pair = Pair(Vector3f(-0.2f, -0.2f, -0.2f), Vector3f(0.2f, 0.2f, 0.2f)), - val rotVelCurve: Array = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)), - val sizeRandom: Pair = Pair(Vector3f(0.5f, 0.5f, 0.5f), Vector3f(1.0f, 1.0f, 1.0f)), - val uniformSize: Boolean = true, - val sizeCurve: Array = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.5f, 0.5f, 0.5f)), - val velRandom: Pair = Pair(Vector3f(-0.1f, 0.4f, -0.1f), Vector3f(0.1f, 0.8f, 0.1f)), - val forceFields: Array = arrayOf(ForceField()), // emptyArray(), - val gravity: Vector3f = Vector3f(0.0f, -0.01f, 0.0f), - val drag: Float = 0.075f, - val minVel: Float = 0.0f, - val lifeTime: Pair = Pair(15, 45) + var shape: SpawningShape? = SpawningShape.Circle(3.0f), + var blockCurve: Array = arrayOf("minecraft:shroomlight", "minecraft:orange_concrete", "minecraft:orange_stained_glass", "minecraft:gray_stained_glass", "minecraft:light_gray_stained_glass"), + var rotRandom: Pair = Pair(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(360.0f, 360.0f, 360.0f)), + var rotVelRandom: Pair = Pair(Vector3f(-0.2f, -0.2f, -0.2f), Vector3f(0.2f, 0.2f, 0.2f)), + var rotVelCurve: Array = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)), + var sizeRandom: Pair = Pair(Vector3f(0.5f, 0.5f, 0.5f), Vector3f(1.0f, 1.0f, 1.0f)), + var uniformSize: Boolean = true, + var sizeCurve: Array = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.5f, 0.5f, 0.5f)), + var velRandom: Pair = Pair(Vector3f(-0.1f, 0.4f, -0.1f), Vector3f(0.1f, 0.8f, 0.1f)), + var forceFields: Array = arrayOf(ForceField()), // emptyArray(), + var gravity: Vector3f = Vector3f(0.0f, -0.01f, 0.0f), + var drag: Float = 0.075f, + var minVel: Float = 0.0f, + var lifeTime: Pair = Pair(15, 45) ) { companion object Presets { val DEFAULT = ParticleParams() diff --git a/src/main/kotlin/com/bytedice/bde_particles/particle/Shapes.kt b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Shapes.kt similarity index 93% rename from src/main/kotlin/com/bytedice/bde_particles/particle/Shapes.kt rename to src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Shapes.kt index b70f515..66a6841 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particle/Shapes.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particleIdRegister/Shapes.kt @@ -1,4 +1,4 @@ -package com.bytedice.bde_particles.particle +package com.bytedice.bde_particles.particleIdRegister import org.joml.Vector2f import org.joml.Vector3f