Skip to content

Commit

Permalink
Fix random sneaking and collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
MineGame159 committed Jun 28, 2023
1 parent f990472 commit e2854ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package meteordevelopment.meteorclient.events.world;

import com.mojang.blaze3d.systems.RenderSystem;
import meteordevelopment.meteorclient.events.Cancellable;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
Expand All @@ -18,10 +19,17 @@ public class CollisionShapeEvent extends Cancellable {
public VoxelShape shape;

public static CollisionShapeEvent get(BlockState state, BlockPos pos, VoxelShape shape) {
INSTANCE.setCancelled(false);
INSTANCE.state = state;
INSTANCE.pos = pos;
INSTANCE.shape = shape;
return INSTANCE;
CollisionShapeEvent event = INSTANCE;

if (!RenderSystem.isOnRenderThread()) {
event = new CollisionShapeEvent();
}

event.setCancelled(false);
event.state = state;
event.pos = pos;
event.shape = shape;

return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
Expand All @@ -22,7 +23,12 @@
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) {
CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, state.getCollisionShape(world, pos, context)));
VoxelShape shape = state.getCollisionShape(world, pos, context);

if (world != MinecraftClient.getInstance().world)
return shape;

CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, shape));
return event.isCancelled() ? VoxelShapes.empty() : event.shape;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
Expand All @@ -22,7 +23,12 @@
public abstract class ChunkAwareBlockCollisionSweeperMixin {
@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) {
CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, state.getCollisionShape(world, pos, context)));
VoxelShape shape = state.getCollisionShape(world, pos, context);

if (world != MinecraftClient.getInstance().world)
return shape;

CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, shape));
return event.isCancelled() ? VoxelShapes.empty() : event.shape;
}
}

0 comments on commit e2854ce

Please sign in to comment.