From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 6 Jul 2025 02:47:58 +0300 Subject: [PATCH] Optimize block state lookup diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java index d11373d6a88f7b3baaf0e04d4f6e0d3837e2ba3b..6d9274f0da9507d0152611d6b7785e0524dedb2d 100644 --- a/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java @@ -270,11 +270,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) { + // DivineMC start - Optimize block state lookup + if (sectionIndex < 0 || sectionIndex >= this.sections.length) { return Blocks.AIR.defaultBlockState(); } - return this.sections[sectionIndex].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15); + + final LevelChunkSection section = this.sections[sectionIndex]; + if (section.nonEmptyBlockCount == 0) { + return Blocks.AIR.defaultBlockState(); + } + + return section.states.get((y & 15) << 8 | (z & 15) << 4 | (x & 15)); + // DivineMC end - Optimize block state lookup } @Override