From 1e39f5370a7831aae3322649e7144fc6b074047e Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 14 Nov 2024 13:31:22 -0800 Subject: [PATCH] Fix experimental minecart collisions on sloped rails We are supposed to ignore some collisions on the sloped rail. --- .../patches/collisions/CollisionUtil.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java index 3abd4ad6..aec503ca 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java @@ -14,7 +14,9 @@ import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.item.Item; +import net.minecraft.world.level.CollisionGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -1943,6 +1945,7 @@ public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, fin final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(); final CollisionContext collisionShape = new LazyEntityCollisionContext(entity); + final boolean useEntityCollisionShape = LazyEntityCollisionContext.useEntityCollisionShape(world, entity); // special cases: if (minBlockY > maxBlockY) { @@ -2028,7 +2031,10 @@ public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, fin VoxelShape blockCollision = ((CollisionBlockState)blockData).moonrise$getConstantContextCollisionShape(); if (edgeCount == 0 || ((edgeCount != 1 || blockData.hasLargeCollisionShape()) && (edgeCount != 2 || blockData.getBlock() == Blocks.MOVING_PISTON))) { - if (blockCollision == null) { + if (useEntityCollisionShape) { + mutablePos.set(blockX, blockY, blockZ); + blockCollision = collisionShape.getCollisionShape(blockData, world, mutablePos); + } else if (blockCollision == null) { mutablePos.set(blockX, blockY, blockZ); blockCollision = blockData.getCollisionShape(world, mutablePos, collisionShape); } @@ -2150,6 +2156,10 @@ public LazyEntityCollisionContext(final Entity entity) { super(false, 0.0, null, null, entity); } + public static boolean useEntityCollisionShape(final Level world, final Entity entity) { + return entity instanceof AbstractMinecart && AbstractMinecart.useExperimentalMovement(world); + } + public boolean isDelegated() { final boolean delegated = this.delegated; this.delegated = false; @@ -2181,6 +2191,11 @@ public boolean isHoldingItem(final Item item) { public boolean canStandOnFluid(final FluidState state, final FluidState fluidState) { return this.getDelegate().canStandOnFluid(state, fluidState); } + + @Override + public VoxelShape getCollisionShape(final BlockState blockState, final CollisionGetter collisionGetter, final BlockPos blockPos) { + return this.getDelegate().getCollisionShape(blockState, collisionGetter, blockPos); + } } private CollisionUtil() {