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;
|
|
|
|
|
2023-01-28 20:22:20 +01:00
|
|
|
public interface AwaitTickQueue {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 20:22:20 +01:00
|
|
|
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);
|
2023-01-28 20:22:20 +01:00
|
|
|
}, CompletableFuture.delayedExecutor(1, TimeUnit.MILLISECONDS, serverWorld.getServer()));
|
2020-04-15 12:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|