From 11d4742cb9f4067db45c07f07357bd73697889d4 Mon Sep 17 00:00:00 2001 From: ThebestkillerTBK <2593828650@qq.com> Date: Fri, 16 Dec 2022 17:41:45 +0800 Subject: [PATCH] resolve conflicts --- .../events/world/CollisionShapeEvent.java | 7 +- .../mixin/AbstractBlockMixin.java | 16 --- .../mixin/BlockCollisionSpliteratorMixin.java | 35 ++++++ .../meteorclient/mixin/CactusBlockMixin.java | 32 ----- .../meteorclient/mixin/FluidBlockMixin.java | 31 ----- .../meteorclient/mixin/WorldBorderMixin.java | 27 ++++ .../meteorclient/systems/modules/Modules.java | 2 +- .../systems/modules/movement/SafeWalk.java | 67 +--------- .../systems/modules/world/AntiCactus.java | 15 --- .../systems/modules/world/Collisions.java | 118 ++++++++++++++++++ src/main/resources/meteor-client.mixins.json | 4 +- 11 files changed, 189 insertions(+), 165 deletions(-) create mode 100644 src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java delete mode 100644 src/main/java/meteordevelopment/meteorclient/mixin/CactusBlockMixin.java delete mode 100644 src/main/java/meteordevelopment/meteorclient/mixin/FluidBlockMixin.java create mode 100644 src/main/java/meteordevelopment/meteorclient/mixin/WorldBorderMixin.java delete mode 100644 src/main/java/meteordevelopment/meteorclient/systems/modules/world/AntiCactus.java create mode 100644 src/main/java/meteordevelopment/meteorclient/systems/modules/world/Collisions.java diff --git a/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java b/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java index f34f3a8bec..14d183c0c8 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java @@ -5,11 +5,12 @@ package meteordevelopment.meteorclient.events.world; +import meteordevelopment.meteorclient.events.Cancellable; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; -public class CollisionShapeEvent { +public class CollisionShapeEvent extends Cancellable { public enum CollisionType { BLOCK, FLUID @@ -22,10 +23,10 @@ public enum CollisionType { public VoxelShape shape; public CollisionType type; - public static CollisionShapeEvent get(BlockState state, BlockPos pos, CollisionType type) { + public static CollisionShapeEvent get(BlockState state, BlockPos pos, VoxelShape shape, CollisionType type) { INSTANCE.state = state; INSTANCE.pos = pos; - INSTANCE.shape = null; + INSTANCE.shape = shape; INSTANCE.type = type; return INSTANCE; } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java index 5b262cd667..acea24a485 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java @@ -7,12 +7,9 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.world.AmbientOcclusionEvent; -import meteordevelopment.meteorclient.events.world.CollisionShapeEvent; import net.minecraft.block.AbstractBlock; import net.minecraft.block.BlockState; -import net.minecraft.block.ShapeContext; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -27,17 +24,4 @@ private void onGetAmbientOcclusionLightLevel(BlockState state, BlockView world, if (event.lightLevel != -1) info.setReturnValue(event.lightLevel); } - - @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) - private void onGetCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context, CallbackInfoReturnable info) { - if (!(state.getFluidState().isEmpty())) { - CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state.getFluidState().getBlockState(), pos, CollisionShapeEvent.CollisionType.FLUID)); - - if (event.shape != null) info.setReturnValue(event.shape); - } else { - CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, CollisionShapeEvent.CollisionType.BLOCK)); - - if (event.shape != null) info.setReturnValue(event.shape); - } - } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java new file mode 100644 index 0000000000..2fc9a0d734 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java @@ -0,0 +1,35 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.events.world.CollisionShapeEvent; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockCollisionSpliterator; +import net.minecraft.world.BlockView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BlockCollisionSpliterator.class) +public class BlockCollisionSpliteratorMixin { + @Redirect(method = "computeNext", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;")) + private VoxelShape onComputeNextCollisionBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + VoxelShape shape = state.getCollisionShape(world, pos, context); + CollisionShapeEvent event = state.getFluidState().isEmpty() + ? MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, shape, CollisionShapeEvent.CollisionType.BLOCK)) + : MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state.getFluidState().getBlockState(), pos, shape, CollisionShapeEvent.CollisionType.FLUID)); + + if (event.isCancelled()) + return VoxelShapes.empty(); + else + return event.shape; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CactusBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CactusBlockMixin.java deleted file mode 100644 index 7014cdba20..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CactusBlockMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import meteordevelopment.meteorclient.systems.modules.Modules; -import meteordevelopment.meteorclient.systems.modules.world.AntiCactus; -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.block.ShapeContext; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(CactusBlock.class) -public class CactusBlockMixin { - @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) - private void onGetCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable info) { - Modules modules = Modules.get(); - - if (modules != null && modules.isActive(AntiCactus.class)) { - info.setReturnValue(VoxelShapes.fullCube()); - } - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FluidBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FluidBlockMixin.java deleted file mode 100644 index 8b1407aafd..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FluidBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import meteordevelopment.meteorclient.MeteorClient; -import meteordevelopment.meteorclient.events.world.CollisionShapeEvent; -import net.minecraft.block.*; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(FluidBlock.class) -public abstract class FluidBlockMixin extends Block implements FluidDrainable { - public FluidBlockMixin(Settings settings) { - super(settings); - } - - @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) - private void onGetCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context, CallbackInfoReturnable info) { - CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, CollisionShapeEvent.CollisionType.FLUID)); - - if (event.shape != null) info.setReturnValue(event.shape); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/WorldBorderMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/WorldBorderMixin.java new file mode 100644 index 0000000000..e92c975fcd --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/WorldBorderMixin.java @@ -0,0 +1,27 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.world.Collisions; +import net.minecraft.world.border.WorldBorder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(WorldBorder.class) +public abstract class WorldBorderMixin { + @Inject(method = "canCollide", at = @At("HEAD"), cancellable = true) + private void canCollide(CallbackInfoReturnable info) { + if (Modules.get().get(Collisions.class).ignoreBorder()) info.setReturnValue(false); + } + + @Inject(method = "contains(Lnet/minecraft/util/math/BlockPos;)Z", at = @At("HEAD"), cancellable = true) + private void contains(CallbackInfoReturnable info) { + if (Modules.get().get(Collisions.class).ignoreBorder()) info.setReturnValue(true); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java index 7894c2b2c8..b30d354da0 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java @@ -521,7 +521,7 @@ private void initRender() { private void initWorld() { add(new AirPlace()); add(new Ambience()); - add(new AntiCactus()); + add(new Collisions()); add(new AutoBreed()); add(new AutoBrewer()); add(new AutoMount()); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/SafeWalk.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/SafeWalk.java index 8db34ac51f..4c0118cf31 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/SafeWalk.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/SafeWalk.java @@ -6,80 +6,17 @@ package meteordevelopment.meteorclient.systems.modules.movement; import meteordevelopment.meteorclient.events.entity.player.ClipAtLedgeEvent; -import meteordevelopment.meteorclient.events.world.CollisionShapeEvent; -import meteordevelopment.meteorclient.settings.BlockListSetting; -import meteordevelopment.meteorclient.settings.BoolSetting; -import meteordevelopment.meteorclient.settings.Setting; -import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.orbit.EventHandler; -import net.minecraft.block.*; -import net.minecraft.util.shape.VoxelShapes; - -import java.util.List; public class SafeWalk extends Module { - private final SettingGroup sgGeneral = settings.getDefaultGroup(); - - private final Setting ledge = sgGeneral.add(new BoolSetting.Builder() - .name("ledge") - .description("Prevents you from walking of blocks, like pressing shift.") - .defaultValue(true) - .build() - ); - - private final Setting> blocks = sgGeneral.add(new BlockListSetting.Builder() - .name("blocks") - .description("Which blocks to prevent on walking") - .filter(this::blockFilter) - .build() - ); - - private final Setting magma = sgGeneral.add(new BoolSetting.Builder() - .name("magma") - .description("Prevents you from walking over magma blocks.") - .defaultValue(false) - .build() - ); - public SafeWalk() { - super(Categories.Movement, "safe-walk", "Prevents you from walking off blocks or on blocks that you dont want."); + super(Categories.Movement, "safe-walk", "Prevents you from walking off blocks."); } @EventHandler private void onClipAtLedge(ClipAtLedgeEvent event) { - if (!mc.player.isSneaking()) event.setClip(ledge.get()); - } - - @EventHandler - private void onCollisionShape(CollisionShapeEvent event) { - if (mc.world == null || mc.player == null) return; - if (event.type != CollisionShapeEvent.CollisionType.BLOCK) return; - if (blocks.get().contains(event.state.getBlock())) { - event.shape = VoxelShapes.fullCube(); - } - else if (magma.get() && !mc.player.isSneaking() - && event.state.isAir() - && mc.world.getBlockState(event.pos.down()).getBlock() == Blocks.MAGMA_BLOCK) { - event.shape = VoxelShapes.fullCube(); - } - } - - private boolean blockFilter(Block block) { - return (block instanceof AbstractFireBlock - || block instanceof AbstractPressurePlateBlock - || block instanceof TripwireBlock - || block instanceof TripwireHookBlock - || block instanceof CobwebBlock - || block instanceof CampfireBlock - || block instanceof SweetBerryBushBlock - || block instanceof CactusBlock - || block instanceof AbstractRailBlock - || block instanceof TrapdoorBlock - || block instanceof PowderSnowBlock - || block instanceof AbstractCauldronBlock - || block instanceof HoneyBlock - ); + if (!mc.player.isSneaking()) event.setClip(true); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AntiCactus.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AntiCactus.java deleted file mode 100644 index 499c06ea22..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AntiCactus.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.systems.modules.world; - -import meteordevelopment.meteorclient.systems.modules.Categories; -import meteordevelopment.meteorclient.systems.modules.Module; - -public class AntiCactus extends Module { - public AntiCactus() { - super(Categories.World, "anti-cactus", "Prevents you from taking damage from cacti."); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Collisions.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Collisions.java new file mode 100644 index 0000000000..d53feaa2b1 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Collisions.java @@ -0,0 +1,118 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.systems.modules.world; + +import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent; +import meteordevelopment.meteorclient.events.packets.PacketEvent; +import meteordevelopment.meteorclient.events.world.CollisionShapeEvent; +import meteordevelopment.meteorclient.mixininterface.IVec3d; +import meteordevelopment.meteorclient.settings.BlockListSetting; +import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.SettingGroup; +import meteordevelopment.meteorclient.systems.modules.Categories; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.block.*; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; +import net.minecraft.network.packet.c2s.play.VehicleMoveC2SPacket; +import net.minecraft.util.shape.VoxelShapes; + +import java.util.List; + +public class Collisions extends Module { + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + public final Setting> blocks = sgGeneral.add(new BlockListSetting.Builder() + .name("blocks") + .description("What blocks should be added collision box.") + .filter(this::blockFilter) + .build() + ); + + private final Setting magma = sgGeneral.add(new BoolSetting.Builder() + .name("magma") + .description("Prevents you from walking over magma blocks.") + .defaultValue(false) + .build() + ); + + private final Setting unloadedChunks = sgGeneral.add(new BoolSetting.Builder() + .name("unloaded-chunks") + .description("Stops you from going into unloaded chunks.") + .defaultValue(false) + .build() + ); + + private final Setting ignoreBorder = sgGeneral.add(new BoolSetting.Builder() + .name("ignore-border") + .description("Removes world border collision.") + .defaultValue(false) + .build() + ); + + public Collisions() { + super(Categories.World, "collisions", "Adds collision boxes to certain blocks/areas."); + } + + @EventHandler + private void onCollisionShape(CollisionShapeEvent event) { + if (mc.world == null || mc.player == null) return; + if (event.type != CollisionShapeEvent.CollisionType.BLOCK) return; + if (blocks.get().contains(event.state.getBlock())) { + event.shape = VoxelShapes.fullCube(); + } else if (magma.get() && !mc.player.isSneaking() + && event.state.isAir() + && mc.world.getBlockState(event.pos.down()).getBlock() == Blocks.MAGMA_BLOCK) { + event.shape = VoxelShapes.fullCube(); + } + } + + @EventHandler + private void onPlayerMove(PlayerMoveEvent event) { + int x = (int) (mc.player.getX() + event.movement.x) >> 4; + int z = (int) (mc.player.getZ() + event.movement.z) >> 4; + if (unloadedChunks.get() && !mc.world.getChunkManager().isChunkLoaded(x, z)) { + ((IVec3d) event.movement).set(0, event.movement.y, 0); + } + } + + @EventHandler + private void onPacketSend(PacketEvent.Send event) { + if (!unloadedChunks.get()) return; + if (event.packet instanceof VehicleMoveC2SPacket packet) { + if (!mc.world.getChunkManager().isChunkLoaded((int) packet.getX() >> 4, (int) packet.getZ() >> 4)) { + mc.player.getVehicle().updatePosition(mc.player.getVehicle().prevX, mc.player.getVehicle().prevY, mc.player.getVehicle().prevZ); + event.cancel(); + } + } else if (event.packet instanceof PlayerMoveC2SPacket packet) { + if (!mc.world.getChunkManager().isChunkLoaded((int) packet.getX(mc.player.getX()) >> 4, (int) packet.getZ(mc.player.getZ()) >> 4)) { + event.cancel(); + } + } + } + + private boolean blockFilter(Block block) { + return (block instanceof AbstractFireBlock + || block instanceof AbstractPressurePlateBlock + || block instanceof TripwireBlock + || block instanceof TripwireHookBlock + || block instanceof CobwebBlock + || block instanceof CampfireBlock + || block instanceof SweetBerryBushBlock + || block instanceof CactusBlock + || block instanceof AbstractRailBlock + || block instanceof TrapdoorBlock + || block instanceof PowderSnowBlock + || block instanceof AbstractCauldronBlock + || block instanceof HoneyBlock + ); + } + + public boolean ignoreBorder() { + return isActive() && ignoreBorder.get(); + } +} diff --git a/src/main/resources/meteor-client.mixins.json b/src/main/resources/meteor-client.mixins.json index 78d8a73cb9..d530d323f4 100644 --- a/src/main/resources/meteor-client.mixins.json +++ b/src/main/resources/meteor-client.mixins.json @@ -16,6 +16,7 @@ "BannerBlockEntityRendererMixin", "BeaconScreenMixin", "BiomeColorsMixin", + "BlockCollisionSpliteratorMixin", "BlockEntityRenderDispatcherMixin", "BlockEntityTypeAccessor", "BlockHitResultAccessor", @@ -32,7 +33,6 @@ "BrewingStandScreenMixin", "BufferBuilderAccessor", "BufferRendererAccessor", - "CactusBlockMixin", "CameraMixin", "CapabilityTrackerMixin", "ChatHudAccessor", @@ -79,7 +79,6 @@ "FireworkRocketEntityMixin", "FireworksSparkParticleMixin", "FireworksSparkParticleSubMixin", - "FluidBlockMixin", "FluidRendererMixin", "FoliageColorsMixin", "GameOptionsMixin", @@ -153,6 +152,7 @@ "Vec3dMixin", "VertexBufferMixin", "WorldAccessor", + "WorldBorderMixin", "WorldChunkMixin", "WorldRendererAccessor", "WorldRendererMixin"