Optimize block getter

This commit is contained in:
TheMode 2021-06-16 01:01:27 +02:00
parent 235100e87b
commit 0bdc84558f

View File

@ -110,17 +110,21 @@ public class DynamicChunk extends Chunk {
@Override @Override
public @NotNull Block getBlock(int x, int y, int z) { public @NotNull Block getBlock(int x, int y, int z) {
final Section section = retrieveSection(y); final Section section = retrieveSection(y);
final int index = ChunkUtils.getBlockIndex(x, y, z);
final short blockStateId = section.getBlockAt(x, y, z); final short blockStateId = section.getBlockAt(x, y, z);
BlockHandler handler = handlerMap.get(index);
NBTCompound nbt = nbtMap.get(index);
Block block = Block.fromStateId(blockStateId); Block block = Block.fromStateId(blockStateId);
if (block == null) { if (block == null) {
return Block.AIR; return Block.AIR;
} }
return block final int index = ChunkUtils.getBlockIndex(x, y, z);
.withHandler(handler) final BlockHandler handler = handlerMap.get(index);
.withNbt(nbt); final NBTCompound nbt = nbtMap.get(index);
if (handler != null) {
block = block.withHandler(handler);
}
if (nbt != null) {
block = block.withNbt(nbt);
}
return block;
} }
@NotNull @NotNull