diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/ftbsc/bscv/BoSCoVicino.java | 1 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/events/BoatEvent.java | 22 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/modules/motion/BoatFly.java | 89 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/BoatPatch.java | 115 | ||||
-rw-r--r-- | src/main/resources/META-INF/services/ftbsc.lll.IInjector | 3 |
5 files changed, 230 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java index 60735c3..c5c397c 100644 --- a/src/main/java/ftbsc/bscv/BoSCoVicino.java +++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java @@ -72,6 +72,7 @@ public class BoSCoVicino implements ICommons { BoSCoVicino.mods.add(new AutoFish(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new AutoTool(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new Freecam(cfg, dp).done(cfg)); + BoSCoVicino.mods.add(new BoatFly(cfg, dp).done(cfg)); BoSCoVicino.spec = cfg.build(); 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..1bef3a6 --- /dev/null +++ b/src/main/java/ftbsc/bscv/events/BoatEvent.java @@ -0,0 +1,22 @@ +package ftbsc.bscv.events; + +import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; + +public class BoatEvent { + + @Cancelable + public static class Control extends Event { + public Control() { super(); } + } + + @Cancelable + public static class ClampRotation extends Event { + public ClampRotation() { super(); } + } + + @Cancelable + public static class Gravity extends Event { + public Gravity() { super(); } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java new file mode 100644 index 0000000..d158f9a --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java @@ -0,0 +1,89 @@ +package ftbsc.bscv.modules.motion; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.DoubleArgumentType; + +import ftbsc.bscv.ICommons; +import ftbsc.bscv.events.BoatEvent; +import ftbsc.bscv.modules.Module; +import ftbsc.bscv.tools.Keyboard; +import net.minecraft.command.CommandSource; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.vector.Vector2f; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.TickEvent.Phase; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class BoatFly extends Module implements ICommons { + + public final ForgeConfigSpec.ConfigValue<Double> speed; + public final ForgeConfigSpec.ConfigValue<Double> rise; + public final ForgeConfigSpec.ConfigValue<Boolean> gravity; + + public BoatFly(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) { + super("BoatFly", Group.MOTION, builder, dispatcher); + + this.speed = this.option( + "speed", "magnitude of boat movement", 1., + DoubleArgumentType.doubleArg(), Double.class, + builder, dispatcher + ); + + this.rise = this.option( + "rise", "vertical speed", 0.5, + DoubleArgumentType.doubleArg(), Double.class, + builder, dispatcher + ); + + this.gravity = this.option( + "gravity", "toggle boat gravity", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onBoatControl(BoatEvent.Control event) { + if (MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onBoatClampRotation(BoatEvent.ClampRotation event) { + if (MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onBoatGravity(BoatEvent.Gravity event) { + if (!this.gravity.get() && MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (event.phase == Phase.END) return; + if (MC.player == null) { + this.disable(); + return; + } + Entity vehicle = MC.player.getVehicle(); + if (vehicle == null) return; + + vehicle.yRot = MC.player.yRot; + + if (Keyboard.isMoving()) { + Vector2f motion = MC.player.input.getMoveVector(); + double speed = this.speed.get(); + Vector3d delta = new Vector3d(motion.x * speed, MC.options.keyJump.isDown() ? this.rise.get() : 0., motion.y * speed); + vehicle.setDeltaMovement(delta.yRot((float) -(MC.player.yRot * (Math.PI / 180F)))); + } + } + +} 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..1283b88 --- /dev/null +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -0,0 +1,115 @@ +package ftbsc.bscv.patches; + +import net.minecraft.entity.Entity; +import net.minecraftforge.common.MinecraftForge; + +import org.objectweb.asm.Opcodes; +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.ICommons; +import ftbsc.bscv.events.BoatEvent; +import ftbsc.lll.IInjector; +import ftbsc.lll.tools.InsnSequence; + +public class BoatPatch { + + public static class BoatHook implements ICommons { + public static boolean boatControl() { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); + } + + public static boolean boatClampRotation() { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.ClampRotation()); + } + + public static boolean boatGravityCheck(Entity entity) { + if (MC.player == null) return false; + if (MC.player.getVehicle() == null) return false; + if (MC.player.getVehicle() != entity) return false; + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); + } + } + + 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 MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatControl", + "()Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(RETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } + + 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) { + // Hook at method start + LabelNode skip = new LabelNode(); + InsnSequence is = new InsnSequence(); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatClampRotation", + "()Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(RETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } + + 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) { + // Hook at method start + LabelNode skip = new LabelNode(); + InsnSequence is = new InsnSequence(); + is.add(new VarInsnNode(ALOAD, 0)); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatGravityCheck", + "(Lnet/minecraft/entity/Entity;)Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(ICONST_1)); + is.add(new InsnNode(IRETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } +} diff --git a/src/main/resources/META-INF/services/ftbsc.lll.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector index bda5738..b80faa2 100644 --- a/src/main/resources/META-INF/services/ftbsc.lll.IInjector +++ b/src/main/resources/META-INF/services/ftbsc.lll.IInjector @@ -1,2 +1,5 @@ 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 |