Class IStoredSpellVar.StoredSpellVar<T,E extends net.minecraft.nbt.Tag>

java.lang.Object
com.binaris.wizardry.api.content.data.IStoredSpellVar.StoredSpellVar<T,E>
Type Parameters:
T - the type of value this spell variable holds
E - the type of NBT tag used for serialization
All Implemented Interfaces:
ISpellVar<T>, IStoredSpellVar<T>
Enclosing interface:
IStoredSpellVar<T>

public static class IStoredSpellVar.StoredSpellVar<T,E extends net.minecraft.nbt.Tag> extends Object implements IStoredSpellVar<T>
Default implementation of IStoredSpellVar with NBT serialization support.

This implementation uses customizable serializer and deserializer functions to convert between the value type and NBT tags. It supports both NBT and network synchronization.

  • Constructor Details

    • StoredSpellVar

      public StoredSpellVar(String key, Function<T,E> serializer, Function<E,T> deserializer, Persistence persistence)
      Creates a new stored spell variable with the specified serialization functions.
      Parameters:
      key - the NBT key used to store this variable
      serializer - function to convert the value to an NBT tag
      deserializer - function to convert an NBT tag back to the value
      persistence - the persistence settings for this variable
  • Method Details

    • ofByte

      public static IStoredSpellVar.StoredSpellVar<Byte,net.minecraft.nbt.ByteTag> ofByte(String key, Persistence persistence)
      Creates a stored spell variable for byte values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for byte values
    • ofBoolean

      public static IStoredSpellVar.StoredSpellVar<Boolean,net.minecraft.nbt.ByteTag> ofBoolean(String key, Persistence persistence)
      Creates a stored spell variable for boolean values.

      Booleans are stored as bytes (1 for true, 0 for false).

      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for boolean values
    • ofInt

      public static IStoredSpellVar.StoredSpellVar<Integer,net.minecraft.nbt.IntTag> ofInt(String key, Persistence persistence)
      Creates a stored spell variable for integer values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for integer values
    • ofIntArray

      public static IStoredSpellVar.StoredSpellVar<int[],net.minecraft.nbt.IntArrayTag> ofIntArray(String key, Persistence persistence)
      Creates a stored spell variable for integer array values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for integer array values
    • ofFloat

      public static IStoredSpellVar.StoredSpellVar<Float,net.minecraft.nbt.FloatTag> ofFloat(String key, Persistence persistence)
      Creates a stored spell variable for float values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for float values
    • ofDouble

      public static IStoredSpellVar.StoredSpellVar<Double,net.minecraft.nbt.DoubleTag> ofDouble(String key, Persistence persistence)
      Creates a stored spell variable for double values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for double values
    • ofShort

      public static IStoredSpellVar.StoredSpellVar<Short,net.minecraft.nbt.ShortTag> ofShort(String key, Persistence persistence)
      Creates a stored spell variable for short values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for short values
    • ofLong

      public static IStoredSpellVar.StoredSpellVar<Long,net.minecraft.nbt.LongTag> ofLong(String key, Persistence persistence)
      Creates a stored spell variable for long values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for long values
    • ofString

      public static IStoredSpellVar.StoredSpellVar<String,net.minecraft.nbt.StringTag> ofString(String key, Persistence persistence)
      Creates a stored spell variable for string values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for string values
    • ofBlockPos

      public static IStoredSpellVar.StoredSpellVar<net.minecraft.core.BlockPos,net.minecraft.nbt.CompoundTag> ofBlockPos(String key, Persistence persistence)
      Creates a stored spell variable for BlockPos values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for BlockPos values
    • ofUUID

      public static IStoredSpellVar.StoredSpellVar<UUID,net.minecraft.nbt.IntArrayTag> ofUUID(String key, Persistence persistence)
      Creates a stored spell variable for UUID values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for UUID values
    • ofNBT

      public static IStoredSpellVar.StoredSpellVar<net.minecraft.nbt.CompoundTag,net.minecraft.nbt.CompoundTag> ofNBT(String key, Persistence persistence)
      Creates a stored spell variable for raw NBT compound tag values.
      Parameters:
      key - the NBT key
      persistence - the persistence settings
      Returns:
      a new stored spell variable for NBT compound tag values
    • withTicker

      public IStoredSpellVar.StoredSpellVar<T,E> 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
    • setSynced

      public IStoredSpellVar.StoredSpellVar<T,E> setSynced()
      Enables network synchronization for this spell variable. When synced, the variable will be automatically sent to clients when it changes.
      Returns:
      this spell variable for method chaining
    • write

      public void write(net.minecraft.nbt.CompoundTag nbt, T value)
      Description copied from interface: IStoredSpellVar
      Writes the value to an NBT compound tag for persistent storage.
      Specified by:
      write in interface IStoredSpellVar<T>
      Parameters:
      nbt - the NBT compound tag to write to
      value - the value to write
    • read

      public T read(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: IStoredSpellVar
      Reads the value from an NBT compound tag.
      Specified by:
      read in interface IStoredSpellVar<T>
      Parameters:
      nbt - the NBT compound tag to read from
      Returns:
      the value read from the tag, or null if no value is present
    • 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