From 0bdc84558f6c453bfb7bc64bd93fc9f9a3aed3aa Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 16 Jun 2021 01:01:27 +0200 Subject: [PATCH] Optimize block getter --- .../minestom/server/instance/DynamicChunk.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/DynamicChunk.java b/src/main/java/net/minestom/server/instance/DynamicChunk.java index 38dfb21e0..0a7b5beb8 100644 --- a/src/main/java/net/minestom/server/instance/DynamicChunk.java +++ b/src/main/java/net/minestom/server/instance/DynamicChunk.java @@ -110,17 +110,21 @@ public class DynamicChunk extends Chunk { @Override public @NotNull Block getBlock(int x, int y, int z) { final Section section = retrieveSection(y); - final int index = ChunkUtils.getBlockIndex(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); if (block == null) { return Block.AIR; } - return block - .withHandler(handler) - .withNbt(nbt); + final int index = ChunkUtils.getBlockIndex(x, y, z); + final BlockHandler handler = handlerMap.get(index); + final NBTCompound nbt = nbtMap.get(index); + if (handler != null) { + block = block.withHandler(handler); + } + if (nbt != null) { + block = block.withNbt(nbt); + } + return block; } @NotNull