added all particles config options

This commit is contained in:
2024-11-23 11:58:05 +01:00
parent a9108941d7
commit 71900577e9
3 changed files with 250 additions and 55 deletions
@@ -15,7 +15,6 @@ import net.minecraft.entity.decoration.DisplayEntity.BlockDisplayEntity
import net.minecraft.entity.player.PlayerEntity import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtList
import net.minecraft.server.MinecraftServer import net.minecraft.server.MinecraftServer
import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.server.world.ServerWorld import net.minecraft.server.world.ServerWorld
@@ -23,12 +22,12 @@ import net.minecraft.util.ActionResult
import net.minecraft.util.Hand import net.minecraft.util.Hand
import net.minecraft.util.TypedActionResult import net.minecraft.util.TypedActionResult
import net.minecraft.world.World import net.minecraft.world.World
import org.apache.logging.log4j.core.jmx.Server
import java.util.* import java.util.*
// TODO: finish the particle ticking // TODO: finish the particle ticking
// TODO: make custom commands to create particles easier (only temporarily saved) // TODO: make custom commands to create particles easier (only temporarily saved)
// ONLY FORCE FIELDS LEFT LES GO!!!!!!!!
var ALL_PARTICLE_EMITTERS: Array<ParticleEmitter> = emptyArray() var ALL_PARTICLE_EMITTERS: Array<ParticleEmitter> = emptyArray()
@@ -1,12 +1,15 @@
package com.bytedice.bde_particles.commands package com.bytedice.bde_particles.commands
import com.bytedice.bde_particles.InterpolationCurves
import com.bytedice.bde_particles.particleIdRegister.SpawningShape import com.bytedice.bde_particles.particleIdRegister.SpawningShape
import com.bytedice.bde_particles.particleIdRegister.updateSingleParam import com.bytedice.bde_particles.particleIdRegister.updateSingleParam
import com.mojang.brigadier.Command import com.mojang.brigadier.Command
import com.mojang.brigadier.arguments.BoolArgumentType
import com.mojang.brigadier.arguments.FloatArgumentType import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.arguments.IntegerArgumentType 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.context.CommandContext import com.mojang.brigadier.context.CommandContext
import net.minecraft.server.command.CommandManager import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource import net.minecraft.server.command.ServerCommandSource
@@ -17,6 +20,7 @@ import org.joml.Vector2f
import org.joml.Vector3f import org.joml.Vector3f
import org.lwjgl.system.linux.X11 import org.lwjgl.system.linux.X11
import java.awt.Color import java.awt.Color
import java.util.concurrent.CompletableFuture
fun argUpdateEmitterParam(context: CommandContext<ServerCommandSource>, paramName: String, typeValue: Any) : MutableText { fun argUpdateEmitterParam(context: CommandContext<ServerCommandSource>, paramName: String, typeValue: Any) : MutableText {
@@ -192,68 +196,242 @@ class ArgConfigParticleKeys {
.then( .then(
CommandManager.argument("Array (separate by comma)", StringArgumentType.string()) CommandManager.argument("Array (separate by comma)", StringArgumentType.string())
.executes { context -> .executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val typeValue = StringArgumentType.getString(context, "Array (separate by comma)") val typeValue = StringArgumentType.getString(context, "Array (separate by comma)")
val typeArray = typeValue.split(",").toTypedArray() val typeArray = typeValue.split(",").toTypedArray()
val feedback = argUpdateEmitterParam(context, "blockCurve", typeArray) val feedback = argUpdateParticleParam(context, particleIndex, "blockCurve", typeArray)
context.source.sendFeedback({ feedback }, false) context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS Command.SINGLE_SUCCESS
} }
) )
} }
fun rotRandom() : LiteralArgumentBuilder<ServerCommandSource> { fun rotRandom() : LiteralArgumentBuilder<ServerCommandSource> {
// I'd like to introduce you to, drumroll please... *drumroll*... The pyramid of "X1,Y1,Z1,X2,Y2,Z2"
return CommandManager.literal("rotRandom") return CommandManager.literal("rotRandom")
.then(CommandManager.argument("X1", FloatArgumentType.floatArg()) .then(
.then(CommandManager.argument("Y1", FloatArgumentType.floatArg()) argPairVector3f()
.then(CommandManager.argument("Z1", FloatArgumentType.floatArg()) .executes { context ->
.then(CommandManager.argument("X2", FloatArgumentType.floatArg()) val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
.then(CommandManager.argument("Y2", FloatArgumentType.floatArg()) val vectors = x1x2ToPairVector3f(context)
.then(CommandManager.argument("Z2", FloatArgumentType.floatArg())
.executes { context ->
val x1 = FloatArgumentType.getFloat(context, "X1")
val y1 = FloatArgumentType.getFloat(context, "Y1")
val z1 = FloatArgumentType.getFloat(context, "Z1")
val x2 = FloatArgumentType.getFloat(context, "X2")
val y2 = FloatArgumentType.getFloat(context, "Y2")
val z2 = FloatArgumentType.getFloat(context, "Z2")
val feedback = argUpdateEmitterParam(context, "rotRandom", Pair(Vector3f(x1, y1, z1), Vector3f(x2, y2, z2))) val feedback = argUpdateParticleParam(context, particleIndex, "rotRandom", vectors)
context.source.sendFeedback({ feedback }, false) context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS Command.SINGLE_SUCCESS
} }
) )
) }
) fun rotVelRandom() : LiteralArgumentBuilder<ServerCommandSource> {
) return CommandManager.literal("rotVelRandom")
.then(
argPairVector3f()
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val vectors = x1x2ToPairVector3f(context)
val feedback = argUpdateParticleParam(context, particleIndex, "rotVelRandom", vectors)
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun sizeRandom() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("sizeRandom")
.then(
argPairVector3f()
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val vectors = x1x2ToPairVector3f(context)
val feedback = argUpdateParticleParam(context, particleIndex, "sizeRandom", vectors)
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun uniformSize() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("uniformSize")
.then(
CommandManager.argument("Bool", BoolArgumentType.bool())
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val uniform = BoolArgumentType.getBool(context, "Bool")
val feedback = argUpdateParticleParam(context, particleIndex, "uniformSize", uniform)
context.source.sendFeedback( { feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun velRandom() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("velRandom")
.then(
argPairVector3f()
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val vectors = x1x2ToPairVector3f(context)
val feedback = argUpdateParticleParam(context, particleIndex, "velRandom", vectors)
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun forceFields() {} // TODO: how?
fun gravity() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("gravity")
.then(
argVector3f()
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val x1 = FloatArgumentType.getFloat(context, "Min X")
val y1 = FloatArgumentType.getFloat(context, "Min Y")
val z1 = FloatArgumentType.getFloat(context, "Min Z")
val feedback = argUpdateParticleParam(context, particleIndex, "gravity", Vector3f(x1, y1, z1))
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun drag() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("drag")
.then(
CommandManager.argument("Float", FloatArgumentType.floatArg())
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val value = FloatArgumentType.getFloat(context, "Float")
val feedback = argUpdateParticleParam(context, particleIndex, "drag", value)
context.source.sendFeedback( { feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun minVel() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("minVel")
.then(
CommandManager.argument("Float", FloatArgumentType.floatArg())
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val value = FloatArgumentType.getFloat(context, "Float")
val feedback = argUpdateParticleParam(context, particleIndex, "minVel", value)
context.source.sendFeedback( { feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
fun lifeTime() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("lifeTime")
.then(CommandManager.argument("min", IntegerArgumentType.integer())
.then(CommandManager.argument("max", IntegerArgumentType.integer())
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val min = IntegerArgumentType.getInteger(context, "min")
val max = IntegerArgumentType.getInteger(context, "max")
val feedback = argUpdateParticleParam(context, particleIndex, "lifeTime", Pair(min, max))
context.source.sendFeedback( { feedback }, false)
Command.SINGLE_SUCCESS
}
) )
) )
} }
fun rotVelRandom() : LiteralArgumentBuilder<ServerCommandSource> { fun rotVelCurve() : LiteralArgumentBuilder<ServerCommandSource> {
// I'd like to introduce you to, drumroll please... *drumroll*... The pyramid of "X1,Y1,Z1,X2,Y2,Z2" return CommandManager.literal("rotVelCurve")
return CommandManager.literal("rotVelRandom") // TODO: convert this to a reusable variable .then(argCurve()
.then(CommandManager.argument("X1", FloatArgumentType.floatArg()) .executes { context ->
.then(CommandManager.argument("Y1", FloatArgumentType.floatArg()) val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
.then(CommandManager.argument("Z1", FloatArgumentType.floatArg()) val vectors = x1x2ToPairVector3f(context)
.then(CommandManager.argument("X2", FloatArgumentType.floatArg()) val curveString = StringArgumentType.getString(context, "Curve")
.then(CommandManager.argument("Y2", FloatArgumentType.floatArg())
.then(CommandManager.argument("Z2", FloatArgumentType.floatArg())
.executes { context ->
val x1 = FloatArgumentType.getFloat(context, "X1")
val y1 = FloatArgumentType.getFloat(context, "Y1")
val z1 = FloatArgumentType.getFloat(context, "Z1")
val x2 = FloatArgumentType.getFloat(context, "X2")
val y2 = FloatArgumentType.getFloat(context, "Y2")
val z2 = FloatArgumentType.getFloat(context, "Z2")
val feedback = argUpdateEmitterParam(context, "rotVelRandom", Pair(Vector3f(x1, y1, z1), Vector3f(x2, y2, z2))) val feedback = argUpdateParticleParam(
context.source.sendFeedback({ feedback }, false) context,
Command.SINGLE_SUCCESS particleIndex,
} "rotVelCurve",
) Triple(vectors.first, vectors.second, getCurveByString(curveString)))
)
) context.source.sendFeedback({ feedback }, false)
) Command.SINGLE_SUCCESS
) }
)
}
fun sizeCurve() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("sizeCurve")
.then(argCurve()
.executes { context ->
val particleIndex = IntegerArgumentType.getInteger(context, "Particle Index")
val vectors = x1x2ToPairVector3f(context)
val curveString = StringArgumentType.getString(context, "Curve")
val feedback = argUpdateParticleParam(
context,
particleIndex,
"sizeCurve",
Triple(vectors.first, vectors.second, getCurveByString(curveString)))
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
) )
} }
} }
fun argPairVector3f() : RequiredArgumentBuilder<ServerCommandSource, Float> {
return CommandManager.argument("Min X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Min Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Min Z", FloatArgumentType.floatArg())
.then(CommandManager.argument("Max X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Max Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Max Z", FloatArgumentType.floatArg()))
)
)
)
)
}
fun argVector3f() : RequiredArgumentBuilder<ServerCommandSource, Float> {
return CommandManager.argument("Min X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Min Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Min Z", FloatArgumentType.floatArg()))
)
}
val curves = arrayOf("LINEAR", "SQRT", "EXPONENT", "CUBIC", "SINE", "COSINE", "INVERSE", "LOG", "EXP", "BOUNCE")
fun argCurve() : RequiredArgumentBuilder<ServerCommandSource, Float> {
return argPairVector3f()
.then(
CommandManager.argument("Curve", StringArgumentType.string())
.suggests { _, builder ->
curves.forEach { builder.suggest(it) }
CompletableFuture.completedFuture(builder.build())
}
)
}
fun getCurveByString(str: String) : InterpolationCurves {
return when (str) {
"LINEAR" -> InterpolationCurves.LINEAR
"SQRT" -> InterpolationCurves.SQRT
"EXPONENT" -> InterpolationCurves.EXPONENT
"CUBIC" -> InterpolationCurves.CUBIC
"SINE" -> InterpolationCurves.SINE
"COSINE" -> InterpolationCurves.COSINE
"INVERSE" -> InterpolationCurves.INVERSE
"LOG" -> InterpolationCurves.LOG
"EXP" -> InterpolationCurves.EXP
"BOUNCE" -> InterpolationCurves.BOUNCE
else -> InterpolationCurves.LINEAR
}
}
fun x1x2ToPairVector3f(context: CommandContext<ServerCommandSource>) : Pair<Vector3f, Vector3f> {
val x1 = FloatArgumentType.getFloat(context, "Min X")
val y1 = FloatArgumentType.getFloat(context, "Min Y")
val z1 = FloatArgumentType.getFloat(context, "Min Z")
val x2 = FloatArgumentType.getFloat(context, "Max X")
val y2 = FloatArgumentType.getFloat(context, "Max Y")
val z2 = FloatArgumentType.getFloat(context, "Max Z")
return Pair(Vector3f(x1, y1, z1), Vector3f(x2, y2, z2))
}
@@ -35,7 +35,7 @@ import java.util.concurrent.CompletableFuture
// <emitter id> // <emitter id>
// output -> removes the particle with that id // output -> removes the particle with that id
// config // TODO // config
// <emitter id> // <emitter id>
// <[particle index] / EMITTER> // <[particle index] / EMITTER>
// <param key> // HARDCODED KEYS, if EMITTER use emitter params. // <param key> // HARDCODED KEYS, if EMITTER use emitter params.
@@ -83,7 +83,10 @@ val emitterConfigKeys = ArgConfigEmitterKeys()
val particleConfigKeys = ArgConfigParticleKeys() val particleConfigKeys = ArgConfigParticleKeys()
// TODO: fix "new emitter id" error // create
// <emitter id>
// <preset emitter id>
// output -> register new emitter with a preset
fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> { fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("create") return CommandManager.literal("create")
.then( .then(
@@ -129,7 +132,9 @@ fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> {
) )
} }
// remove
// <emitter id>
// output -> removes the particle with that id
fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> { fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("remove") return CommandManager.literal("remove")
.then( .then(
@@ -155,7 +160,8 @@ fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
) )
} }
// list
// output -> all registered emitters
fun argList() : LiteralArgumentBuilder<ServerCommandSource> { fun argList() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("list") return CommandManager.literal("list")
.executes { context -> .executes { context ->
@@ -174,7 +180,9 @@ fun argList() : LiteralArgumentBuilder<ServerCommandSource> {
} }
} }
// copy
// <emitter id>
// output -> give player a command block with the particle params (should be paste-able in kotlin)
fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> { fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("copy") return CommandManager.literal("copy")
.then( .then(
@@ -211,7 +219,7 @@ fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> {
) )
} }
// config // TODO // config
// <emitter id> // <emitter id>
// <[particle index] / EMITTER> // <[particle index] / EMITTER>
// <param key> // HARDCODED KEYS, if EMITTER use emitter params. // <param key> // HARDCODED KEYS, if EMITTER use emitter params.
@@ -244,6 +252,16 @@ fun argConfig() : LiteralArgumentBuilder<ServerCommandSource> {
.then(particleConfigKeys.blockCurve()) .then(particleConfigKeys.blockCurve())
.then(particleConfigKeys.rotRandom()) .then(particleConfigKeys.rotRandom())
.then(particleConfigKeys.rotVelRandom()) .then(particleConfigKeys.rotVelRandom())
.then(particleConfigKeys.sizeRandom())
.then(particleConfigKeys.uniformSize())
.then(particleConfigKeys.velRandom())
//.then(particleConfigKeys.forceFields())
.then(particleConfigKeys.gravity())
.then(particleConfigKeys.drag())
.then(particleConfigKeys.minVel())
.then(particleConfigKeys.lifeTime())
.then(particleConfigKeys.rotVelCurve())
.then(particleConfigKeys.sizeCurve())
) )
) )
} }