9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0281-optimize-LevelChunk-getBlockStateFinal.patch

35 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
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 833684b30214566ba27438a1dfb48fbe9f1e6c67..a82049aabcdb64f4632c707ee1d48a885da4301a 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