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 fullChunk = false;
private boolean calculateInverse = false; private boolean calculateInverse = false;
private boolean unsafeApply = false; private boolean unsafeApply = false;
private boolean sendUpdate = true;
public BatchOption() { public BatchOption() {
} }
@ -62,6 +63,10 @@ public class BatchOption {
return this.unsafeApply; return this.unsafeApply;
} }
public boolean shouldSendUpdate() {
return sendUpdate;
}
/** /**
* @param fullChunk true to make this batch composes the whole chunk * @param fullChunk true to make this batch composes the whole chunk
* @return 'this' for chaining * @return 'this' for chaining
@ -98,4 +103,10 @@ public class BatchOption {
this.unsafeApply = unsafeApply; this.unsafeApply = unsafeApply;
return this; 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) { private void updateChunk(@NotNull Instance instance, Chunk chunk, IntSet updatedSections, @Nullable ChunkCallback callback, boolean safeCallback) {
// Refresh chunk for viewers // Refresh chunk for viewers
ChunkDataPacket chunkDataPacket = chunk.createChunkPacket(); if (options.shouldSendUpdate()) {
// TODO update all sections from `updatedSections` ChunkDataPacket chunkDataPacket = chunk.createChunkPacket();
PacketUtils.sendGroupedPacket(chunk.getViewers(), chunkDataPacket); // TODO update all sections from `updatedSections`
PacketUtils.sendGroupedPacket(chunk.getViewers(), chunkDataPacket);
}
if (instance instanceof InstanceContainer) { if (instance instanceof InstanceContainer) {
// FIXME: put method in Instance instead // FIXME: put method in Instance instead