diff --git a/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java b/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java index c4aaea97eb..b759780555 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/world/CollisionShapeEvent.java @@ -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; @@ -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; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java index 026acc0e73..f51dc897b0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java @@ -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; @@ -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; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/lithium/ChunkAwareBlockCollisionSweeperMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/lithium/ChunkAwareBlockCollisionSweeperMixin.java index 1ada66b788..eb15d0e2b1 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/lithium/ChunkAwareBlockCollisionSweeperMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/lithium/ChunkAwareBlockCollisionSweeperMixin.java @@ -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; @@ -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; } }