summaryrefslogtreecommitdiff
path: root/src/main/java/co
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/co')
-rw-r--r--src/main/java/co/fantabos/bscv/BoSCoVicino.java31
1 files changed, 30 insertions, 1 deletions
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);