Skip to content

Commit

Permalink
Fix experimental minecart collisions on sloped rails
Browse files Browse the repository at this point in the history
We are supposed to ignore some collisions on the sloped
rail.
  • Loading branch information
Spottedleaf committed Nov 14, 2024
1 parent ea50ba3 commit 1e39f53
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

1 comment on commit 1e39f53

@EterNityCH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.