Interface Tag<T extends @UnknownNullability Object>

Type Parameters:
T - the tag type
All Known Implementing Classes:
TagImpl

public sealed interface Tag<T extends @UnknownNullability Object> permits TagImpl<T>
Represents a key to retrieve or change a value.

All tags are serializable.

  • Method Details

    • Byte

      static Tag<Byte> Byte(String key)
    • Boolean

      static Tag<Boolean> Boolean(String key)
    • Short

      static Tag<Short> Short(String key)
    • Integer

      static Tag<Integer> Integer(String key)
    • Long

      static Tag<Long> Long(String key)
    • Float

      static Tag<Float> Float(String key)
    • Double

      static Tag<Double> Double(String key)
    • String

      static Tag<String> String(String key)
    • UUID

      static Tag<UUID> UUID(String key)
    • ItemStack

      static Tag<ItemStack> ItemStack(String key)
    • Component

      static Tag<Component> Component(String key)
    • NBT

      static Tag<BinaryTag> NBT(String key)
      Creates a flexible tag able to read and write any BinaryTag objects.

      Specialized tags are recommended if the type is known as conversion will be required both way (read and write).

    • Structure

      static <T> Tag<T> Structure(String key, TagSerializer<T> serializer)
      Creates a tag containing multiple fields.

      Those fields cannot be modified from an outside tag. (This is to prevent the backed object from becoming out of sync)

      Type Parameters:
      T - the tag type
      Parameters:
      key - the tag key
      serializer - the tag serializer
      Returns:
      the created tag
    • View

      static <T> Tag<T> View(TagSerializer<T> serializer)
      Specialized Structure tag affecting the src of the handler (i.e. overwrite all its data).

      Must be used with care.

    • Structure

      @Experimental static <T extends Record> Tag<T> Structure(String key, Class<T> type)
    • View

      @Experimental static <T extends Record> Tag<T> View(Class<T> type)
    • Transient

      static <T> Tag<T> Transient(String key)
      Creates a transient tag with the specified key. This tag does not get serialized to NBT (Named Binary Tag) format and is not sent to the client. Unlike other tags, which are serialized, transient tags are used for temporary data that only needs to exist on the server side.
      Type Parameters:
      T - The type of the tag's value.
      Parameters:
      key - The key.
      Returns:
      A transient tag with the key.
    • getKey

      Deprecated.
      misleading non-record component, use key() instead.
      Use key() instead
      Returns:
      the key
    • key

      String key()
      Returns the key for the Tag
      Same key specified during the creation.
      Returns:
      the key to use
    • defaultValue

      @Contract(value="_ -> new", pure=true) Tag<T> defaultValue(Supplier<T> defaultValue)
    • defaultValue

      @Contract(value="_ -> new", pure=true) Tag<T> defaultValue(T defaultValue)
    • map

      @Contract(value="_, _ -> new", pure=true) <R> Tag<R> map(Function<T,R> readMap, Function<R,T> writeMap)
    • list

      @Contract(value="-> new", pure=true) Tag<List<T>> list()
    • path

      @Contract(value="_ -> new", pure=true) Tag<T> path(String @Nullable ... path)
    • read

      T read(CompoundBinaryTag nbt)
    • write

      void write(CompoundBinaryTag.Builder nbtCompound, T value)
    • writeUnsafe

      void writeUnsafe(CompoundBinaryTag.Builder nbtCompound, @Nullable @Nullable Object value)
    • isView

      boolean isView()
    • shareValue

      boolean shareValue(Tag<?> other)
    • createDefault

      T createDefault()
    • copyValue

      T copyValue(T value)