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) {
|
2021-12-27 12:04:35 +01:00
|
|
|
if (reference instanceof ServerWorld) {
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
task.accept(reference);
|
|
|
|
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, reference.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) {
|
|
|
|
if (reference instanceof ServerWorld) {
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
task.accept(reference);
|
|
|
|
}, reference.getServer());
|
2020-04-15 12:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|