Reduce needed map checks for InstanceContainer#setCustomBlock

This commit is contained in:
Felix Cravic 2020-04-28 15:41:29 +02:00
parent 8050708ecf
commit 03f4e19db3
2 changed files with 10 additions and 9 deletions

View File

@ -76,10 +76,10 @@ public class Chunk implements Viewable {
if (customBlock == null)
throw new IllegalArgumentException("The custom block " + customBlockId + " does not exist or isn't registered");
setCustomBlock(x, y, z, customBlock, data);
UNSAFE_setCustomBlock(x, y, z, customBlock, data);
}
private void setCustomBlock(int x, int y, int z, CustomBlock customBlock, Data data) {
protected void UNSAFE_setCustomBlock(int x, int y, int z, CustomBlock customBlock, Data data) {
UpdateConsumer updateConsumer = customBlock.hasUpdate() ? customBlock::update : null;
setBlock(x, y, z, customBlock.getBlockId(), customBlock.getCustomBlockId(), data, updateConsumer);
}

View File

@ -47,20 +47,21 @@ public class InstanceContainer extends Instance {
@Override
public void setBlock(int x, int y, int z, short blockId, Data data) {
setBlock(x, y, z, blockId, (short) 0, data);
setBlock(x, y, z, blockId, null, data);
}
@Override
public void setCustomBlock(int x, int y, int z, short customBlockId, Data data) {
short blockId = BLOCK_MANAGER.getCustomBlock(customBlockId).getBlockId();
setBlock(x, y, z, blockId, customBlockId, data);
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
setBlock(x, y, z, (short) 0, customBlock, data);
}
private synchronized void setBlock(int x, int y, int z, short blockId, short customBlockId, Data data) {
private synchronized void setBlock(int x, int y, int z, short blockId, CustomBlock customBlock, Data data) {
Chunk chunk = getChunkAt(x, z);
synchronized (chunk) {
boolean isCustomBlock = customBlockId != 0;
boolean isCustomBlock = customBlock != null;
blockId = isCustomBlock ? customBlock.getBlockId() : blockId;
int index = SerializerUtils.coordToChunkIndex(x, y, z);
@ -74,8 +75,8 @@ public class InstanceContainer extends Instance {
// Set the block
if (isCustomBlock) {
data = BLOCK_MANAGER.getCustomBlock(customBlockId).createData(blockPosition, data);
chunk.UNSAFE_setCustomBlock(x, y, z, customBlockId, data);
data = customBlock.createData(blockPosition, data);
chunk.UNSAFE_setCustomBlock(x, y, z, customBlock, data);
} else {
chunk.UNSAFE_setBlock(x, y, z, blockId, data);
}