I am trying to implement cooldown for my items (CooldownItem extends Item), and it seems like ItemStack.itemDamage is the only place where I can store the cooldown time, so that it is correctly shared between client and server and is remembered when the itemStack is moved/dropped/etc.
Once the cooldown starts, I set itemDamage to the respective itemStack, and then on each tick in the CooldownItem.onUpdate(...) method I decrease this itemStack's itemDamage by 1.
Now the problem happens in ItemRenderer.updateEquippedItems(): probably because the itemStacks' damage is updated EVERY tick, it can get out of sync between different itemStacks that were copied. In the method I mentioned above the item that the player is currently holding in his hand gets out of sync with some other ItemStack reference to the same item because their itemDamage values are off by a small amount, and unequip animation starts. On some other tick they get in sync again and equip animation starts. So while my item is on cooldown and the player is holding it, it jerks up and down in a really annoying fashion.
Perhaps this could even be regarded as a bug in Minecraft, since ItemRenderer is located in package net.minecraft.client.renderer. But there are no items in Minecraft that get damaged constantly while no one uses them, like my CooldownItem.
I thought about storing cooldown in some other place, like make a Map<ItemStack, Integer> in CooldownItem, but then sharing the cooldown between copied itemStacks and between client and server seems like it's going to be a real pain to code. I can't subclass ItemStack, because it's declared final.
Anyone got ideas how to fix my rendering issue?