Skip to content

Commit

Permalink
fix: don't check entities if it requires iterating too many sections
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Oct 22, 2023
1 parent eeafb59 commit cf8d7ad
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ private static void renderBlockEntity(MatrixStack matrices,
matrices.pop();
}

// the volume of a section multiplied by the number of sections to be checked at most
private static final double MAX_ENTITY_CHECK_VOLUME = 16 * 16 * 16 * 15;

/**
* Returns whether or not the entity intersects with any visible chunks in the graph.
Expand All @@ -388,6 +390,12 @@ public boolean isEntityVisible(Entity entity) {

Box box = entity.getVisibilityBoundingBox();

// bail on very large entities to avoid checking many sections
double entityVolume = (box.maxX - box.minX) * (box.maxY - box.minY) * (box.maxZ - box.minZ);
if (entityVolume > MAX_ENTITY_CHECK_VOLUME) {
return true;
}

return this.isBoxVisible(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
}

Expand Down

0 comments on commit cf8d7ad

Please sign in to comment.