Class TickAssumption<T>

java.lang.Object
dev.twilite.game.common.TickAssumption<T>

public class TickAssumption<T> extends Object
Stores a predicted value that is only trusted for the current game tick.

This is useful after enqueueing a client action whose backing varp or varbit will not update until a later client cycle or server tick. The facade can assume the requested value immediately, while still falling back to the real client state once the tick changes.


 private static final TickAssumption<Boolean> ENABLED = new TickAssumption<>();

 public static boolean enabled() {
   return ENABLED.get(() -> Game.var(VarpId.SOME_TOGGLE) == 1);
 }

 public static boolean setEnabled(boolean enabled) {
   if (enabled() == enabled) {
     return false;
   }

   if (clickToggle()) {
     ENABLED.set(enabled);
     return true;
   }

   return false;
 }
 
  • Constructor Details

    • TickAssumption

      public TickAssumption()
  • Method Details

    • get

      public T get(Supplier<T> fallback)
      Returns the assumed value for this tick, or the supplied fallback value.
    • set

      public void set(T value)
      Assumes value for the current game tick.