Unicopia/src/main/java/com/minelittlepony/unicopia/AwaitTickQueue.java

26 lines
900 B
Java
Raw Normal View History

2020-04-15 19:06:45 +02:00
package com.minelittlepony.unicopia;
2020-04-15 12:37:14 +02:00
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
2020-04-15 12:37:14 +02:00
import java.util.function.Consumer;
import net.minecraft.server.world.ServerWorld;
2020-04-15 12:37:14 +02:00
import net.minecraft.world.World;
public class AwaitTickQueue {
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
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
}
}
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
}
}
}