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 6713250..1305db2 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/GiveEmitterTool.kt @@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture object GiveEmitterTool { fun register(dispatcher: CommandDispatcher, registryAccess: CommandRegistryAccess) { val command = CommandManager.literal("GiveEmitterTool") - .requires { source -> source.hasPermissionLevel(4) } + .requires { source -> source.hasPermissionLevel(2) } val allEmitterIds = idRegister.keys 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 71345f6..3463b88 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/ManageEmitters.kt @@ -69,8 +69,8 @@ blockCurve: Pair, LerpCurves>, // config // // - // // HARDCODED KEYS, if EMITTER use emitter params. - // // HARDCODED TYPES + // + // // output -> update the selected parameter of the selected emitter id to the new value // list @@ -80,222 +80,16 @@ blockCurve: Pair, LerpCurves>, // // 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) { val command = CommandManager.literal("ManageEmitters") - .requires { source -> source.hasPermissionLevel(4) } + .requires { source -> source.hasPermissionLevel(2) } dispatcher.register( command - // - .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 = 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 - // - // - // output -> register new emitter with a preset -fun argCreate() : LiteralArgumentBuilder { - 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 - - 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 - // - // output -> removes the particle with that id -fun argRemove() : LiteralArgumentBuilder { - 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 { - 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 - // - // output -> give player a command block with the particle params (should be paste-able in kotlin) -fun argCopy() : LiteralArgumentBuilder { - 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 - // - // - // // 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(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): 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 -} -*/ \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/commands/SpawnEmitter.kt b/src/main/kotlin/com/bytedice/bde_particles/commands/SpawnEmitter.kt new file mode 100644 index 0000000..0cf57ed --- /dev/null +++ b/src/main/kotlin/com/bytedice/bde_particles/commands/SpawnEmitter.kt @@ -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) { + val command = CommandManager.literal("SpawnEmitter") + .requires { source -> source.hasPermissionLevel(2) } + + dispatcher.register( + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/bytedice/bde_particles/particles/ParticleIdRegister.kt b/src/main/kotlin/com/bytedice/bde_particles/particles/ParticleIdRegister.kt index 64b8a64..c195c87 100644 --- a/src/main/kotlin/com/bytedice/bde_particles/particles/ParticleIdRegister.kt +++ b/src/main/kotlin/com/bytedice/bde_particles/particles/ParticleIdRegister.kt @@ -13,6 +13,11 @@ fun addToRegister(id: String, params: EmitterParams, cacheLength: Int) : Pair = mutableListOf() for (model in params.modelCurve.first) {