diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 956a6192b..aeb110dc4 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -9,6 +9,7 @@ import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwPackets; import net.minecraft.commands.synchronization.ArgumentTypes; +import net.minecraft.commands.synchronization.EmptyArgumentSerializer; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; @@ -41,6 +42,6 @@ public class Flywheel { private void setup(final FMLCommonSetupEvent event) { FlwPackets.registerPackets(); - ArgumentTypes.register("flywheel:engine", EngineArgument.class, EngineArgument.SERIALIZER); + ArgumentTypes.register("flywheel:engine", EngineArgument.class, new EmptyArgumentSerializer<>(EngineArgument::getInstance)); } } diff --git a/src/main/java/com/jozufozu/flywheel/config/EngineArgument.java b/src/main/java/com/jozufozu/flywheel/config/EngineArgument.java index f24a758cb..90588554f 100644 --- a/src/main/java/com/jozufozu/flywheel/config/EngineArgument.java +++ b/src/main/java/com/jozufozu/flywheel/config/EngineArgument.java @@ -2,9 +2,7 @@ package com.jozufozu.flywheel.config; import java.util.Collection; import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; -import com.google.gson.JsonObject; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; @@ -14,16 +12,14 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.synchronization.ArgumentSerializer; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.TranslatableComponent; public class EngineArgument implements ArgumentType { - public static final EngineArgument INSTANCE = new EngineArgument(); - public static final Serializer SERIALIZER = new Serializer(); + private static final EngineArgument INSTANCE = new EngineArgument(); private static final Dynamic2CommandExceptionType INVALID = new Dynamic2CommandExceptionType((found, constants) -> { + // TODO: don't steal lang return new TranslatableComponent("commands.forge.arguments.enum.invalid", constants, found); }); @@ -52,18 +48,7 @@ public class EngineArgument implements ArgumentType { return FlwEngine.validNames(); } - public static class Serializer implements ArgumentSerializer { - private Serializer() { - } - - public void serializeToNetwork(EngineArgument argument, FriendlyByteBuf buffer) { - } - - public EngineArgument deserializeFromNetwork(FriendlyByteBuf buffer) { - return INSTANCE; - } - - public void serializeToJson(EngineArgument argument, JsonObject json) { - } + public static EngineArgument getInstance() { + return INSTANCE; } } diff --git a/src/main/java/com/jozufozu/flywheel/config/EngineConfigCommand.java b/src/main/java/com/jozufozu/flywheel/config/EngineConfigCommand.java deleted file mode 100644 index e8aefc36f..000000000 --- a/src/main/java/com/jozufozu/flywheel/config/EngineConfigCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.jozufozu.flywheel.config; - -import com.mojang.brigadier.Command; -import com.mojang.brigadier.builder.ArgumentBuilder; - -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.server.command.EnumArgument; - -public class EngineConfigCommand { - public static ArgumentBuilder register() { - return Commands.literal("backend") - .executes(context -> { - ServerPlayer player = context.getSource() - .getPlayerOrException(); - FlwPackets.channel.send(PacketDistributor.PLAYER.with(() -> player), new SConfigureEnginePacket()); - return Command.SINGLE_SUCCESS; - }) - .then(Commands.argument("type", EngineArgument.INSTANCE) - .executes(context -> { - FlwEngine type = context.getArgument("type", FlwEngine.class); - - ServerPlayer player = context.getSource() - .getPlayerOrException(); - FlwPackets.channel.send(PacketDistributor.PLAYER.with(() -> player), new SConfigureEnginePacket(type)); - - return Command.SINGLE_SUCCESS; - })); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index af8f9648b..6778d9996 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -1,11 +1,15 @@ package com.jozufozu.flywheel.config; +import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.ArgumentBuilder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.network.PacketDistributor; public class FlwCommands { @SubscribeEvent @@ -15,8 +19,32 @@ public class FlwCommands { .getDispatcher(); dispatcher.register(Commands.literal("flywheel") - .then(new BooleanConfigCommand("debugNormals", BooleanConfig.NORMAL_OVERLAY).register()) - .then(EngineConfigCommand.register()) + .then(debugCommand()) + .then(backendCommand()) ); } + + private static ArgumentBuilder debugCommand() { + return new BooleanConfigCommand("debugNormals", BooleanConfig.NORMAL_OVERLAY).register(); + } + + private static ArgumentBuilder backendCommand() { + return Commands.literal("backend") + .executes(context -> { + ServerPlayer player = context.getSource() + .getPlayerOrException(); + FlwPackets.channel.send(PacketDistributor.PLAYER.with(() -> player), new SConfigureEnginePacket()); + return Command.SINGLE_SUCCESS; + }) + .then(Commands.argument("type", EngineArgument.getInstance()) + .executes(context -> { + FlwEngine type = context.getArgument("type", FlwEngine.class); + + ServerPlayer player = context.getSource() + .getPlayerOrException(); + FlwPackets.channel.send(PacketDistributor.PLAYER.with(() -> player), new SConfigureEnginePacket(type)); + + return Command.SINGLE_SUCCESS; + })); + } }