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).

Converts maps, lists, arrays, and primitives to SNBT strings with proper formatting. Supports data component format with brackets and equals syntax.

Example:


 SNBTConverter.convert(Map.of("key", 42, "name", "test"));
 // Returns: {key:42,name:"test"}

 SNBTConverter.convert(Map.of("key", 42), true);
 // Returns: [key=42]
 
  • 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