diff options
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r-- | src/main/java/ftbsc/bscv/module/self/Freecam.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/module/self/Freecam.java b/src/main/java/ftbsc/bscv/module/self/Freecam.java new file mode 100644 index 0000000..b3eff57 --- /dev/null +++ b/src/main/java/ftbsc/bscv/module/self/Freecam.java @@ -0,0 +1,60 @@ +package ftbsc.bscv.module.self; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.events.PacketEvent; +import ftbsc.bscv.module.QuickModule; +import net.minecraft.command.CommandSource; +import net.minecraft.network.play.client.CPlayerPacket; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.GameType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class Freecam extends QuickModule { + + public final ForgeConfigSpec.ConfigValue<Boolean> log; + + public Freecam(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) { + super("Freecam", Group.SELF, UNBOUND, builder, dispatcher); + + this.log = this.option( + "log", "log canceled packets", false, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + } + + private Vector3d prev_pos = new Vector3d(0.0, 0.0, 0.0); + + @SubscribeEvent + public void onPacket(PacketEvent event) { + if (BoSCoVicino.minecraft.player == null) return; + if (event.outgoing && event.packet instanceof CPlayerPacket) { // TODO must ignore more packets than just this + if (this.log.get()) { + BoSCoVicino.log(String.format("[X] %s", event.packet.getClass().getName())); + } + event.setCanceled(true); + } + } + + @Override + protected void onEnabled() { + if (BoSCoVicino.minecraft.player != null) { + this.prev_pos = BoSCoVicino.minecraft.player.position(); + BoSCoVicino.minecraft.gameMode.setLocalMode(GameType.SPECTATOR); + } + } + + @Override + protected void onDisabled() { + if (BoSCoVicino.minecraft.player != null) { + BoSCoVicino.minecraft.gameMode.setLocalMode(GameType.SURVIVAL); + BoSCoVicino.minecraft.player.setPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); + } + } + +} |