From 6a9df35f400eb1e31c574d1418b0772246b5870f Mon Sep 17 00:00:00 2001 From: alemidev Date: Sat, 28 Jan 2023 23:41:14 +0100 Subject: fix: very cheap and temp solution to missing hints Added a command, /rebuild_hints, which overwrites completer commands list using reflections and hardcoded obfuscated name. Classy! But it works without patches --- src/main/java/co/fantabos/bscv/BoSCoVicino.java | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java index de3cc3a..1ee1fc3 100644 --- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java +++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java @@ -3,7 +3,9 @@ package co.fantabos.bscv; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; @@ -26,6 +28,7 @@ import org.apache.logging.log4j.Logger; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -70,6 +73,32 @@ public class BoSCoVicino { // register config handler ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml"); + // TEMPORARY! add command to regenerate suggestions + dispatcher.register( + Commands.literal("rebuild_hints") + .executes(ctx -> { + ClientPlayerEntity player = BoSCoVicino.minecraft.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"); + return 1; + } catch (NoSuchFieldException e) { + LOGGER.error("No such field Exception while rebuilding hints"); + return 0; + } catch (IllegalAccessException e) { + LOGGER.error("Illegal Access Exception while rebuilding hints"); + return 0; + } + } else { + LOGGER.error("Local player is NULL"); + return 0; + } + }) + ); + // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } @@ -105,7 +134,7 @@ public class BoSCoVicino { @SubscribeEvent public void onClientChatEvent(ClientChatEvent event) { if (event.getMessage().startsWith("/")) { - CommandSource source = BoSCoVicino.minecraft.player.createCommandSourceStack(); + CommandSource source = BoSCoVicino.minecraft.player.createCommandSourceStack(); // TODO player could be NULL try { LOGGER.info(String.format("Running command %s", event.getMessage())); this.dispatcher.execute(event.getMessage().substring(1), source); -- cgit v1.2.3-56-ga3b1