This commit is contained in:
TheMode 2021-06-18 14:43:14 +02:00
parent e25f521253
commit 7032645c63

View File

@ -86,8 +86,7 @@ public class DynamicChunk extends Chunk {
this.nbtMap.remove(index); this.nbtMap.remove(index);
} }
// Tickable // Tickable
final boolean tickable = handler != null && handler.isTickable(); if (handler != null && handler.isTickable()) {
if (tickable) {
this.tickableMap.put(index, handler); this.tickableMap.put(index, handler);
} else { } else {
this.tickableMap.remove(index); this.tickableMap.remove(index);
@ -106,15 +105,19 @@ public class DynamicChunk extends Chunk {
@Override @Override
public void tick(long time) { public void tick(long time) {
this.tickableMap.forEach((index, handler) -> { if (tickableMap.isEmpty())
return;
for (var entry : tickableMap.int2ObjectEntrySet()) {
final int index = entry.getIntKey();
final byte x = ChunkUtils.blockIndexToChunkPositionX(index); final byte x = ChunkUtils.blockIndexToChunkPositionX(index);
final short y = ChunkUtils.blockIndexToChunkPositionY(index); final short y = ChunkUtils.blockIndexToChunkPositionY(index);
final byte z = ChunkUtils.blockIndexToChunkPositionZ(index); final byte z = ChunkUtils.blockIndexToChunkPositionZ(index);
final BlockPosition blockPosition = new BlockPosition(x, y, z); final BlockPosition blockPosition = new BlockPosition(x, y, z);
final Block block = getBlock(blockPosition); final Block block = getBlock(blockPosition);
handler.tick(BlockHandler.Tick.from(block, instance, blockPosition)); entry.getValue().tick(BlockHandler.Tick.from(block, instance, blockPosition));
}); }
} }
@Override @Override