Class NbtOps

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<net.minecraft.nbt.Tag>
com.github.darksoulq.abyssallib.common.serialization.ops.NbtOps

public class NbtOps extends DynamicOps<net.minecraft.nbt.Tag>
An implementation of DynamicOps for Minecraft's NBT Tag structure.

This class facilitates the direct serialization of objects into native NBT tags (CompoundTag, ListTag, IntTag, etc.) without intermediate JSON conversion.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final NbtOps
    Singleton instance of NbtOps.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.nbt.Tag
    createBoolean(boolean value)
    Creates a ByteTag representing a boolean value.
    net.minecraft.nbt.Tag
    createDouble(double value)
    Creates a DoubleTag from a double value.
    net.minecraft.nbt.Tag
    createFloat(float value)
    Creates a FloatTag from a float value.
    net.minecraft.nbt.Tag
    createInt(int value)
    Creates an IntTag from an integer value.
    net.minecraft.nbt.Tag
    createList(List<net.minecraft.nbt.Tag> elements)
    Creates a ListTag from a list of tags.
    net.minecraft.nbt.Tag
    createLong(long value)
    Creates a LongTag from a long value.
    net.minecraft.nbt.Tag
    createMap(Map<net.minecraft.nbt.Tag, net.minecraft.nbt.Tag> map)
    Creates a CompoundTag from a map of tags.
    net.minecraft.nbt.Tag
    Creates a StringTag from a string value.
    net.minecraft.nbt.Tag
    Returns an empty tag representing no value (EndTag).
    getBooleanValue(net.minecraft.nbt.Tag input)
    Retrieves a boolean value from a tag.
    getDoubleValue(net.minecraft.nbt.Tag input)
    Retrieves a double value from a tag.
    getFloatValue(net.minecraft.nbt.Tag input)
    Retrieves a float value from a tag.
    getIntValue(net.minecraft.nbt.Tag input)
    Retrieves an integer value from a tag.
    Optional<List<net.minecraft.nbt.Tag>>
    getList(net.minecraft.nbt.Tag input)
    Retrieves a list of tags from a tag.
    getLongValue(net.minecraft.nbt.Tag input)
    Retrieves a long value from a tag.
    Optional<Map<net.minecraft.nbt.Tag, net.minecraft.nbt.Tag>>
    getMap(net.minecraft.nbt.Tag input)
    Retrieves a map of tags from a tag.
    getStringValue(net.minecraft.nbt.Tag input)
    Retrieves a string value from a tag.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final NbtOps INSTANCE
      Singleton instance of NbtOps.
  • Method Details

    • createString

      public net.minecraft.nbt.Tag createString(String value)
      Creates a StringTag from a string value.
      Specified by:
      createString in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The string to wrap.
      Returns:
      The resulting StringTag.
    • createInt

      public net.minecraft.nbt.Tag createInt(int value)
      Creates an IntTag from an integer value.
      Specified by:
      createInt in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The integer to wrap.
      Returns:
      The resulting IntTag.
    • createLong

      public net.minecraft.nbt.Tag createLong(long value)
      Creates a LongTag from a long value.
      Specified by:
      createLong in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The long to wrap.
      Returns:
      The resulting LongTag.
    • createFloat

      public net.minecraft.nbt.Tag createFloat(float value)
      Creates a FloatTag from a float value.
      Specified by:
      createFloat in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The float to wrap.
      Returns:
      The resulting FloatTag.
    • createDouble

      public net.minecraft.nbt.Tag createDouble(double value)
      Creates a DoubleTag from a double value.
      Specified by:
      createDouble in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The double to wrap.
      Returns:
      The resulting DoubleTag.
    • createBoolean

      public net.minecraft.nbt.Tag createBoolean(boolean value)
      Creates a ByteTag representing a boolean value.
      Specified by:
      createBoolean in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      value - The boolean to wrap (1 for true, 0 for false).
      Returns:
      The resulting ByteTag.
    • createList

      public net.minecraft.nbt.Tag createList(List<net.minecraft.nbt.Tag> elements)
      Creates a ListTag from a list of tags.
      Specified by:
      createList in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      elements - The tags to include in the list.
      Returns:
      A ListTag containing the elements.
    • createMap

      public net.minecraft.nbt.Tag createMap(Map<net.minecraft.nbt.Tag, net.minecraft.nbt.Tag> map)
      Creates a CompoundTag from a map of tags.

      Keys in the map must be convertible to strings.

      Specified by:
      createMap in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      map - The map of key-value tags.
      Returns:
      A CompoundTag containing the map entries.
    • getStringValue

      public Optional<String> getStringValue(net.minecraft.nbt.Tag input)
      Retrieves a string value from a tag.
      Specified by:
      getStringValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the string if present.
    • getIntValue

      public Optional<Integer> getIntValue(net.minecraft.nbt.Tag input)
      Retrieves an integer value from a tag.
      Specified by:
      getIntValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the integer if present.
    • getLongValue

      public Optional<Long> getLongValue(net.minecraft.nbt.Tag input)
      Retrieves a long value from a tag.
      Specified by:
      getLongValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the long if present.
    • getFloatValue

      public Optional<Float> getFloatValue(net.minecraft.nbt.Tag input)
      Retrieves a float value from a tag.
      Specified by:
      getFloatValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the float if present.
    • getDoubleValue

      public Optional<Double> getDoubleValue(net.minecraft.nbt.Tag input)
      Retrieves a double value from a tag.
      Specified by:
      getDoubleValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the double if present.
    • getBooleanValue

      public Optional<Boolean> getBooleanValue(net.minecraft.nbt.Tag input)
      Retrieves a boolean value from a tag.

      Typically parses a ByteTag where 0 is false and non-zero is true.

      Specified by:
      getBooleanValue in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the boolean if present.
    • getList

      public Optional<List<net.minecraft.nbt.Tag>> getList(net.minecraft.nbt.Tag input)
      Retrieves a list of tags from a tag.
      Specified by:
      getList in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the list if the tag is a list type.
    • getMap

      public Optional<Map<net.minecraft.nbt.Tag, net.minecraft.nbt.Tag>> getMap(net.minecraft.nbt.Tag input)
      Retrieves a map of tags from a tag.
      Specified by:
      getMap in class DynamicOps<net.minecraft.nbt.Tag>
      Parameters:
      input - The tag to inspect.
      Returns:
      An Optional containing the map if the tag is a compound type.
    • empty

      public net.minecraft.nbt.Tag empty()
      Returns an empty tag representing no value (EndTag).
      Specified by:
      empty in class DynamicOps<net.minecraft.nbt.Tag>
      Returns:
      The singleton EndTag instance.