Class SNBTConverter

java.lang.Object
io.github.projectunified.craftitem.nbt.SNBTConverter

public final class SNBTConverter extends Object
Converts Java objects to SNBT (Minecraft's text NBT format).

Takes maps, lists, arrays, and primitives and turns them into SNBT strings. Handles all the NBT types (byte, short, int, long, float, double, arrays, etc.) with proper formatting.

Bonus Feature - Data Component Format: Pass true to the second parameter of convert(Object, boolean) to use the newer data component format (brackets and equals instead of braces and colons).

  • Method Details

    • convert

      public static String convert(Object value)
      Converts a value to SNBT string format
      Parameters:
      value - The value to convert
      Returns:
      SNBT formatted string
    • convert

      public static String convert(Object value, boolean useDataComponentFormat)
      Converts a value to SNBT string format
      Parameters:
      value - The value to convert
      useDataComponentFormat - If true, use Minecraft data component format
      Returns:
      SNBT formatted string