From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Sat, 9 Aug 2025 15:00:20 +0900 Subject: [PATCH] optimize LevelChunk#getBlockStateFinal diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java index e429932a044647f931443c6761d1b39e4eb7665c..6a70665e9b8bc767ba316ada542178634e090afa 100644 --- a/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java @@ -316,12 +316,18 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p public BlockState getBlockStateFinal(final int x, final int y, final int z) { // Copied and modified from below - final int sectionIndex = this.getSectionIndex(y); - if (sectionIndex < 0 || sectionIndex >= this.sections.length - || this.sections[sectionIndex].nonEmptyBlockCount == 0) { - return Blocks.AIR.defaultBlockState(); + // Leaf start - optimize LevelChunk#getBlockStateFinal + final int sectionIndex = (y >> 4) - this.minSection; + if (sectionIndex < 0 || sectionIndex >= this.sections.length) { + return AIR_BLOCKSTATE; + } else { + LevelChunkSection section = this.sections[sectionIndex]; + if (section.nonEmptyBlockCount == 0) { + return AIR_BLOCKSTATE; + } + return section.states.get((y & 15) << 8 | (z & 15) << 4 | x & 15); } - return this.sections[sectionIndex].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15); + // Leaf end - optimize LevelChunk#getBlockStateFinal } @Override