State.java 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. package mod.adrenix.oldswing.command.executors;
  2. import com.mojang.brigadier.builder.LiteralArgumentBuilder;
  3. import mod.adrenix.oldswing.command.ColorUtil;
  4. import mod.adrenix.oldswing.config.ClientConfig;
  5. import mod.adrenix.oldswing.config.ConfigHandler;
  6. import net.minecraft.command.CommandSource;
  7. import net.minecraft.command.Commands;
  8. import net.minecraft.util.text.ITextComponent;
  9. public class State {
  10. public static LiteralArgumentBuilder<CommandSource> register() {
  11. return Commands.literal("mod")
  12. .then(Commands.literal("enable")
  13. .executes(context -> modState(context.getSource(), true))
  14. )
  15. .then(Commands.literal("disable")
  16. .executes(context -> modState(context.getSource(), false))
  17. );
  18. }
  19. private static int modState(CommandSource source, boolean flag) {
  20. ClientConfig.mod_enabled.set(flag);
  21. ConfigHandler.bake();
  22. final String out = String.format("OldSwing enabled: %s",
  23. ColorUtil.value(String.valueOf(flag)));
  24. source.sendFeedback(ITextComponent.func_244388_a(out), true);
  25. return 1;
  26. }
  27. }