Module syntaxnbt

Class NBTUtil

java.lang.Object
at.syntaxerror.syntaxnbt.NBTUtil

public final class NBTUtil extends Object
A utility class for serializing and deserializing NBT and SNBT
Author:
SyntaxError404
  • Field Details

    • MAX_DEPTH

      public static int MAX_DEPTH
      The default maximum number of layers to traverse when serializing/stringifying
  • Method Details

    • deserialize

      public static TagCompound deserialize(InputStream input) throws IOException
      Reads and populates a compound tag from a stream (NBT format). If the stream is compressed, it is decompressed automatically
      Parameters:
      input - stream to read from
      Returns:
      the deserialized tag
      Throws:
      IOException - if an I/O error occured
      See Also:
    • deserialize

      public static TagCompound deserialize(InputStream input, NBTCompression compression) throws IOException
      Reads and populates a compound tag from a stream (NBT format)
      Parameters:
      input - stream to read from
      compression - compression of the stream
      Returns:
      the deserialized tag
      Throws:
      IOException - if an I/O error occured
      See Also:
    • deserializeRegion

      public static Region deserializeRegion(RandomAccessFile input) throws IOException
      Reads and populates a region from a file
      Parameters:
      input - file to read from
      Returns:
      the deserialized region
      Throws:
      IOException - if an I/O error occured
    • serialize

      public static void serialize(String name, TagCompound compound, OutputStream output) throws IOException
      Writes a compound tag to a stream (NBT format)
      Parameters:
      name - name of the compound tag (optional)
      compound - compound tag to be serialized
      output - stream to write to
      Throws:
      IOException - if an I/O error occured
      See Also:
    • serialize

      public static void serialize(String name, TagCompound compound, OutputStream output, NBTCompression compression) throws IOException
      Writes a compound tag to a stream (NBT format)
      Parameters:
      name - name of the compound tag (optional)
      compound - compound tag to be serialized
      output - stream to write to
      compression - compression scheme to apply to the stream
      Throws:
      IOException - if an I/O error occured
      See Also:
    • serializeRegion

      public static void serializeRegion(Region region, RandomAccessFile output) throws IOException
      Writes a region to a file
      Parameters:
      region - region to be serialized
      output - file to write to
      Throws:
      IOException - if an I/O error occured
    • parse

      public static TagCompound parse(String input)
      Reads and populates a compound tag from a string (SNBT format)
      Parameters:
      input - string to read from
      Returns:
      the parsed tag
    • parsePath

      public static PathNode parsePath(String input)
      Reads an NBT path from a string
      Parameters:
      input - string to read from
      Returns:
      the parsed path
    • stringify

      public static String stringify(TagCompound compound)
      Writes a compound tag to a string (SNBT format)
      Parameters:
      compound - compound tag to be stringifyed
      Returns:
      the stringifyed compound tag
    • stringify

      public static String stringify(TagCompound compound, boolean colored)
      Writes a compound tag to a string (SNBT format). If colored, the string will contain color codes (according to Minecraft's old chat color system using section signs ยง)
      Parameters:
      compound - compound tag to be stringifyed
      colored - whether the string should contain color codes
      Returns:
      the stringifyed compound tag
    • stringify

      public static String stringify(PathNode path)
      Writes an NBT path to a string
      Parameters:
      path - path node to be stringifyed
      Returns:
      the stringifyed path