Probably Silly Question on ItemMeta/Damageable


#1

Hi there! First post! Woo!
I’m in the process of updating an older custom-made plugin to 1.13.2, but have hit a snag on a custom command, fixing items to be exact!

My old code used itemStackThing.setDurability( (short) 0), and it’s deprecated now.
It’s been a bit since I coded for Minecraft, so my issue is that I don’t remember how durability works!
My current understanding is that I should use something to the effect of:

Damagable itemStuff = (Damageable) itemStackThing.getItemMeta();,
and then use
itemStuff.setDamage( int damage );
to actually set the new durability.

Is the integer something I can set to be 0 like before, or do I need to set it to a different number?
Thanks,
Mip

P.S.: The reason I’m asking before testing anything is because half of my code is needing updated to 1.13 still so… :stuck_out_tongue:
EDIT: It looks like it’s still 0 like it was before, but let me check to be sure. I think it uses NBT values, but I could be wrong. Will report back.


#2

Yes you can set it like the old method does. 0 = no damage.
If you forgot check if ItemMeta is instanceof Damageable before casting
to avoid a CastException

The only difference here is the method for setting the ItemStack durability was moved
to ItemMeta/Damageable and the value set to int instead of a short which I highly agree on.