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() {
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<String, Any> {
fun emitterParamsToJson(params: EmitterParams) : Map<String, Any> {
val allParticleParamsJSON: MutableList<Map<String, Any?>> = mutableListOf()
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<*>
?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams")
@@ -161,12 +161,12 @@ fun jsonToEmitterParams(json: Map<String, Any>): 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()
)
@@ -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,20 +46,15 @@ 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 / JSON>
// single param (if EMITTER, use emitter params instead) // TODO
// 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
// list
// output -> all registered emitters
@@ -68,7 +73,6 @@ object ManageEmitters {
// <create / remove / config / list / copy>
.then(argCreate())
.then(argRemove())
.then(argConfig())
.then(argList())
.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> {
return CommandManager.literal("list")
.executes { context ->
@@ -293,60 +235,3 @@ fun makeCommandBlock(emitterData: Map<String, Any>): ItemStack {
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
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,
@@ -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<Particle> = emptyArray()
@@ -1,10 +1,10 @@
package com.bytedice.bde_particles.particle
val emitterIdRegister: MutableMap<String, ParticleEmitterParams> = mutableMapOf()
val emitterIdRegister: MutableMap<String, EmitterParams> = mutableMapOf()
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(" ", "_")
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
}