From 2473a1bbe62f3325b958712bd245de85c5d14949 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Tue, 28 Apr 2020 23:43:37 +0200 Subject: [PATCH] Instance#refreshBlockId optimization --- src/main/java/net/minestom/server/instance/Chunk.java | 9 +++++++++ .../net/minestom/server/instance/InstanceContainer.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/instance/Chunk.java b/src/main/java/net/minestom/server/instance/Chunk.java index 1597ee613..83b8d8dbf 100644 --- a/src/main/java/net/minestom/server/instance/Chunk.java +++ b/src/main/java/net/minestom/server/instance/Chunk.java @@ -182,6 +182,15 @@ public class Chunk implements Viewable { this.customBlocksId[blockIndex] = customId; } + protected void refreshBlockId(int x, int y, int z, short blockId) { + int blockIndex = getBlockIndex(x, y, z); + if (blockIndex < 0 || blockIndex >= blocksId.length) { + return; + } + + this.blocksId[blockIndex] = blockId; + } + protected void refreshBlockValue(int x, int y, int z, short blockId) { CustomBlock customBlock = getCustomBlock(x, y, z); short customBlockId = customBlock == null ? 0 : customBlock.getCustomBlockId(); diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index fcc5c747f..7fbfb1eee 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -97,7 +97,7 @@ public class InstanceContainer extends Instance { public void refreshBlockId(BlockPosition blockPosition, short blockId) { Chunk chunk = getChunkAt(blockPosition.getX(), blockPosition.getZ()); synchronized (chunk) { - chunk.refreshBlockValue(blockPosition.getX(), blockPosition.getY(), + chunk.refreshBlockId(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockId); sendBlockChange(chunk, blockPosition, blockId);