mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Small config changes
- Make FlwCommands more readable - EmptyArgumentSerializer for EngineArgument
This commit is contained in:
parent
c3bc231d0a
commit
39439d6335
4 changed files with 36 additions and 54 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FlwEngine> {
|
||||
|
||||
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<FlwEngine> {
|
|||
return FlwEngine.validNames();
|
||||
}
|
||||
|
||||
public static class Serializer implements ArgumentSerializer<EngineArgument> {
|
||||
private Serializer() {
|
||||
}
|
||||
|
||||
public void serializeToNetwork(EngineArgument argument, FriendlyByteBuf buffer) {
|
||||
}
|
||||
|
||||
public EngineArgument deserializeFromNetwork(FriendlyByteBuf buffer) {
|
||||
public static EngineArgument getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void serializeToJson(EngineArgument argument, JsonObject json) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<CommandSourceStack, ?> 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;
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -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<CommandSourceStack, ?> debugCommand() {
|
||||
return new BooleanConfigCommand("debugNormals", BooleanConfig.NORMAL_OVERLAY).register();
|
||||
}
|
||||
|
||||
private static ArgumentBuilder<CommandSourceStack, ?> 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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue