Fix experimental minecart collisions on sloped rails

We are supposed to ignore some collisions on the sloped
rail.
This commit is contained in:
Spottedleaf
2024-11-14 21:01:04 -08:00
parent 41085fc8b9
commit d0a2d92713
2 changed files with 340 additions and 324 deletions

View File

@@ -16184,7 +16184,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+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;
@@ -18113,6 +18115,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ 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) {
@@ -18198,7 +18201,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ 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);
+ }
@@ -18320,6 +18326,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ 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;
@@ -18351,6 +18361,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ 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() {