A simple solution to creating tasks and managing them. Schedule a repeating task from anywhere, chain sync and async functions easily, cancel the task from anywhere (even inside or on another thread).
- Add jitpack to repo
repositories {
maven { url 'https://jitpack.io' }
}- Add the dependency
dependencies {
implementation("dev.polv:PolTaskManager:{release or commit hash}") // Currently v1.0
}First instanciate a TaskManager object. Inside, there's a TaskManager::tick() method that will run the tasks.
public class ExampleMod implements ModInitializer {
@Override
public void onInitialize() {
TaskManager taskManager = TaskManager.create();
ServerTickEvents.START_SERVER_TICK.register((xd) -> taskManager.tick());
}
}@Environment(EnvType.CLIENT)
public class ExampleMod implements ClientModInitializer {
@Override
public void onInitializeClient() {
TaskManager taskManager = TaskManager.create();
ClientTickEvents.START_CLIENT_TICK.register((xd) -> taskManager.tick());
}
}It is recommended to execute the tick function from the Main App Thread.