feat: add patch and event to add command hints
finally /hints is no longer necessary since we fire an event every time the server makes us rebuild command hints. Still need to figure out how to namespace stuff
This commit is contained in:
parent
00cf2570e3
commit
1991ea5fba
3 changed files with 82 additions and 0 deletions
|
@ -2,7 +2,10 @@ package ftbsc.bscv;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
|
||||
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;
|
||||
|
@ -123,6 +126,11 @@ public class Boscovicino implements ICommons {
|
|||
return 1;
|
||||
})
|
||||
);
|
||||
@SubscribeEvent
|
||||
public void onCommandSuggestionsBuilt(CommandsBuiltEvent event) {
|
||||
for (CommandNode<CommandSource> child : this.dispatcher.getRoot().getChildren()) {
|
||||
event.dispatcher().getRoot().addChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
19
src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java
Normal file
19
src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package ftbsc.bscv.events;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
public class CommandsBuiltEvent extends Event {
|
||||
private CommandDispatcher<CommandSource> dispatcher;
|
||||
|
||||
public CommandDispatcher<CommandSource> dispatcher() {
|
||||
return this.dispatcher;
|
||||
}
|
||||
|
||||
public CommandsBuiltEvent(CommandDispatcher<CommandSource> dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
}
|
55
src/main/java/ftbsc/bscv/patches/CommandsPatch.java
Normal file
55
src/main/java/ftbsc/bscv/patches/CommandsPatch.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package ftbsc.bscv.patches;
|
||||
|
||||
import ftbsc.bscv.events.CommandsBuiltEvent;
|
||||
import ftbsc.lll.processor.annotations.Injector;
|
||||
import ftbsc.lll.processor.annotations.Patch;
|
||||
import ftbsc.lll.processor.annotations.Target;
|
||||
import ftbsc.lll.tools.InsnSequence;
|
||||
import ftbsc.lll.tools.PatternMatcher;
|
||||
import net.minecraft.client.network.play.ClientPlayNetHandler;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.network.play.server.SCommandListPacket;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
public class CommandsPatch {
|
||||
|
||||
public static class CommandsHook {
|
||||
public static void cmdBuilt(CommandDispatcher<CommandSource> dispatcher) {
|
||||
MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher));
|
||||
}
|
||||
}
|
||||
|
||||
@Patch(value = ClientPlayNetHandler.class, reason = "add hook to insert our command suggestions")
|
||||
public abstract static class CommandsDispatcherCatcher implements Opcodes {
|
||||
@Target
|
||||
abstract void handleCommands(SCommandListPacket pkt);
|
||||
|
||||
@Injector
|
||||
public void inject(ClassNode clazz, MethodNode main) {
|
||||
AbstractInsnNode found = PatternMatcher.builder()
|
||||
.opcodes(ALOAD, INVOKEVIRTUAL, INVOKESPECIAL)
|
||||
.ignoreFrames()
|
||||
.ignoreLabels()
|
||||
.ignoreLineNumbers()
|
||||
.build()
|
||||
.find(main)
|
||||
.getLast()
|
||||
.getNext(); // TODO temp fix!!!
|
||||
|
||||
InsnSequence is = new InsnSequence();
|
||||
is.add(new InsnNode(DUP));
|
||||
is.add(new MethodInsnNode(
|
||||
INVOKESTATIC,
|
||||
"ftbsc/bscv/patches/CommandsPatch$CommandsHook",
|
||||
"cmdBuilt",
|
||||
"(Lcom/mojang/brigadier/CommandDispatcher;)V"
|
||||
));
|
||||
|
||||
main.instructions.insert(found, is);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue