Instance#refreshBlockId optimization

This commit is contained in:
Felix Cravic 2020-04-28 23:43:37 +02:00
parent 93f1b240da
commit 2473a1bbe6
2 changed files with 10 additions and 1 deletions

View File

@ -182,6 +182,15 @@ public class Chunk implements Viewable {
this.customBlocksId[blockIndex] = customId; 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) { protected void refreshBlockValue(int x, int y, int z, short blockId) {
CustomBlock customBlock = getCustomBlock(x, y, z); CustomBlock customBlock = getCustomBlock(x, y, z);
short customBlockId = customBlock == null ? 0 : customBlock.getCustomBlockId(); short customBlockId = customBlock == null ? 0 : customBlock.getCustomBlockId();

View File

@ -97,7 +97,7 @@ public class InstanceContainer extends Instance {
public void refreshBlockId(BlockPosition blockPosition, short blockId) { public void refreshBlockId(BlockPosition blockPosition, short blockId) {
Chunk chunk = getChunkAt(blockPosition.getX(), blockPosition.getZ()); Chunk chunk = getChunkAt(blockPosition.getX(), blockPosition.getZ());
synchronized (chunk) { synchronized (chunk) {
chunk.refreshBlockValue(blockPosition.getX(), blockPosition.getY(), chunk.refreshBlockId(blockPosition.getX(), blockPosition.getY(),
blockPosition.getZ(), blockId); blockPosition.getZ(), blockId);
sendBlockChange(chunk, blockPosition, blockId); sendBlockChange(chunk, blockPosition, blockId);