mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Improve tickable block loop
This commit is contained in:
parent
2339fe1c07
commit
42a6654993
@ -2,6 +2,7 @@ package net.minestom.server.instance;
|
|||||||
|
|
||||||
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@ -10,8 +11,8 @@ import net.minestom.server.instance.block.Block;
|
|||||||
import net.minestom.server.instance.block.BlockHandler;
|
import net.minestom.server.instance.block.BlockHandler;
|
||||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
|
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||||
import net.minestom.server.utils.ArrayUtils;
|
import net.minestom.server.utils.ArrayUtils;
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||||
@ -88,20 +89,18 @@ public class DynamicChunk extends Chunk {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(long time) {
|
public void tick(long time) {
|
||||||
if (tickableMap.isEmpty())
|
if (tickableMap.isEmpty()) return;
|
||||||
return;
|
Int2ObjectMaps.fastForEach(tickableMap, entry -> {
|
||||||
for (var entry : tickableMap.int2ObjectEntrySet()) {
|
|
||||||
final int index = entry.getIntKey();
|
final int index = entry.getIntKey();
|
||||||
final Block block = entry.getValue();
|
final Block block = entry.getValue();
|
||||||
final var handler = block.handler();
|
final BlockHandler handler = block.handler();
|
||||||
if (handler != null) {
|
if (handler == null) return;
|
||||||
final int x = ChunkUtils.blockIndexToChunkPositionX(index);
|
final int x = ChunkUtils.blockIndexToChunkPositionX(index);
|
||||||
final int y = ChunkUtils.blockIndexToChunkPositionY(index);
|
final int y = ChunkUtils.blockIndexToChunkPositionY(index);
|
||||||
final int z = ChunkUtils.blockIndexToChunkPositionZ(index);
|
final int z = ChunkUtils.blockIndexToChunkPositionZ(index);
|
||||||
final Vec blockPosition = new Vec(x, y, z);
|
final Vec blockPosition = new Vec(x, y, z);
|
||||||
handler.tick(new BlockHandler.Tick(block, instance, blockPosition));
|
handler.tick(new BlockHandler.Tick(block, instance, blockPosition));
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user