Interface ISpellVar<T>

Type Parameters:
T - the type of value this spell variable holds
All Known Subinterfaces:
IStoredSpellVar<T>
All Known Implementing Classes:
ISpellVar.SpellVar, IStoredSpellVar.StoredSpellVar

public interface ISpellVar<T>
Interface for spell variables that can be stored and synchronized between client and server.

Spell variables are used to store data associated with spells or players, with support for persistence across dimension changes and respawns, as well as network synchronization.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Default implementation of ISpellVar that provides basic functionality.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    canPurge(net.minecraft.world.entity.player.Player player, T value)
    Determines whether this spell variable can be purged for the given player.
    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.
    void
    write(net.minecraft.network.FriendlyByteBuf buf, T value)
    Writes the value to a network buffer for synchronization.
  • Method Details

    • update

      T update(net.minecraft.world.entity.player.Player player, T value)
      Updates the value of this spell variable for the given player.

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

      Parameters:
      player - the player whose spell variable is being updated
      value - the current value
      Returns:
      the updated value
    • isPersistent

      boolean isPersistent(boolean respawn)
      Determines whether this spell variable should persist.
      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

      boolean isSynced()
      Checks whether this spell variable should be synchronized between client and server.
      Returns:
      true if the variable should be synced, false otherwise
    • write

      void write(net.minecraft.network.FriendlyByteBuf buf, T value)
      Writes the value to a network buffer for synchronization.
      Parameters:
      buf - the buffer to write to
      value - the value to write
    • read

      T read(net.minecraft.network.FriendlyByteBuf buf)
      Reads the value from a network buffer.
      Parameters:
      buf - the buffer to read from
      Returns:
      the value read from the buffer, or null if no value is present
    • canPurge

      default boolean canPurge(net.minecraft.world.entity.player.Player player, T value)
      Determines whether this spell variable can be purged for the given player.

      By default, spell variables cannot be purged.

      Parameters:
      player - the player whose spell variable is being checked
      value - the current value
      Returns:
      true if the variable can be purged, false otherwise