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 authored Oct 31, 2023
1 parent 6cec89b commit baef6db
Showing 1 changed file with 9 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,13 @@ 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) {
// TODO: do a frustum check instead, even large entities aren't visible if they're outside the frustum
return true;
}

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

Expand Down

0 comments on commit baef6db

Please sign in to comment.