From cf8d7ad2ca081d65f4adc9b6429a38e6b04105e9 Mon Sep 17 00:00:00 2001 From: douira Date: Sun, 22 Oct 2023 05:26:10 +0200 Subject: [PATCH] fix: don't check entities if it requires iterating too many sections --- .../mods/sodium/client/render/SodiumWorldRenderer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.java index 15a7aa51be..2a3c693d08 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.java @@ -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. @@ -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); }