diff --git a/build.gradle b/build.gradle index 8f73289..1dd45bb 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ repositories { } apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "com.palantir.git-version" @@ -89,7 +90,11 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" - implementation 'ftbsc:lll:0.1.2' + implementation 'ftbsc:lll:0.2.1' + implementation 'ftbsc.lll:processor:0.1.0' + annotationProcessor 'com.squareup:javapoet:1.13.0' + annotationProcessor 'ftbsc:lll:0.2.1' + annotationProcessor 'ftbsc.lll:processor:0.1.0' } jar { diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java index 1283b88..f035a50 100644 --- a/src/main/java/ftbsc/bscv/patches/BoatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -1,6 +1,10 @@ package ftbsc.bscv.patches; +import ftbsc.lll.processor.annotations.Injector; +import ftbsc.lll.processor.annotations.Patch; +import ftbsc.lll.processor.annotations.Target; import net.minecraft.entity.Entity; +import net.minecraft.entity.item.BoatEntity; import net.minecraftforge.common.MinecraftForge; import org.objectweb.asm.Opcodes; @@ -36,14 +40,13 @@ public class BoatPatch { } } - 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) { + @Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls") + public abstract static class BoatControlOverride implements Opcodes { + @Target + public abstract void controlBoat(); + + @Injector + public static void inject(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); @@ -61,14 +64,13 @@ public class BoatPatch { } } - public static class BoatClampOverride implements IInjector, Opcodes { - public String name() { return "BoatClampOverride"; } - public String reason() { return "add hook to cancel vanilla boat rotation clamping"; } - public String targetClass() { return "net.minecraft.entity.item.BoatEntity"; } - public String methodName() { return "func_184454_a"; } // void clampRotation(Entity e) - public String methodDesc() { return "(Lnet/minecraft/entity/Entity;)V"; } - - public void inject(ClassNode clazz, MethodNode main) { + @Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat rotation clamping") + public abstract static class BoatClampOverride implements Opcodes { + @Target + public abstract void clampRotation(Entity e); + + @Injector + public static void inject(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); @@ -86,14 +88,13 @@ public class BoatPatch { } } - public static class BoatGravityOverride implements IInjector, Opcodes { - public String name() { return "BoatGravityOverride"; } - public String reason() { return "add hook to alter vanilla boat gravity"; } - public String targetClass() { return "net.minecraft.entity.Entity"; } - public String methodName() { return "func_189652_ae"; } // boolean isNoGravity() - public String methodDesc() { return "()Z"; } - - public void inject(ClassNode clazz, MethodNode main) { + @Patch(value = Entity.class, reason = "add hook to alter vanilla boat gravity") + public abstract static class BoatGravityOverride implements Opcodes { + @Target + public abstract boolean isNoGravity(); + + @Injector + public static void inject(ClassNode clazz, MethodNode main) { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); diff --git a/src/main/java/ftbsc/bscv/patches/PacketPatch.java b/src/main/java/ftbsc/bscv/patches/PacketPatch.java index 4c7292d..610638e 100644 --- a/src/main/java/ftbsc/bscv/patches/PacketPatch.java +++ b/src/main/java/ftbsc/bscv/patches/PacketPatch.java @@ -1,6 +1,12 @@ package ftbsc.bscv.patches; +import ftbsc.lll.processor.annotations.Injector; +import ftbsc.lll.processor.annotations.Patch; +import ftbsc.lll.processor.annotations.Target; +import io.netty.channel.ChannelHandlerContext; +import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.network.IPacket; +import net.minecraft.network.NetworkManager; import net.minecraftforge.common.MinecraftForge; import org.objectweb.asm.Opcodes; @@ -31,21 +37,14 @@ public class PacketPatch { } } - public static class IncomingPacketInterceptor implements IInjector, Opcodes { - public String name() { return "IncomingPacketInterceptor"; } - public String reason() { return "add hook to intercept and alter/cancel incoming packets"; } - public String targetClass() { return "net.minecraft.network.NetworkManager"; } - public String methodName() { return "channelRead0"; } - public String methodDesc() { - return - new DescriptorBuilder() - .setReturnType(void.class) - .addParameter("io.netty.channel.ChannelHandlerContext") - .addParameter("net.minecraft.network.IPacket") - .build(); - } - - public void inject(ClassNode clazz, MethodNode main) { + @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets") + public abstract static class IncomingPacketInterceptor implements Opcodes { + @Target + @SuppressWarnings("rawtypes") + public abstract void channelRead0(ChannelHandlerContext ctx, IPacket pak); + + @Injector + public static void inject(ClassNode clazz, MethodNode main) { // ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ AbstractInsnNode found = PatternMatcher.builder() .opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ) @@ -73,21 +72,14 @@ public class PacketPatch { } } - public static class OutgoingPacketInterceptor implements IInjector, Opcodes { - public String name() { return "OutgoingPacketInterceptor"; } - public String reason() { return "add hook to intercept and alter/cancel outgoing packets"; } - public String targetClass() { return "net.minecraft.network.NetworkManager"; } - public String methodName() { return "func_150732_b"; } - public String methodDesc() { - return - new DescriptorBuilder() - .setReturnType(void.class) - .addParameter("net.minecraft.network.IPacket") - .addParameter("io.netty.util.concurrent.GenericFutureListener") - .build(); - } + @Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel outgoing packets") + public abstract static class OutgoingPacketInterceptor implements Opcodes { + @Target + @SuppressWarnings("rawtypes") + public abstract void sendPacket(IPacket pak, GenericFutureListener gfl); - public void inject(ClassNode clazz, MethodNode main) { + @Injector + public static void inject(ClassNode clazz, MethodNode main) { // hook at the top LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); diff --git a/src/main/resources/META-INF/services/ftbsc.lll.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector deleted file mode 100644 index b80faa2..0000000 --- a/src/main/resources/META-INF/services/ftbsc.lll.IInjector +++ /dev/null @@ -1,5 +0,0 @@ -ftbsc.bscv.patches.PacketPatch$IncomingPacketInterceptor -ftbsc.bscv.patches.PacketPatch$OutgoingPacketInterceptor -ftbsc.bscv.patches.BoatPatch$BoatControlOverride -ftbsc.bscv.patches.BoatPatch$BoatClampOverride -ftbsc.bscv.patches.BoatPatch$BoatGravityOverride