I don't know if there's a better way but you can use tr7zw's item nbt api, create a new NBTItem with the itemstack you have and then use hasTag and setString, setInt etc. methods according to what you need.
An example in kotlin:
Code:
val item = ItemStack(Material.HOPPER)
val nbtitem = NBTItem(item)
nbtitem.setString("collector", this::class.java.simpleName)
nbtitem.setString("material", material.name)
player.inventory.addItem(nbtitem.item)
An example in a listener to see if the tool has the tags:
Code:
@EventHandler
fun onPlace(event: BlockPlaceEvent) {
if (event.isCancelled) return
if (!event.itemInHand.hasItemMeta()) return
val nbtitem = NBTItem(event.itemInHand)
if (!nbtitem.hasTag("collector") || !nbtitem.hasTag("material")) return
//whatever you want to do with the item
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.