diff options
author | alemi <me@alemi.dev> | 2023-03-04 04:03:14 +0100 |
---|---|---|
committer | alemi <me@alemi.dev> | 2023-03-04 04:03:14 +0100 |
commit | 0dc1644c148a9483c545efd08ae2094e85d5a55f (patch) | |
tree | 4a8957cd48443598faf3af1da423fc58bbbee2e0 /src/main | |
parent | 1991ea5fbae0df188992286b52a25b613fcb21d6 (diff) |
chore: cleaned up Boscovicino, added mods commands
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/ftbsc/bscv/Boscovicino.java | 68 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/commands/ModCommands.java | 51 |
2 files changed, 52 insertions, 67 deletions
diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java index d0860bf..19ca92f 100644 --- a/src/main/java/ftbsc/bscv/Boscovicino.java +++ b/src/main/java/ftbsc/bscv/Boscovicino.java @@ -8,18 +8,15 @@ import ftbsc.bscv.api.IModule; import ftbsc.bscv.events.CommandsBuiltEvent; import ftbsc.bscv.system.Friends; import ftbsc.bscv.system.ModManager; -import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.screen.IngameMenuScreen; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; @@ -29,7 +26,6 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.lang.reflect.Field; @Mod("bscv") public class Boscovicino implements ICommons { @@ -83,49 +79,8 @@ public class Boscovicino implements ICommons { for (IModule m : modManager.mods) { if (m.isEnabled()) m.enable(); } + } - // TEMPORARY! add command to regenerate suggestions - dispatcher.register( - Commands.literal("hints") - .executes(ctx -> { - ClientPlayerEntity player = MC.player; - if (player != null) { - try { - Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated - commands.setAccessible(true); - commands.set(player.connection, this.dispatcher); - LOGGER.info("Rebuild HINTS"); - log("> rebuilt hints"); - return 1; - } catch (NoSuchFieldException e) { - log("! no such field error"); - LOGGER.error("No such field Exception while rebuilding hints"); - return 0; - } catch (IllegalAccessException e) { - log("! illegal access error"); - LOGGER.error("Illegal Access Exception while rebuilding hints"); - return 0; - } - } else { - log("! local player is NULL"); - LOGGER.error("Local player is NULL"); - return 0; - } - }) - ); - - dispatcher.register( - Commands.literal("toggle-all") - .executes(ctx -> { - for (IModule mod : modManager.mods) { - if (mod.isEnabled()) { - mod.disable(); - mod.enable(); - } - } - return 1; - }) - ); @SubscribeEvent public void onCommandSuggestionsBuilt(CommandsBuiltEvent event) { for (CommandNode<CommandSource> child : this.dispatcher.getRoot().getChildren()) { @@ -171,25 +126,4 @@ public class Boscovicino implements ICommons { screen.children.add(3, mods_btn); } } - - @SubscribeEvent - public void onWorldLoad(WorldEvent.Load event) { - // TEMPORARY! add command to regenerate suggestions - ClientPlayerEntity player = MC.player; - if (player != null) { - try { - Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated - commands.setAccessible(true); - commands.set(player.connection, this.dispatcher); - LOGGER.info("Rebuild HINTS"); - log("> rebuilt hints"); - } catch (NoSuchFieldException e) { - LOGGER.error("No such field Exception while rebuilding hints"); - } catch (IllegalAccessException e) { - LOGGER.error("Illegal Access Exception while rebuilding hints"); - } - } else { - LOGGER.error("Local player is NULL"); - } - } } diff --git a/src/main/java/ftbsc/bscv/commands/ModCommands.java b/src/main/java/ftbsc/bscv/commands/ModCommands.java new file mode 100644 index 0000000..82e8661 --- /dev/null +++ b/src/main/java/ftbsc/bscv/commands/ModCommands.java @@ -0,0 +1,51 @@ +package ftbsc.bscv.commands; + +import com.google.auto.service.AutoService; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import ftbsc.bscv.Boscovicino; +import ftbsc.bscv.api.ILoadable; +import ftbsc.bscv.api.IModule; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; + +import static ftbsc.bscv.Boscovicino.log; + +@AutoService(ILoadable.class) +public class ModCommands extends AbstractCommand { + + @Override + public String getName() { return "mods"; } + + public LiteralArgumentBuilder<CommandSource> register(LiteralArgumentBuilder<CommandSource> builder) { + return builder + .then( + Commands.literal("off") + .executes(ctx -> { + for (IModule mod : Boscovicino.modManager.mods) { + if (mod.isEnabled()) { + mod.disable(); + } + } + return 1; + }) + ) + .then( + Commands.literal("re-enable") // this is to fix some jankyness in event subscriptions + .executes(ctx -> { + for (IModule mod : Boscovicino.modManager.mods) { + if (mod.isEnabled()) { + mod.disable(); + mod.enable(); + } + } + return 1; + }) + ) + .executes(ctx -> { + log("no args specified"); + return 0; + }); + } + +} |