Class NBTMapNormalizer

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

public final class NBTMapNormalizer extends Object
Normalizes maps and converts them to the right types for SNBT.

Takes raw map data and recursively converts it to properly typed values. Also supports custom string translators for dynamic substitution.

Bonus Feature - Forced-Value Maps: Use $type and $value keys to force a specific type:


 Map<String, Object> map = Map.of(
     "$type", "float",
     "$value", "123.45"
 );
 Object result = NBTMapNormalizer.normalize(map);  // Returns 123.45f
 

Supported types: byte, short, int, long, float, double, boolean, string, raw, list, compound, byte_array, int_array, long_array. Useful when Java's default type would be wrong.

  • Method Details

    • normalize

      public static Object normalize(Object value)
      Normalizes a value by resolving forced-value maps and applying translator
      Parameters:
      value - The value to normalize
      Returns:
      Normalized value (can be a Map, primitive, or array)
      Throws:
      IllegalArgumentException - if forced-value map is invalid
    • normalize

      public static Object normalize(Object value, UnaryOperator<String> translator)
      Normalizes a value by resolving forced-value maps and applying translator
      Parameters:
      value - The value to normalize
      translator - Custom string translator for values
      Returns:
      Normalized value (can be a Map, primitive, or array)
      Throws:
      IllegalArgumentException - if forced-value map is invalid