Refactored Generation and class structure
This commit is contained in:
@@ -2,14 +2,15 @@ package eu.mhsl.minenet.minigames.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.batch.Batch;
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class BatchUtil {
|
||||
public static long[] getAffectedChunks(AbsoluteBlockBatch batch) {
|
||||
public static long[] getAffectedChunks(Batch batch) {
|
||||
try {
|
||||
Field field = batch.getClass().getDeclaredField("chunkBatchesMap");
|
||||
field.setAccessible(true);
|
||||
@@ -23,10 +24,33 @@ public class BatchUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadAndApplyBatch(AbsoluteBlockBatch batch, InstanceContainer instance, Runnable onFinish) {
|
||||
public static void loadAndApplyBatch(Batch batch, InstanceContainer instance, Runnable onFinish) {
|
||||
batch.awaitReady();
|
||||
long[] affectedChunks = BatchUtil.getAffectedChunks(batch);
|
||||
ChunkUtils.optionalLoadAll(instance, affectedChunks, null).thenRun(() -> batch.apply(instance, onFinish));
|
||||
}
|
||||
|
||||
public static void loadAndApplyBatchBlocking(Batch batch, InstanceContainer instance) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
batch.awaitReady();
|
||||
long[] affectedChunks = BatchUtil.getAffectedChunks(batch);
|
||||
CompletableFuture<Void> loadChunksTask = ChunkUtils.optionalLoadAll(instance, affectedChunks, null);
|
||||
|
||||
Runnable completerTask = () -> {
|
||||
System.out.println("COMPLETE");
|
||||
future.complete(null);
|
||||
};
|
||||
|
||||
loadChunksTask.thenRun(() -> {
|
||||
System.out.println("BEGIN");
|
||||
batch.apply(instance, completerTask);
|
||||
});
|
||||
|
||||
try {
|
||||
future.get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user