This commit is contained in:
2024-12-05 12:14:06 +01:00
parent e2049fd204
commit ad9ef87874
4 changed files with 30 additions and 214 deletions
@@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture
object GiveEmitterTool {
fun register(dispatcher: CommandDispatcher<ServerCommandSource>, registryAccess: CommandRegistryAccess) {
val command = CommandManager.literal("GiveEmitterTool")
.requires { source -> source.hasPermissionLevel(4) }
.requires { source -> source.hasPermissionLevel(2) }
val allEmitterIds = idRegister.keys
@@ -69,8 +69,8 @@ blockCurve: Pair<Array<String>, LerpCurves>,
// config
// <emitter id>
// <PARTICLE / EMITTER>
// <param key> // HARDCODED KEYS, if EMITTER use emitter params.
// <new param value> // HARDCODED TYPES
// <param key>
// <new param value>
// output -> update the selected parameter of the selected emitter id to the new value
// list
@@ -80,222 +80,16 @@ blockCurve: Pair<Array<String>, LerpCurves>,
// <emitter id>
// output -> give player a command block with the particle params (should be paste-able in kotlin)
/*
object ManageEmitters {
val allEmitterIds = idRegister.keys
fun register(dispatcher: CommandDispatcher<ServerCommandSource>) {
val command = CommandManager.literal("ManageEmitters")
.requires { source -> source.hasPermissionLevel(4) }
.requires { source -> source.hasPermissionLevel(2) }
dispatcher.register(
command
// <create / remove / config / list / copy>
.then(argCreate())
.then(argRemove())
.then(argConfig())
.then(argList())
.then(argCopy())
)
)
}
}
val allEmitterIds = emitterIdRegister.keys
// TODO: perhaps make this a Command.literal() if possible
val emitterIdSuggestion: RequiredArgumentBuilder<ServerCommandSource, String> = CommandManager.argument("Registered Emitter ID", StringArgumentType.string())
.suggests { _, builder ->
allEmitterIds.forEach { key ->
builder.suggest(key)
}
CompletableFuture.completedFuture(builder.build())
}
val emitterConfigKeys = ArgConfigEmitterKeys()
val particleConfigKeys = ArgConfigParticleKeys()
// create
// <emitter id>
// <preset emitter id>
// output -> register new emitter with a preset
fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("create")
.then(CommandManager.argument("Emitter ID", StringArgumentType.string())
.then(emitterIdSuggestion
.executes { context ->
val emitterIdVal = StringArgumentType.getString(context, "Emitter ID")
val emitterPresetVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "DEFAULT"
val emitterPresetParams = getEmitterParams(emitterPresetVal)
var newEmitterId = "NULL"
val emitterRegisterData: Pair<String, Boolean>
if (emitterPresetParams != null) {
emitterRegisterData = addToEmitterRegister(emitterIdVal, emitterPresetParams)
newEmitterId = emitterRegisterData.first
}
else { emitterRegisterData = Pair("NULL", false) }
val feedback = if (emitterRegisterData.second) {
Text.literal("BPS - Created particle emitter with ID \"$newEmitterId\".\n" +
"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" +
"BPS - Use \"/ManageEmitters list\" to view all Emitter ID's.")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb)))
}
context.source.sendFeedback( { feedback }, false )
Command.SINGLE_SUCCESS
}
)
)
}
// remove
// <emitter id>
// output -> removes the particle with that id
fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("remove")
.then(emitterIdSuggestion
.executes { context ->
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "NULL"
val isRemoved = removeFromEmitterRegister(emitterIdVal)
val feedback = if (isRemoved) {
Text.literal("BPS - Removed particle emitter with ID \"$emitterIdVal\".")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)))
}
else {
Text.literal("BPS - Emitter ID \"$emitterIdVal\" doesn't exist or is reserved!\n" +
"BPS - Use \"/ManageEmitters list\" to view all Emitter ID's.")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb)))
}
context.source.sendFeedback( { feedback }, false )
Command.SINGLE_SUCCESS
}
)
}
// list
// output -> all registered emitters
fun argList() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("list")
.executes { context ->
val allEmittersString = allEmitterIds.joinToString(", ")
val feedbackStatic = Text.literal("BPS - List of all available Emitter IDs:\n")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)))
val feedbackVar = Text.literal(allEmittersString)
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(255, 255, 255).rgb)))
val feedback = feedbackStatic.append(feedbackVar)
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
}
// copy
// <emitter id>
// output -> give player a command block with the particle params (should be paste-able in kotlin)
fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("copy")
.then(emitterIdSuggestion
.executes { context ->
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID")
val commandBlock = makeCommandBlock(
emitterParamsToJson(
getEmitterParams(
emitterIdVal
)!!
)
)
val feedback: MutableText
if (context.source.server.areCommandBlocksEnabled()) {
feedback = Text.literal("BPS - Copied Emitter data as a JSON. Place down the command block and copy it to your clipboard to use the value.")
.setStyle(Style.EMPTY.withColor(Color(0, 200, 0).rgb))
}
else {
feedback = Text.literal("BPS - Could not copy Emitter data: Command blocks aren't enabled. Go to server.properties and enable command blocks before retrying.")
.setStyle(Style.EMPTY.withColor(Color(200, 0, 0).rgb))
Command.SINGLE_SUCCESS
}
context.source.player?.inventory?.insertStack(commandBlock)
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
}
// config
// <emitter id>
// <PARTICLE / EMITTER>
// <param key> // HARDCODED KEYS, if EMITTER use emitter params.
// <new param value> // HARDCODED TYPES
// output -> update the selected parameter of the selected emitter id to the new value
fun argConfig() : LiteralArgumentBuilder<ServerCommandSource> {
return CommandManager.literal("config")
.then(emitterIdSuggestion
.then(CommandManager.literal("emitter")
.then(emitterConfigKeys.maxCount())
.then(emitterConfigKeys.spawnsPerTick())
.then(emitterConfigKeys.loopDur())
.then(emitterConfigKeys.loopDelay())
.then(emitterConfigKeys.loopCount())
)
.then(CommandManager.literal("particle")
.then(particleConfigKeys.shape())
.then(particleConfigKeys.blockCurve())
.then(particleConfigKeys.rotRandom())
.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())
)
)
}
fun makeCommandBlock(emitterData: Map<String, Any>): ItemStack {
val i = ItemStack(Items.COMMAND_BLOCK)
val nbt = NbtCompound()
nbt.putString("Command", emitterData.toString())
nbt.putString("id", "minecraft:command_block")
nbt.putByte("powered", 0)
nbt.putByte("auto", 0)
nbt.putByte("UpdateLastExecution", 1)
nbt.putByte("conditionMet", 0)
nbt.putByte("TrackOutput", 1)
nbt.putInt("SuccessCount", 0)
val component: NbtComponent = NbtComponent.of(nbt)
i.set(DataComponentTypes.BLOCK_ENTITY_DATA, component)
return i
}
*/
@@ -0,0 +1,17 @@
package com.bytedice.bde_particles.commands
import com.mojang.brigadier.CommandDispatcher
import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.server.command.SummonCommand
object SpawnEmitter {
fun register(dispatcher: CommandDispatcher<ServerCommandSource>) {
val command = CommandManager.literal("SpawnEmitter")
.requires { source -> source.hasPermissionLevel(2) }
dispatcher.register(
)
}
}
@@ -13,6 +13,11 @@ fun addToRegister(id: String, params: EmitterParams, cacheLength: Int) : Pair<St
return Pair(newId, false)
}
if (newId in forbiddenIds) {
println("BPS - Failed to register Emitter ID \"$newId\" as it's been reserved!")
return Pair(newId, false)
}
val newModels: MutableList<String> = mutableListOf()
for (model in params.modelCurve.first) {