NBT State

Usage of NBTState

In this page we gonna learn how to use NBTState in TailsLib.

What is NBTState?

NBTState is basicly wrapper for PersistentDataContainer (PDC) inspired by React.js useState .

Nothing fancy really.

Usage

To use NBTState we need a type that NBTState gonna use for access PDC and that means we need PersistentDataType. You could create your own PersistentDataType to automaticly convert data from PDC to your object.

So basicly we have 2 constructors.

public NBTState(String key, PersistentDataType<?, T> type)
public NBTState(String key, PersistentDataType<?, T> type, T defaultValue)

Just create a field with one of constructors.

public final NBTState<Integer> clicksState = new NBTState<>(
    "clicks", // Key of NBT
    PersistentDataType.INTEGER, // Type 
    0 // Default value to be set
);

To access and write data to PDC with this state we use

There's example if without default value

Last updated