From 1e9017fa6eb9c15b8040b263087862d1c1682f55 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Fri, 23 Feb 2024 15:11:23 -0600 Subject: [PATCH] feat: add nbt related methods --- .../hibiscuscommons/items/ItemBuilder.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/items/ItemBuilder.java b/common/src/main/java/me/lojosho/hibiscuscommons/items/ItemBuilder.java index d15ce06..3d40bbd 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/items/ItemBuilder.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/items/ItemBuilder.java @@ -233,6 +233,37 @@ public class ItemBuilder { return this; } + /** + * Adds NBT data to the item + * @param key + * @param value + * @return + */ + public ItemBuilder addNBTData(NamespacedKey key, String value) { + nbtData.put(key, value); + return this; + } + + /** + * Removes the NBT data from the item + * @param key + * @return + */ + public ItemBuilder removeNBTData(NamespacedKey key) { + nbtData.remove(key); + return this; + } + + /** + * This clears the extra NBT data that has been added. This will not clear the default NBT data that is added by the game. + * So if you're materially getting an oraxen item, it will not clear the oraxen NBT data. + * @return + */ + public ItemBuilder clearNBTData() { + nbtData.clear(); + return this; + } + /** * Returns the lore of the item. Use #setLore to set the lore! * @return @@ -249,6 +280,10 @@ public class ItemBuilder { return List.copyOf(itemFlags); } + public List getNBTDataKeys() { + return List.copyOf(nbtData.keySet()); + } + /** * Check to see if a item has any enchantments * @return @@ -273,6 +308,10 @@ public class ItemBuilder { return itemFlags.contains(flag); } + public boolean hasNBTData(NamespacedKey key) { + return nbtData.containsKey(key); + } + public ItemStack build() { ItemStack itemStack = Hooks.getItem(material); if (itemStack == null) return null;