From 2cff88598d1d99e61a3a78b57eff13e02f66966f Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sat, 21 Oct 2023 12:59:15 -0400 Subject: [PATCH] Sort by distance from region center instead of origin --- .../client/render/chunk/lists/SortedRenderLists.java | 6 +++--- .../client/render/chunk/region/RenderRegion.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists.java index fabfbb2575..25365a3b15 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists.java @@ -53,9 +53,9 @@ public SortedRenderLists build(Vec3d cameraPos) { for (int i = 0; i < this.lists.size(); i++) { ChunkRenderList renderList = this.lists.get(i); RenderRegion region = renderList.getRegion(); - double dx = cameraPos.x - region.getOriginX(); - double dy = cameraPos.y - region.getOriginY(); - double dz = cameraPos.z - region.getOriginZ(); + double dx = cameraPos.x - region.getCenterX(); + double dy = cameraPos.y - region.getCenterY(); + double dz = cameraPos.z - region.getCenterZ(); renderList.setDistanceFromCamera((dx * dx) + (dy * dy) + (dz * dz)); } this.lists.sort(LIST_DISTANCE_COMPARATOR); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/region/RenderRegion.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/region/RenderRegion.java index e41da2387e..154aebf496 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/region/RenderRegion.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/region/RenderRegion.java @@ -87,6 +87,18 @@ public int getOriginZ() { return this.getChunkZ() << 4; } + public int getCenterX() { + return (this.getChunkX() + REGION_WIDTH / 2) << 4; + } + + public int getCenterY() { + return (this.getChunkY() + REGION_HEIGHT / 2) << 4; + } + + public int getCenterZ() { + return (this.getChunkZ() + REGION_LENGTH / 2) << 4; + } + public void delete(CommandList commandList) { for (var storage : this.sectionRenderData.values()) { storage.delete();