feat: added Immovable mod

This commit is contained in:
əlemi 2023-03-11 22:47:11 +01:00
parent d5aee8289f
commit 0a2609ac0c
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 234 additions and 0 deletions

View file

@ -0,0 +1,85 @@
package ftbsc.bscv.modules.self;
import com.google.auto.service.AutoService;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.patches.BlockPushPatch.PlayerBlockPushEvent;
import ftbsc.bscv.patches.EntityPushPatch.PlayerEntityPushEvent;
import ftbsc.bscv.patches.LiquidPushPatch.PlayerLiquidPushEvent;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.server.SEntityVelocityPacket;
import net.minecraft.network.play.server.SExplosionPacket;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@AutoService(ILoadable.class)
public class Immovable extends AbstractModule {
public final ForgeConfigSpec.ConfigValue<Boolean> explosions;
public final ForgeConfigSpec.ConfigValue<Boolean> server;
public final ForgeConfigSpec.ConfigValue<Boolean> liquids;
public final ForgeConfigSpec.ConfigValue<Boolean> entities;
public final ForgeConfigSpec.ConfigValue<Boolean> blocks;
public Immovable() {
super();
this.explosions = Setting.Bool.builder()
.fallback(true)
.name("explosions")
.comment("cancel velocity from explosions")
.build(this);
this.server = Setting.Bool.builder()
.fallback(true)
.name("server")
.comment("cancel velocity sent from server")
.build(this);
this.liquids = Setting.Bool.builder()
.fallback(true)
.name("liquids")
.comment("cancel velocity from liquids pushing")
.build(this);
this.entities = Setting.Bool.builder()
.fallback(true)
.name("entities")
.comment("cancel velocity from entities pushing")
.build(this);
this.blocks = Setting.Bool.builder()
.fallback(true)
.name("block")
.comment("cancel velocity from blocks pushing")
.build(this);
}
@SubscribeEvent
public void onPacket(PacketEvent.Incoming event) {
if (event.packet instanceof SExplosionPacket && this.explosions.get()) {
event.setCanceled(true);
}
if (event.packet instanceof SEntityVelocityPacket && this.server.get()) {
SEntityVelocityPacket packet = (SEntityVelocityPacket) event.packet;
if (packet.getId() == MC.player.getId()) {
event.setCanceled(true);
}
}
}
@SubscribeEvent
public void onEntityCollisions(PlayerEntityPushEvent event) {
if (this.entities.get()) event.setCanceled(true);
}
@SubscribeEvent
public void onBlockCollisions(PlayerBlockPushEvent event) {
if (this.blocks.get()) event.setCanceled(true);
}
@SubscribeEvent
public void onLiquidCollisions(PlayerLiquidPushEvent event) {
if (this.liquids.get()) event.setCanceled(true);
}
}

View file

@ -0,0 +1,46 @@
package ftbsc.bscv.patches;
import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.tools.InsnSequence;
import net.minecraft.client.entity.player.ClientPlayerEntity;
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.tree.*;
public class BlockPushPatch {
@Cancelable
public static class PlayerBlockPushEvent extends Event {}
public static boolean shouldCancelBlockCollisions() {
return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent());
}
@Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel block collisions")
public abstract static class BlockCollisionsOverride implements Opcodes {
@Target
abstract void moveTowardsClosestSpace(double x, double z);
@Injector
public void inject(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence();
is.add(new MethodInsnNode(
INVOKESTATIC,
"ftbsc/bscv/patches/BlockPushPatch",
"shouldCancelBlockCollisions",
"()Z"
));
is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN));
is.add(skip);
main.instructions.insert(is); // hook at top
}
}
}

View file

@ -0,0 +1,51 @@
package ftbsc.bscv.patches;
import ftbsc.bscv.ICommons;
import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.tools.InsnSequence;
import net.minecraft.entity.Entity;
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.tree.*;
public class EntityPushPatch implements ICommons {
@Cancelable
public static class PlayerEntityPushEvent extends Event {}
public static boolean shouldCancelEntityCollisions(Entity e) {
if (e.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerEntityPushEvent());
}
return false;
}
@Patch(value = Entity.class, reason = "add hook to cancel entity collisions")
public abstract static class EntityCollisionsOverride implements Opcodes {
@Target
abstract void push(double x, double y, double z);
@Injector
public void inject(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodInsnNode(
INVOKESTATIC,
"ftbsc/bscv/patches/EntityPushPatch",
"shouldCancelEntityCollisions",
"(Lnet/minecraft/entity/Entity;)Z"
));
is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN));
is.add(skip);
main.instructions.insert(is); // hook at top
}
}
}

View file

@ -0,0 +1,52 @@
package ftbsc.bscv.patches;
import ftbsc.bscv.ICommons;
import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.tools.InsnSequence;
import net.minecraft.entity.player.PlayerEntity;
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.tree.*;
public class LiquidPushPatch implements ICommons {
@Cancelable
public static class PlayerLiquidPushEvent extends Event {}
public static boolean shouldCancelLiquidCollisions(PlayerEntity player) {
if (player.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerLiquidPushEvent());
}
return false;
}
@Patch(value = PlayerEntity.class, reason = "add hook to cancel liquid collisions")
public abstract static class LiquidCollisionsOverride implements Opcodes {
@Target
abstract boolean isPushedByFluid();
@Injector
public void inject(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodInsnNode(
INVOKESTATIC,
"ftbsc/bscv/patches/LiquidPushPatch",
"shouldCancelLiquidCollisions",
"(Lnet/minecraft/entity/player/PlayerEntity;)Z"
));
is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(ICONST_0));
is.add(new InsnNode(IRETURN));
is.add(skip);
main.instructions.insert(is); // hook at top
}
}
}