Make worldborder collisions consistent with Vanilla

Vanilla now requires the use of WorldBorder#isInsideCloseToBorder
to consider a border collision
This commit is contained in:
Spottedleaf
2023-12-18 16:47:43 -08:00
parent bb6d1f2aaa
commit cf5a5b3a30
3 changed files with 11 additions and 41 deletions

View File

@@ -147,14 +147,10 @@ public abstract class EntityMixin implements CollisionEntity {
CollisionUtil.getCollisions(
world, (Entity)(Object)this, collisionBox, potentialCollisionsVoxel, potentialCollisionsBB,
(0),
CollisionUtil.COLLISION_FLAG_CHECK_BORDER,
null, null
);
if (CollisionUtil.isCollidingWithBorderEdge(world.getWorldBorder(), collisionBox)) {
potentialCollisionsVoxel.add(world.getWorldBorder().getCollisionShape());
}
if (potentialCollisionsVoxel.isEmpty() && potentialCollisionsBB.isEmpty()) {
return movement;
}

View File

@@ -23,6 +23,7 @@ import net.minecraft.world.level.block.entity.Hopper;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.VoxelShape;
@@ -188,7 +189,7 @@ public abstract class HopperBlockEntityMixin extends RandomizableContainerBlockE
final int blockY = Mth.floor(y);
final int blockZ = Mth.floor(z);
final LevelChunk chunk = level.getChunk(blockX >> 4, blockZ >> 4);
final LevelChunk chunk = (LevelChunk)level.getChunkSource().getChunk(blockX >> 4, blockZ >> 4, ChunkStatus.FULL, true);
final BlockState state = ((GetBlockChunk)chunk).moonrise$getBlock(blockX, blockY, blockZ);
final Block block = state.getBlock();

View File

@@ -1584,41 +1584,13 @@ public final class CollisionUtil {
return new Vec3(x, y, z);
}
public static boolean isAlmostCollidingOnBorder(final WorldBorder worldborder, final AABB boundingBox) {
return isAlmostCollidingOnBorder(worldborder, boundingBox.minX, boundingBox.maxX, boundingBox.minZ, boundingBox.maxZ);
public static boolean isCollidingWithBorder(final WorldBorder worldborder, final AABB boundingBox) {
return isCollidingWithBorder(worldborder, boundingBox.minX, boundingBox.maxX, boundingBox.minZ, boundingBox.maxZ);
}
public static boolean isAlmostCollidingOnBorder(final WorldBorder worldborder, final double boxMinX, final double boxMaxX,
final double boxMinZ, final double boxMaxZ) {
final double borderMinX = worldborder.getMinX(); // -X
final double borderMaxX = worldborder.getMaxX(); // +X
final double borderMinZ = worldborder.getMinZ(); // -Z
final double borderMaxZ = worldborder.getMaxZ(); // +Z
return
// Not intersecting if we're smaller
!voxelShapeIntersect(
boxMinX + COLLISION_EPSILON, Double.NEGATIVE_INFINITY, boxMinZ + COLLISION_EPSILON,
boxMaxX - COLLISION_EPSILON, Double.POSITIVE_INFINITY, boxMaxZ - COLLISION_EPSILON,
borderMinX, Double.NEGATIVE_INFINITY, borderMinZ, borderMaxX, Double.POSITIVE_INFINITY, borderMaxZ
)
&&
// Are intersecting if we're larger
voxelShapeIntersect(
boxMinX - COLLISION_EPSILON, Double.NEGATIVE_INFINITY, boxMinZ - COLLISION_EPSILON,
boxMaxX + COLLISION_EPSILON, Double.POSITIVE_INFINITY, boxMaxZ + COLLISION_EPSILON,
borderMinX, Double.NEGATIVE_INFINITY, borderMinZ, borderMaxX, Double.POSITIVE_INFINITY, borderMaxZ
);
}
public static boolean isCollidingWithBorderEdge(final WorldBorder worldborder, final AABB boundingBox) {
return isCollidingWithBorderEdge(worldborder, boundingBox.minX, boundingBox.maxX, boundingBox.minZ, boundingBox.maxZ);
}
public static boolean isCollidingWithBorderEdge(final WorldBorder worldborder, final double boxMinX, final double boxMaxX,
final double boxMinZ, final double boxMaxZ) {
public static boolean isCollidingWithBorder(final WorldBorder worldborder,
final double boxMinX, final double boxMaxX,
final double boxMinZ, final double boxMaxZ) {
final double borderMinX = worldborder.getMinX(); // -X
final double borderMaxX = worldborder.getMaxX(); // +X
@@ -1651,11 +1623,12 @@ public final class CollisionUtil {
boolean ret = false;
if ((collisionFlags & COLLISION_FLAG_CHECK_BORDER) != 0) {
if (CollisionUtil.isCollidingWithBorderEdge(world.getWorldBorder(), aabb)) {
final WorldBorder worldBorder = world.getWorldBorder();
if (CollisionUtil.isCollidingWithBorder(worldBorder, aabb) && entity != null && worldBorder.isInsideCloseToBorder(entity, aabb)) {
if (checkOnly) {
return true;
} else {
final VoxelShape borderShape = world.getWorldBorder().getCollisionShape();
final VoxelShape borderShape = worldBorder.getCollisionShape();
intoVoxel.add(borderShape);
ret = true;
}