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 holdsE- 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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.binaris.wizardry.api.content.data.ISpellVar
ISpellVar.SpellVar<T>Nested classes/interfaces inherited from interface com.binaris.wizardry.api.content.data.IStoredSpellVar
IStoredSpellVar.StoredSpellVar<T,E extends net.minecraft.nbt.Tag> -
Constructor Summary
ConstructorsConstructorDescriptionStoredSpellVar(String key, Function<T, E> serializer, Function<E, T> deserializer, Persistence persistence) Creates a new stored spell variable with the specified serialization functions. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisPersistent(boolean respawn) Determines whether this spell variable should persist.booleanisSynced()Checks whether this spell variable should be synchronized between client and server.static IStoredSpellVar.StoredSpellVar<net.minecraft.core.BlockPos,net.minecraft.nbt.CompoundTag> ofBlockPos(String key, Persistence persistence) Creates a stored spell variable for BlockPos values.static IStoredSpellVar.StoredSpellVar<Boolean,net.minecraft.nbt.ByteTag> ofBoolean(String key, Persistence persistence) Creates a stored spell variable for boolean values.static IStoredSpellVar.StoredSpellVar<Byte,net.minecraft.nbt.ByteTag> ofByte(String key, Persistence persistence) Creates a stored spell variable for byte values.static IStoredSpellVar.StoredSpellVar<Double,net.minecraft.nbt.DoubleTag> ofDouble(String key, Persistence persistence) Creates a stored spell variable for double values.static IStoredSpellVar.StoredSpellVar<Float,net.minecraft.nbt.FloatTag> ofFloat(String key, Persistence persistence) Creates a stored spell variable for float values.static IStoredSpellVar.StoredSpellVar<Integer,net.minecraft.nbt.IntTag> ofInt(String key, Persistence persistence) Creates a stored spell variable for integer values.static IStoredSpellVar.StoredSpellVar<int[],net.minecraft.nbt.IntArrayTag> ofIntArray(String key, Persistence persistence) Creates a stored spell variable for integer array values.static IStoredSpellVar.StoredSpellVar<Long,net.minecraft.nbt.LongTag> ofLong(String key, Persistence persistence) Creates a stored spell variable for long values.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.static IStoredSpellVar.StoredSpellVar<Short,net.minecraft.nbt.ShortTag> ofShort(String key, Persistence persistence) Creates a stored spell variable for short values.static IStoredSpellVar.StoredSpellVar<String,net.minecraft.nbt.StringTag> ofString(String key, Persistence persistence) Creates a stored spell variable for string values.static IStoredSpellVar.StoredSpellVar<UUID,net.minecraft.nbt.IntArrayTag> ofUUID(String key, Persistence persistence) Creates a stored spell variable for UUID values.read(net.minecraft.nbt.CompoundTag nbt) Reads the value from an NBT compound tag.read(net.minecraft.network.FriendlyByteBuf buf) Reads the value from a network buffer.Enables network synchronization for this spell variable.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.voidWrites the value to an NBT compound tag for persistent storage.voidWrites the value to a network buffer for 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 variableserializer- function to convert the value to an NBT tagdeserializer- function to convert an NBT tag back to the valuepersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 keypersistence- 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 duringupdate(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
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
Description copied from interface:IStoredSpellVarWrites the value to an NBT compound tag for persistent storage.- Specified by:
writein interfaceIStoredSpellVar<T>- Parameters:
nbt- the NBT compound tag to write tovalue- the value to write
-
read
Description copied from interface:IStoredSpellVarReads the value from an NBT compound tag.- Specified by:
readin interfaceIStoredSpellVar<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
Description copied from interface:ISpellVarUpdates the value of this spell variable for the given player.This method is typically called each tick to update time-dependent values.
-
isPersistent
public boolean isPersistent(boolean respawn) Description copied from interface:ISpellVarDetermines whether this spell variable should persist.- Specified by:
isPersistentin interfaceISpellVar<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:ISpellVarChecks whether this spell variable should be synchronized between client and server. -
write
Description copied from interface:ISpellVarWrites the value to a network buffer for synchronization. -
read
Description copied from interface:ISpellVarReads the value from a network buffer.
-