Hello guys. I’m really kind of stuck with this problem. As the title says I’m trying to change an items durability, which according to the TransactionResult is successfull. But this doesn’t seem to change the item that the player is hold/ which is in his inventory.
This is the code I’m using to update the items durability: if(item.supports(Keys.ITEM_DURABILITY)) { item.offer(Keys.ITEM_DURABILITY, item.get(Keys.ITEM_DURABILITY).get()-1); }
I’ve already tried offering the item to the players inventory, using player.getInventory().offer(ItemStack), but this just adds a new item with less durability.
One more question. When I set the durability of an item to 0 or -1 it doesn’t break. Do I have to do a custom check and fire an event for that? Currently, I’m just deleting the item by setting the itemInHand to null, but this of course doesn’t trigger the animation&sound.
I don’t think it’s possible because the animation is handled client side but you can send the Sound with player.playSound(SoundTypes.ITEM_BREAK, player.getLocation().getPosition(), 1);
for only the Player.
Or with player.getWorld().playSound(SoundTypes.ITEM_BREAK, player.getLocation().getPosition(), 1);
for every player nearby. The last argument is the volume between 0-2.