mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 02:57:37 +01:00
Block/chunk batching should be much faster
This commit is contained in:
parent
7daac5e610
commit
90925b4967
@ -10,6 +10,7 @@ import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockManager;
|
||||
import net.minestom.server.instance.block.CustomBlock;
|
||||
import net.minestom.server.instance.block.UpdateConsumer;
|
||||
import net.minestom.server.network.PacketWriterUtils;
|
||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
@ -307,6 +308,14 @@ public class Chunk implements Viewable {
|
||||
setFullDataPacket(buffer);
|
||||
}
|
||||
|
||||
// Write the pakcet in the writer thread pools
|
||||
public void refreshDataPacket(Runnable runnable) {
|
||||
PacketWriterUtils.writeCallbackPacket(getFreshFullDataPacket(), buf -> {
|
||||
setFullDataPacket(buf);
|
||||
runnable.run();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Chunk[" + chunkX + ":" + chunkZ + "]";
|
||||
|
@ -66,13 +66,17 @@ public class BlockBatch implements InstanceBatch {
|
||||
for (BlockData data : dataList) {
|
||||
data.apply(chunk);
|
||||
}
|
||||
chunk.refreshDataPacket();
|
||||
|
||||
chunk.refreshDataPacket(() -> {
|
||||
instance.sendChunkUpdate(chunk);
|
||||
});
|
||||
|
||||
if (isLast) {
|
||||
// data.clear();
|
||||
if (callback != null)
|
||||
callback.run();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -67,8 +67,10 @@ public class ChunkBatch implements InstanceBatch {
|
||||
data.apply(chunk);
|
||||
}
|
||||
|
||||
chunk.refreshDataPacket();
|
||||
chunk.refreshDataPacket(() -> {
|
||||
instance.sendChunkUpdate(chunk);
|
||||
});
|
||||
|
||||
if (callback != null)
|
||||
callback.accept(chunk);
|
||||
}
|
||||
|
@ -17,8 +17,10 @@ public class PlayerPositionAndLookPacket implements ServerPacket {
|
||||
writer.writeDouble(position.getX());
|
||||
writer.writeDouble(position.getY());
|
||||
writer.writeDouble(position.getZ());
|
||||
|
||||
writer.writeFloat(position.getYaw());
|
||||
writer.writeFloat(position.getPitch());
|
||||
|
||||
writer.writeByte(flags);
|
||||
writer.writeVarInt(teleportId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user