Class ClientScheduler

java.lang.Object
dev.bouncingelf10.timelesslib.api.scheduler.ClientScheduler

public final class ClientScheduler extends Object
General-purpose task scheduler running against the local Minecraft client context - one-off delays, repeating tasks, and step sequences. For counting down to zero with rich tick/finish/threshold events, see ClientCountdownManager instead.
Obtain the shared instance through TimelessLibClient.scheduler() - this class cannot be constructed by other mods.
  • Constructor Details

    • ClientScheduler

      public ClientScheduler(InternalAccess access, Supplier<net.minecraft.client.Minecraft> contextProvider)
    • ClientScheduler

      public ClientScheduler(InternalAccess access, Supplier<net.minecraft.client.Minecraft> contextProvider, dev.bouncingelf10.timelesslib.api.scheduler.Scheduler.Config config)
  • Method Details

    • after

      public TaskHandle after(Duration delay, Consumer<net.minecraft.client.Minecraft> task)
      Schedules a task to run after the specified delay.
      Parameters:
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
    • after

      public TaskHandle after(Duration delay, Runnable task)
      Schedules a task to run after the specified delay.
      Parameters:
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
    • after

      public TaskHandle after(net.minecraft.resources.ResourceLocation id, Duration delay, Consumer<net.minecraft.client.Minecraft> task)
      Schedules a task to run after the specified delay.
      Parameters:
      id - Unique ID for the task
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
      Throws:
      IllegalArgumentException - if a task with the specified ID already exists
    • after

      public TaskHandle after(net.minecraft.resources.ResourceLocation id, Duration delay, Runnable task)
      Schedules a task to run after the specified delay.
      Parameters:
      id - Unique ID for the task
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
      Throws:
      IllegalArgumentException - if a task with the specified ID already exists
    • every

      public TaskHandle every(Duration period, Consumer<net.minecraft.client.Minecraft> task)
      Schedules a repeating task to run at the specified interval.
      Parameters:
      period - Interval between runs
      task - Task to run
      Returns:
      TaskHandle
    • every

      public TaskHandle every(Duration period, Runnable task)
      Schedules a repeating task to run at the specified interval.
      Parameters:
      period - Interval between runs
      task - Task to run
      Returns:
      TaskHandle
    • everyFixedRate

      public TaskHandle everyFixedRate(Duration period, Consumer<net.minecraft.client.Minecraft> task)
      Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
      E.g. every(Duration, Consumer) will run the interval after the task has finished executing, whereas this method will run the interval immediately after the task starts executing.
      Parameters:
      period - Interval between runs
      task - Task to run
      Returns:
      TaskHandle
    • everyFixedRate

      public TaskHandle everyFixedRate(Duration period, Runnable task)
      Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
      E.g. every(Duration, Runnable) will run the interval after the task has finished executing, whereas this method will run the interval immediately after the task starts executing.
      Parameters:
      period - Interval between runs
      task - Task to run
      Returns:
      TaskHandle
    • afterAsync

      public CompletableFuture<Void> afterAsync(Duration delay, Consumer<net.minecraft.client.Minecraft> task)
      Schedules a task to run after the specified delay, returning a CompletableFuture that completes when the task has finished executing.
      Parameters:
      delay - Delay before running the task
      task - Task to run
      Returns:
      CompletableFuture
    • sequence

      public Sequence<net.minecraft.client.Minecraft> sequence()
      Starts building a sequence of delayed steps that run one after another - "wait, then do this, then wait, then do that".
      Returns:
      Sequence builder
    • get

      public Optional<TaskHandle> get(net.minecraft.resources.ResourceLocation id)
      Looks up an active task (or sequence) by its ID.
      Parameters:
      id - Task ID
      Returns:
      TaskHandle or empty if no active task has that ID
    • activeTaskCount

      public int activeTaskCount()
      Returns:
      the number of currently active tasks and sequences.
    • cancelAll

      public boolean cancelAll()
      Cancels every currently active task and sequence.
      Returns:
      true if at least one task was cancelled
    • shutdown

      public void shutdown()
      If you're getting the scheduler through TimelessLib.scheduler() or the client counterpart you should NOT call this method.
    • shutdownGracefully

      public void shutdownGracefully(long timeout, TimeUnit unit) throws InterruptedException
      If you're getting the scheduler through TimelessLib.scheduler() or the client counterpart you should NOT call this method.
      Throws:
      InterruptedException
    • isShutdown

      public boolean isShutdown()
    • isTerminated

      public boolean isTerminated()