Hunternif Posted January 12, 2013 Posted January 12, 2013 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? Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted January 12, 2013 Author Posted January 12, 2013 After a bit more research, I can add that the desynchronization of itemStacks in method updateEquippedItems() happens because of Container.detectAndSendChanges() Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Kore Posted January 12, 2013 Posted January 12, 2013 also try to do if(!world.isremote)otherwise you are sending it 2 times per tick btw Quote The Korecraft Mod
Hunternif Posted January 13, 2013 Author Posted January 13, 2013 Thanks for the reply, Kore! I thought I had to do everything that is not rendering (and changing itemStack's damage surely is not) BOTH on the server and the client. But I tried your suggestion and added this check to CooldownItem.onUpdate(...), and the game still worked properly. However, the jerking item issue was not solved. It even seemed like the item was spending more time in a "lowered" position than before. Although that looked a bit better than a "full" up-and-down swing Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted January 13, 2013 Author Posted January 13, 2013 bump Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
epicsquare Posted January 14, 2013 Posted January 14, 2013 I have this exact same problem. Except for me it does it even if I damage my item just on use not even continuously. Quote
opssemnik Posted January 14, 2013 Posted January 14, 2013 you can change from metadata, to nbttag i ItemStack (read and write from nbt) Quote
Hunternif Posted January 16, 2013 Author Posted January 16, 2013 Thanks for suggestion, opssemnik, I'll look into that Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted January 16, 2013 Author Posted January 16, 2013 Awesome, that was exactly what I needed! Thanks a lot, opssemnik. There's only one (minor) issue: the item name stays on the display for the whole duration of my cooldown, for pretty much the same reason as described in the first post: because when item's NBT tag changes, Minecraft's GUI overlay thinks it's a different item that the player is holding now. But there's no more item unequip/equip problem! Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
gamehawk Posted January 16, 2013 Posted January 16, 2013 It also happens with IC2 chargepads mod, and basically anything that modifies metadata while the item is held. Hopefully the forge devs will find a way to fix this soon. Quote
Hunternif Posted January 16, 2013 Author Posted January 16, 2013 Unfortunately, item name showing up is not the only problem. If I change currently equipped item on cooldown to some other item and then back again to my item on cooldown, it starts unequip-equip animation again. So ultimately the problem wasn't solved. However, NBT Tag is clearly much better than item stack damage, I just haven't read about its usage until now. Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
PCChazter Posted February 11, 2013 Posted February 11, 2013 I have the same issue with a mod that I am working on. I change the damage every 6 ticks using onUpdate(), then use getIconFromDamageForRenderPass() to change the icon for it, so I don't think using nbt would work for me. Is this going to get fixed in the near future? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.