2020-04-15 19:06:45 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
2020-04-15 12:37:14 +02:00
|
|
|
|
2021-12-27 12:04:35 +01:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2020-04-15 12:37:14 +02:00
|
|
|
import java.util.function.Consumer;
|
2020-09-22 15:11:20 +02:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2020-04-15 12:37:14 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class AwaitTickQueue {
|
2020-05-29 20:20:50 +02:00
|
|
|
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
|
2022-09-30 00:23:16 +02:00
|
|
|
if (reference instanceof ServerWorld serverWorld) {
|
2021-12-27 12:04:35 +01:00
|
|
|
CompletableFuture.runAsync(() -> {
|
2022-09-30 00:23:16 +02:00
|
|
|
task.accept(serverWorld);
|
|
|
|
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, serverWorld.getServer()));
|
2020-04-15 12:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 12:04:35 +01:00
|
|
|
public static void scheduleTask(World reference, Consumer<World> task) {
|
2022-09-30 00:23:16 +02:00
|
|
|
if (reference instanceof ServerWorld serverWorld) {
|
2021-12-27 12:04:35 +01:00
|
|
|
CompletableFuture.runAsync(() -> {
|
2022-09-30 00:23:16 +02:00
|
|
|
task.accept(serverWorld);
|
|
|
|
}, serverWorld.getServer());
|
2020-04-15 12:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|