Skip to content

Commit

Permalink
fix: Use correct box for world border collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Jun 13, 2024
1 parent ae9e1ae commit 1ffa3cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static List<VoxelShape> getBlockCollisions(World world, Entity entity, Bo
/***
* @return True if the box (possibly that of an entity's) collided with any blocks
*/
public static boolean doesBoxCollideWithBlocks(World world, Entity entity, Box box) {
public static boolean doesBoxCollideWithBlocks(World world, @Nullable Entity entity, Box box) {
final ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, entity, box);

final VoxelShape shape = sweeper.computeNext();
Expand All @@ -55,7 +55,7 @@ public static boolean doesBoxCollideWithBlocks(World world, Entity entity, Box b
/**
* @return True if the box (possibly that of an entity's) collided with any other hard entities
*/
public static boolean doesBoxCollideWithHardEntities(EntityView view, Entity entity, Box box) {
public static boolean doesBoxCollideWithHardEntities(EntityView view, @Nullable Entity entity, Box box) {
if (isBoxEmpty(box)) {
return false;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static void appendWorldBorderCollision(ArrayList<VoxelShape> worldBorderC
* Re-implements the function named above without stream code or unnecessary allocations. This can provide a small
* boost in some situations (such as heavy entity crowding) and reduces the allocation rate significantly.
*/
public static Iterable<VoxelShape> getEntityWorldBorderCollisionIterable(EntityView view, Entity entity, Box box, boolean includeWorldBorder) {
public static Iterable<VoxelShape> getEntityWorldBorderCollisionIterable(EntityView view, @Nullable Entity entity, Box box, boolean includeWorldBorder) {
assert !includeWorldBorder || entity != null;
return new Iterable<>() {
private List<Entity> entityList;
Expand Down Expand Up @@ -194,17 +194,16 @@ private static boolean isBoxEmpty(Box box) {
return box.getAverageSideLength() <= EPSILON;
}

public static boolean doesEntityCollideWithWorldBorder(CollisionView collisionView, Entity entity) {
if (isWithinWorldBorder(collisionView.getWorldBorder(), entity.getBoundingBox())) {
public static boolean doesBoxCollideWithWorldBorder(CollisionView collisionView, Entity entity, Box box) {
if (isWithinWorldBorder(collisionView.getWorldBorder(), box)) {
return false;
} else {
VoxelShape worldBorderShape = getWorldBorderCollision(collisionView, entity);
return worldBorderShape != null && VoxelShapes.matchesAnywhere(worldBorderShape, VoxelShapes.cuboid(entity.getBoundingBox()), BooleanBiFunction.AND);
VoxelShape worldBorderShape = getWorldBorderCollision(collisionView, entity, box);
return worldBorderShape != null && VoxelShapes.matchesAnywhere(worldBorderShape, VoxelShapes.cuboid(box), BooleanBiFunction.AND);
}
}

public static VoxelShape getWorldBorderCollision(CollisionView collisionView, Entity entity) {
Box box = entity.getBoundingBox();
public static VoxelShape getWorldBorderCollision(CollisionView collisionView, @Nullable Entity entity, Box box) {
WorldBorder worldBorder = collisionView.getWorldBorder();
return worldBorder.canCollide(entity, box) ? worldBorder.asVoxelShape() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.ChunkStatus;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -72,10 +73,10 @@ public class ChunkAwareBlockCollisionSweeper extends AbstractIterator<VoxelShape
private Chunk cachedChunk;
private ChunkSection cachedChunkSection;

public ChunkAwareBlockCollisionSweeper(World world, Entity entity, Box box) {
public ChunkAwareBlockCollisionSweeper(World world, @Nullable Entity entity, Box box) {
this(world, entity, box, false);
}
public ChunkAwareBlockCollisionSweeper(World world, Entity entity, Box box, boolean hideLastCollision) {
public ChunkAwareBlockCollisionSweeper(World world, @Nullable Entity entity, Box box, boolean hideLastCollision) {
this.box = box;
this.shape = VoxelShapes.cuboid(box);
this.context = entity == null ? ShapeContext.absent() : ShapeContext.of(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean isSpaceEmpty(@Nullable Entity entity, Box box) {
}

if (ret && entity != null) {
ret = !LithiumEntityCollisions.doesEntityCollideWithWorldBorder(this, entity);
ret = !LithiumEntityCollisions.doesBoxCollideWithWorldBorder(this, entity, box);
}

return ret;
Expand Down

0 comments on commit 1ffa3cf

Please sign in to comment.