summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-02-19 20:20:47 +0100
committer alemi <me@alemi.dev>2023-02-19 20:20:47 +0100
commitac4a18a428d32fe4af9606672f66d713c0965de1 (patch)
treee40e03bd1aefa609ebf9e719b3b20d54ae2e6e35 /src/main/java
parent627150b57049aa321c8d4dfe17824c7867ef6bc9 (diff)
chore: some boilerplate for boat patch
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ftbsc/bscv/events/BoatEvent.java12
-rw-r--r--src/main/java/ftbsc/bscv/patches/BoatPatch.java59
2 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/events/BoatEvent.java b/src/main/java/ftbsc/bscv/events/BoatEvent.java
new file mode 100644
index 0000000..32eeb37
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/events/BoatEvent.java
@@ -0,0 +1,12 @@
+package ftbsc.bscv.events;
+
+import net.minecraftforge.eventbus.api.Cancelable;
+import net.minecraftforge.eventbus.api.Event;
+
+public class BoatEvent {
+
+ @Cancelable
+ public class Control extends Event {
+ public Control() {}
+ }
+}
diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java
new file mode 100644
index 0000000..3d7f13d
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java
@@ -0,0 +1,59 @@
+package ftbsc.bscv.patches;
+
+import net.minecraft.network.IPacket;
+import net.minecraftforge.common.MinecraftForge;
+
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.JumpInsnNode;
+import org.objectweb.asm.tree.LabelNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+import ftbsc.bscv.events.BoatEvent;
+import ftbsc.bscv.events.PacketEvent;
+import ftbsc.lll.IInjector;
+import ftbsc.lll.tools.InsnSequence;
+import ftbsc.lll.tools.PatternMatcher;
+
+public class BoatPatch {
+
+ public static class BoatHook {
+ public static boolean boatControl(IPacket<?> pkt) {
+ return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control());
+ }
+
+ public static boolean pktOut(IPacket<?> pkt) {
+ return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, true));
+ }
+ }
+
+ public static class BoatControlOverride implements IInjector, Opcodes {
+ public String name() { return "BoatControlOverride"; }
+ public String reason() { return "add hook to cancel vanilla boat controls"; }
+ public String targetClass() { return "net.minecraft.entity.item.BoatEntity"; }
+ public String methodName() { return "func_184443_x"; } // void controlBoat()
+ public String methodDesc() { return "()V"; }
+
+ public void inject(ClassNode clazz, MethodNode main) {
+ // Hook at method start
+ LabelNode skip = new LabelNode();
+ InsnSequence is = new InsnSequence();
+ is.add(new VarInsnNode(ALOAD, 2));
+ is.add(new MethodInsnNode(
+ INVOKESTATIC,
+ "ftbsc/bscv/patches/BoatPatch$BoatHook",
+ "boatControl",
+ "(Lnet/minecraft/network/IPacket;)Z"
+ ));
+ is.add(new JumpInsnNode(IFEQ, skip));
+ is.add(new InsnNode(RETURN));
+ is.add(skip);
+
+ main.instructions.insert(is);
+ }
+ }
+}