Add batch option to do not send chunk packet

This commit is contained in:
TheMode 2021-07-03 05:45:55 +02:00
parent 10aeb32b45
commit 7fcd4039cb
2 changed files with 16 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -224,9 +224,11 @@ public class ChunkBatch implements Batch<ChunkCallback> {
*/
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