Class NBTModifier
java.lang.Object
io.github.projectunified.craftitem.spigot.nbt.NBTModifier
- All Implemented Interfaces:
ItemModifier,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 Summary
ConstructorsConstructorDescriptionNBTModifier(Object value, boolean useDataComponent) Creates a new NBTModifier with the specified NBT data. -
Method Summary
Modifier and TypeMethodDescriptionvoidmodify(SpigotItem item, UnaryOperator<String> translator) Applies the NBT data to the SpigotItem.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.projectunified.craftitem.spigot.core.SpigotItemModifier
modify
-
Constructor Details
-
NBTModifier
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
Applies the NBT data to the SpigotItem. The translator is used to resolve variables in the NBT values.- Specified by:
modifyin interfaceSpigotItemModifier- Parameters:
item- the SpigotItem to modifytranslator- the string translator for variable substitution
-