Experimental inverse batch option

This commit is contained in:
TheMode 2021-07-03 06:42:06 +02:00
parent 7fcd4039cb
commit de51970965

View File

@ -7,6 +7,7 @@ import net.minestom.server.instance.Instance;
import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.chunk.ChunkUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -32,6 +33,8 @@ public class AbsoluteBlockBatch implements Batch<Runnable> {
protected final CountDownLatch readyLatch;
private final BatchOption options;
private volatile BatchOption inverseOption = new BatchOption();
public AbsoluteBlockBatch() {
this(new BatchOption());
}
@ -118,7 +121,7 @@ public class AbsoluteBlockBatch implements Batch<Runnable> {
protected AbsoluteBlockBatch apply(@NotNull Instance instance, @Nullable Runnable callback, boolean safeCallback) {
if (!this.options.isUnsafeApply()) this.awaitReady();
final AbsoluteBlockBatch inverse = this.options.shouldCalculateInverse() ? new AbsoluteBlockBatch() : null;
final AbsoluteBlockBatch inverse = this.options.shouldCalculateInverse() ? new AbsoluteBlockBatch(inverseOption) : null;
synchronized (chunkBatchesMap) {
AtomicInteger counter = new AtomicInteger();
for (Long2ObjectMap.Entry<ChunkBatch> entry : chunkBatchesMap.long2ObjectEntrySet()) {
@ -156,4 +159,14 @@ public class AbsoluteBlockBatch implements Batch<Runnable> {
return inverse;
}
@ApiStatus.Experimental
public @NotNull BatchOption getInverseOption() {
return inverseOption;
}
@ApiStatus.Experimental
public void setInverseOption(@NotNull BatchOption inverseOption) {
this.inverseOption = inverseOption;
}
}