create TaskScheduler

This commit is contained in:
dfsek
2021-04-21 15:37:10 -07:00
parent 901677d2c3
commit 5821302eb8
9 changed files with 127 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.task.TaskScheduler;
import com.dfsek.terra.api.util.logging.DebugLogger;
import com.dfsek.terra.api.util.logging.Logger;
import com.dfsek.terra.config.PluginConfig;
@@ -64,4 +65,6 @@ public interface TerraPlugin extends LoaderRegistrar {
default void runPossiblyUnsafeTask(Runnable task) {
task.run();
}
TaskScheduler getScheduler();
}

View File

@@ -0,0 +1,35 @@
package com.dfsek.terra.api.task;
public interface TaskScheduler {
/**
* Run a task synchronously on the next tick.
* Functionally equivalent to {@link #runTask(Runnable, long)}
* @param task Task to run.
*/
default void runTask(Runnable task) {
runTask(task, 0);
}
/**
* Schedule a task asynchronously immediately.
* Functionally equivalent to {@link #runTaskAsynchronously(Runnable)} (Runnable, long)}
* @param task Task to run.
*/
default void runTaskAsynchronously(Runnable task) {
runTaskAsynchronously(task, 0);
}
/**
* Run a task asynchronously after a number of ticks.
* @param task Task to run.
* @param ticks Delay before running the task, in ticks.
*/
void runTaskAsynchronously(Runnable task, long ticks);
/**
* Run a task synchronously after a number of ticks.
* @param task Task to run.
* @param ticks Delay before running the task, in ticks.
*/
void runTask(Runnable task, long ticks);
}

View File

@@ -18,6 +18,7 @@ import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.task.TaskScheduler;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.util.logging.DebugLogger;
import com.dfsek.terra.api.util.logging.JavaLogger;
@@ -137,6 +138,11 @@ public class DistributionTest {
return null;
}
@Override
public TaskScheduler getScheduler() {
return null;
}
@Override
public void register(TypeRegistry registry) {