From 7fcd4039cb0b9cdb2931ef402d1b866867f3e67f Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 3 Jul 2021 05:45:55 +0200 Subject: [PATCH] Add batch option to do not send chunk packet --- .../minestom/server/instance/batch/BatchOption.java | 11 +++++++++++ .../minestom/server/instance/batch/ChunkBatch.java | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/batch/BatchOption.java b/src/main/java/net/minestom/server/instance/batch/BatchOption.java index 833ec766e..1e148713f 100644 --- a/src/main/java/net/minestom/server/instance/batch/BatchOption.java +++ b/src/main/java/net/minestom/server/instance/batch/BatchOption.java @@ -12,6 +12,7 @@ public class BatchOption { private boolean fullChunk = false; private boolean calculateInverse = false; private boolean unsafeApply = false; + private boolean sendUpdate = true; public BatchOption() { } @@ -62,6 +63,10 @@ public class BatchOption { return this.unsafeApply; } + public boolean shouldSendUpdate() { + return sendUpdate; + } + /** * @param fullChunk true to make this batch composes the whole chunk * @return 'this' for chaining @@ -98,4 +103,10 @@ public class BatchOption { this.unsafeApply = unsafeApply; return this; } + + @Contract("_ -> this") + public BatchOption setSendUpdate(boolean sendUpdate) { + this.sendUpdate = sendUpdate; + return this; + } } diff --git a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java index 42254d6e6..ce50369e7 100644 --- a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java +++ b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java @@ -224,9 +224,11 @@ public class ChunkBatch implements Batch { */ private void updateChunk(@NotNull Instance instance, Chunk chunk, IntSet updatedSections, @Nullable ChunkCallback callback, boolean safeCallback) { // Refresh chunk for viewers - ChunkDataPacket chunkDataPacket = chunk.createChunkPacket(); - // TODO update all sections from `updatedSections` - PacketUtils.sendGroupedPacket(chunk.getViewers(), chunkDataPacket); + if (options.shouldSendUpdate()) { + ChunkDataPacket chunkDataPacket = chunk.createChunkPacket(); + // TODO update all sections from `updatedSections` + PacketUtils.sendGroupedPacket(chunk.getViewers(), chunkDataPacket); + } if (instance instanceof InstanceContainer) { // FIXME: put method in Instance instead