feat: working basic boatfly

This commit is contained in:
əlemi 2023-02-19 23:43:40 +01:00
parent eb9e15e004
commit e5f1fdb475
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 108 additions and 10 deletions

View file

@ -9,4 +9,14 @@ public class BoatEvent {
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(); }
}
}

View file

@ -1,6 +1,7 @@
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;
@ -9,16 +10,18 @@ import ftbsc.bscv.modules.Module;
import ftbsc.bscv.tools.Keyboard;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.BoatEntity;
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);
@ -34,6 +37,12 @@ public class BoatFly extends Module implements ICommons {
DoubleArgumentType.doubleArg(), Double.class,
builder, dispatcher
);
this.gravity = this.option(
"gravity", "toggle boat gravity", true,
BoolArgumentType.bool(), Boolean.class,
builder, dispatcher
);
}
@SubscribeEvent
@ -43,24 +52,37 @@ public class BoatFly extends Module implements ICommons {
}
}
@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 (event.phase == Phase.END) return;
if (MC.player == null) {
this.disable();
return;
}
Entity vehicle = MC.player.getVehicle();
if (vehicle == null) return;
if (vehicle instanceof BoatEntity) {
}
vehicle.yRot = MC.player.yRot;
if (Keyboard.isMoving()) {
Vector2f motion = MC.player.input.getMoveVector();
double rise = MC.options.keyJump.isDown() ? this.rise.get() : 0.;
double speed = this.speed.get();
vehicle.setDeltaMovement(motion.x * speed, rise, motion.y * speed);
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))));
}
}

View file

@ -1,6 +1,6 @@
package ftbsc.bscv.patches;
import net.minecraft.network.IPacket;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge;
import org.objectweb.asm.Opcodes;
@ -12,16 +12,28 @@ 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 {
public static boolean boatControl(IPacket<?> pkt) {
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 {
@ -35,7 +47,6 @@ public class BoatPatch {
// 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",
@ -49,4 +60,56 @@ public class BoatPatch {
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);
}
}
}

View file

@ -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