Class ISpellVar.SpellVar<T>

java.lang.Object
com.binaris.wizardry.api.content.data.ISpellVar.SpellVar<T>
Type Parameters:
T - the type of value this spell variable holds
All Implemented Interfaces:
ISpellVar<T>
Enclosing interface:
ISpellVar<T>

public static class ISpellVar.SpellVar<T> extends Object implements ISpellVar<T>
Default implementation of ISpellVar that provides basic functionality.

This implementation stores non-persistent, non-synced values with optional tick updates.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.binaris.wizardry.api.content.data.ISpellVar

    ISpellVar.SpellVar<T>
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpellVar(Persistence persistence)
    Creates a new spell variable with the specified persistence settings.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isPersistent(boolean respawn)
    Determines whether this spell variable should persist.
    boolean
    Checks whether this spell variable should be synchronized between client and server.
    read(net.minecraft.network.FriendlyByteBuf buf)
    Reads the value from a network buffer.
    update(net.minecraft.world.entity.player.Player player, T value)
    Updates the value of this spell variable for the given player.
    withTicker(BiFunction<net.minecraft.world.entity.player.Player,T,T> ticker)
    Sets a custom ticker function for this spell variable.
    void
    write(net.minecraft.network.FriendlyByteBuf buf, T value)
    Writes the value to a network buffer for synchronization.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.binaris.wizardry.api.content.data.ISpellVar

    canPurge
  • Constructor Details

    • SpellVar

      public SpellVar(Persistence persistence)
      Creates a new spell variable with the specified persistence settings.
      Parameters:
      persistence - the persistence settings for this variable
  • Method Details

    • withTicker

      public ISpellVar.SpellVar<T> withTicker(BiFunction<net.minecraft.world.entity.player.Player,T,T> ticker)
      Sets a custom ticker function for this spell variable.

      The ticker function is called during update(Player, Object) to compute the new value.

      Parameters:
      ticker - a function that takes a player and current value, and returns the updated value
      Returns:
      this spell variable for method chaining
    • update

      public T update(net.minecraft.world.entity.player.Player player, T value)
      Description copied from interface: ISpellVar
      Updates the value of this spell variable for the given player.

      This method is typically called each tick to update time-dependent values.

      Specified by:
      update in interface ISpellVar<T>
      Parameters:
      player - the player whose spell variable is being updated
      value - the current value
      Returns:
      the updated value
    • isPersistent

      public boolean isPersistent(boolean respawn)
      Description copied from interface: ISpellVar
      Determines whether this spell variable should persist.
      Specified by:
      isPersistent in interface ISpellVar<T>
      Parameters:
      respawn - if true, checks persistence across player respawns; if false, checks persistence across dimension changes
      Returns:
      true if the variable should persist, false otherwise
    • isSynced

      public boolean isSynced()
      Description copied from interface: ISpellVar
      Checks whether this spell variable should be synchronized between client and server.
      Specified by:
      isSynced in interface ISpellVar<T>
      Returns:
      true if the variable should be synced, false otherwise
    • write

      public void write(net.minecraft.network.FriendlyByteBuf buf, T value)
      Description copied from interface: ISpellVar
      Writes the value to a network buffer for synchronization.
      Specified by:
      write in interface ISpellVar<T>
      Parameters:
      buf - the buffer to write to
      value - the value to write
    • read

      public T read(net.minecraft.network.FriendlyByteBuf buf)
      Description copied from interface: ISpellVar
      Reads the value from a network buffer.
      Specified by:
      read in interface ISpellVar<T>
      Parameters:
      buf - the buffer to read from
      Returns:
      the value read from the buffer, or null if no value is present