java.lang.Object
io.github.projectunified.craftitem.spigot.nbt.NBTModifier
All Implemented Interfaces:
ItemModifier, SpigotItemModifier

public class NBTModifier extends Object implements SpigotItemModifier
Spigot modifier for applying NBT data to items.

Normalizes and converts map-based NBT data to SNBT format, then applies it to items. Supports both legacy NBT format and newer data component format (1.20.5+).

Example Usage:


 Map<String, Object> nbtData = Map.of(
     "display", Map.of(
         "Name", "Enchanted Sword"
     ),
     "Enchantments", List.of(
         Map.of("id", "minecraft:sharpness", "lvl", 5)
     )
 );
 ItemModifier modifier = new NBTModifier(nbtData, false);
 modifier.modify(spigotItem, s -> s);
 
  • Constructor Details

    • NBTModifier

      public NBTModifier(Object value, boolean useDataComponent)
      Creates a new NBTModifier with the specified NBT data.
      Parameters:
      value - the NBT data (typically a Map)
      useDataComponent - whether to use data component format (1.20.5+) or legacy NBT
  • Method Details

    • modify

      public void modify(SpigotItem item, UnaryOperator<String> translator)
      Applies the NBT data to the SpigotItem. The translator is used to resolve variables in the NBT values.
      Specified by:
      modify in interface SpigotItemModifier
      Parameters:
      item - the SpigotItem to modify
      translator - the string translator for variable substitution