chore: some boilerplate for boat patch
This commit is contained in:
parent
627150b570
commit
ac4a18a428
2 changed files with 71 additions and 0 deletions
12
src/main/java/ftbsc/bscv/events/BoatEvent.java
Normal file
12
src/main/java/ftbsc/bscv/events/BoatEvent.java
Normal file
|
@ -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() {}
|
||||
}
|
||||
}
|
59
src/main/java/ftbsc/bscv/patches/BoatPatch.java
Normal file
59
src/main/java/ftbsc/bscv/patches/BoatPatch.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue