chore: moved boatpatch stuff into boatpatch class

This commit is contained in:
əlemi 2023-03-11 22:52:05 +01:00
parent 0a2609ac0c
commit f0488fdd5d
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 31 additions and 43 deletions

View file

@ -1,22 +0,0 @@
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(); }
}
}

View file

@ -1,10 +1,9 @@
package ftbsc.bscv.modules.motion; package ftbsc.bscv.modules.motion;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.BoatEvent;
import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.BoatPatch.BoatEvent;
import ftbsc.bscv.tools.Keyboard; import ftbsc.bscv.tools.Keyboard;
import ftbsc.bscv.tools.Setting; import ftbsc.bscv.tools.Setting;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -15,7 +14,7 @@ import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@AutoService(ILoadable.class) @AutoService(ILoadable.class)
public class BoatFly extends AbstractModule implements ICommons { public class BoatFly extends AbstractModule {
public final ForgeConfigSpec.ConfigValue<Double> speed; public final ForgeConfigSpec.ConfigValue<Double> speed;
public final ForgeConfigSpec.ConfigValue<Double> rise; public final ForgeConfigSpec.ConfigValue<Double> rise;

View file

@ -1,7 +1,6 @@
package ftbsc.bscv.patches; package ftbsc.bscv.patches;
import ftbsc.bscv.ICommons; import ftbsc.bscv.ICommons;
import ftbsc.bscv.events.BoatEvent;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
@ -9,12 +8,25 @@ import ftbsc.lll.tools.InsnSequence;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.BoatEntity; import net.minecraft.entity.item.BoatEntity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.*;
public class BoatPatch { public class BoatPatch implements ICommons {
public static class BoatEvent {
@Cancelable
public static class Control extends Event { }
@Cancelable
public static class ClampRotation extends Event { }
@Cancelable
public static class Gravity extends Event { }
}
public static class BoatHook implements ICommons {
public static boolean boatControl() { public static boolean boatControl() {
return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control());
} }
@ -29,7 +41,6 @@ public class BoatPatch {
if (MC.player.getVehicle() != entity) return false; if (MC.player.getVehicle() != entity) return false;
return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity());
} }
}
@Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls") @Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls")
public abstract static class BoatControlOverride implements Opcodes { public abstract static class BoatControlOverride implements Opcodes {
@ -43,7 +54,7 @@ public class BoatPatch {
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodInsnNode( is.add(new MethodInsnNode(
INVOKESTATIC, INVOKESTATIC,
"ftbsc/bscv/patches/BoatPatch$BoatHook", "ftbsc/bscv/patches/BoatPatch",
"boatControl", "boatControl",
"()Z" "()Z"
)); ));
@ -67,7 +78,7 @@ public class BoatPatch {
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodInsnNode( is.add(new MethodInsnNode(
INVOKESTATIC, INVOKESTATIC,
"ftbsc/bscv/patches/BoatPatch$BoatHook", "ftbsc/bscv/patches/BoatPatch",
"boatClampRotation", "boatClampRotation",
"()Z" "()Z"
)); ));
@ -92,7 +103,7 @@ public class BoatPatch {
is.add(new VarInsnNode(ALOAD, 0)); is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodInsnNode( is.add(new MethodInsnNode(
INVOKESTATIC, INVOKESTATIC,
"ftbsc/bscv/patches/BoatPatch$BoatHook", "ftbsc/bscv/patches/BoatPatch",
"boatGravityCheck", "boatGravityCheck",
"(Lnet/minecraft/entity/Entity;)Z" "(Lnet/minecraft/entity/Entity;)Z"
)); ));