From 8535653fd9e3aa4d15671b7d9227492ec74f055c Mon Sep 17 00:00:00 2001 From: Luna0x01 Date: Mon, 30 Dec 2024 11:32:08 +0530 Subject: [PATCH] fix section y --- .../sodium/client/render/chunk/RenderSectionManager.java | 6 ++++-- .../client/world/cloned/ClonedChunkSectionCache.java | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java index feec5d39..c27c732d 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java @@ -211,6 +211,8 @@ public void onSectionRemoved(int x, int y, int z) { long sectionPos = SectionPos.asLong(x, y, z); RenderSection section = this.sectionByPosition.remove(sectionPos); + + if (section == null) { return; } @@ -688,13 +690,13 @@ public boolean isSectionBuilt(int x, int y, int z) { } public void onChunkAdded(int x, int z) { - for (int y = 1; y < 16; y++) { + for (int y = 0; y < 16; y++) { this.onSectionAdded(x, y, z); } } public void onChunkRemoved(int x, int z) { - for (int y = 1; y < 16; y++) { + for (int y = 0; y < 16; y++) { this.onSectionRemoved(x, y, z); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/cloned/ClonedChunkSectionCache.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/cloned/ClonedChunkSectionCache.java index 09ff4bcc..8ca80274 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/cloned/ClonedChunkSectionCache.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/cloned/ClonedChunkSectionCache.java @@ -61,13 +61,17 @@ private ClonedChunkSection clone(int x, int y, int z) { @Nullable ChunkSection section = null; - if (SectionPos.sectionToBlockCoord(y) < 256) { - section = chunk.getBlockStorage()[y]; + if (!withinBuildHeight(SectionPos.sectionToBlockCoord(y))) { + section = chunk.getBlockStorage()[SectionPos.blockToSectionCoord(SectionPos.sectionToBlockCoord(y))]; } return new ClonedChunkSection(this.level, chunk, section, SectionPos.of(x, y, z)); } + private static boolean withinBuildHeight(int y) { + return y < 0 || y >= 256; + } + public void invalidate(int x, int y, int z) { this.positionToEntry.remove(SectionPos.asLong(x, y, z)); }