Jacky2611 Posted July 23, 2017 Posted July 23, 2017 (edited) Whenever I change my items nbt data the item switch animation gets triggered. Is there any good reason why this happens or is it a bug? Edited July 23, 2017 by Jacky2611 I am an idiot Quote Here could be your advertisement!
Choonster Posted July 23, 2017 Posted July 23, 2017 Override Item#shouldCauseReequipAnimation. 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 (edited) I am already doing that. EDIT: Somehow forgot the override annotation and spelled reequip with only one "e". Edited July 23, 2017 by Jacky2611 Quote Here could be your advertisement!
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 Yeah, I misspelled the method name. I wrote that yesterday evening when I was way too tired. Sorry for bothering you guys with it. Only problem left is that when I switch between the same items (which both save data to nbt in their update method) the switch animation gets canceled after the first few frames. I am guessing that a nbt changes a few moments after the animation starts playing makes the shouldCauseReequipAnimation function return false and then cancels the already started animation. Any good ideas on how to solve this? if not I will just not trigger the animation in the first place if I switch to the same item. Spoiler @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { if(slotChanged) return true; //check item damage for subitems! return !oldStack.getItem().equals(newStack.getItem()); //!ItemStack.areItemStacksEqual(oldStack, newStack); } Quote Here could be your advertisement!
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 (edited) I know, I know. I hadn't slept in 24 hours when I first wrote that piece of code yesterday and was absolutely sure that I didn't make any mistakes. (thats why I usually rewrite half my code in the morning) And what IDE do you have that generates method overrided for you? I am using eclipse and it doesn't even help me at all when I try to overwrite something. Edited July 23, 2017 by Jacky2611 Quote Here could be your advertisement!
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 Whoa! I didn't know that autocomplete could be used for overwriting methods. I only used it for fields, to create new methods or to fix spelling. NO MORE SEARCHING THE ORIGINAL CLASSES TO FIND THE DAMN PARAMETERS! Quote Here could be your advertisement!
Guest Posted July 23, 2017 Posted July 23, 2017 Item#shouldCauseReequipAnimation has a parameter called slotChanged. You can use this to determine if you switched between identical items in different slots. Quote
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 The problem is that the animation starts when I change from sloat a to b (both containing the same item) but gets canceld a few moments later when the item in slot b updates it nbt. Quote Here could be your advertisement!
Guest Posted July 23, 2017 Posted July 23, 2017 Oh, ok. That makes sense. As far as I know (I might be horribly wrong) updating an ItemStack's NBT data every tick can get very performance intensive. What are you trying to accomplish with that? Quote
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 I need a (short) countdown. And I know that it's not the most perfect solution. But I doubt that it will ever become a real performance bottleneck and I would rather avoid writing a Capability. (Mainly because a: I need to port this item back a few mc versions for a friend and b: I don't want to manually sync my data with the clients.) Quote Here could be your advertisement!
Guest Posted July 23, 2017 Posted July 23, 2017 If I understand that correctly, you are doing this on the client. You could add a first tick boolean to your item stack. If this value is false, you add a timestamp value to the stack's nbt tag and set it to Minecraft.getMinecraft().getSystemTime() and set the first tick boolean to true. You would need a method in your proxy for this though as the Minecraft class is not available on the server. Then you check every tick if the difference between the current value of Minecraft.getMinecraft().getSystemTime() and the timestamp value is higher than a certain amount of miliseconds and if that is the case, you do whatever you need to do. That way you only read the nbt every tick but you don't change it every tick. Quote
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 Nah, I am doing it on a server. Using timestamps is an option, but that would get complicated should the server be shut down for a while or crash. I would have to save the already passed ticks and set the timer to the current time every few minutes. And I don't really want to use getTotalWorldTime because as soon as an admin decides that he wants to skip the night my counter needs to be reset. I had the same problem a while ago when I tried to count the world age in days. Quote Here could be your advertisement!
Choonster Posted July 23, 2017 Posted July 23, 2017 1 minute ago, Jacky2611 said: Nah, I am doing it on a server. Using timestamps is an option, but that would get complicated should the server be shut down for a while or crash. I would have to save the already passed ticks and set the timer to the current time every few minutes. And I don't really want to use getTotalWorldTime because as soon as an admin decides that he wants to skip the night my counter needs to be reset. I had the same problem a while ago when I tried to count the world age in days. The /time command only changes the world time (WorldInfo#worldTime), not the total world time (WorldInfo#totalTime). 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 1 minute ago, Choonster said: The /time command only changes the world time (WorldInfo#worldTime), not the total world time (WorldInfo#totalTime). Riiiight. The problem with getTotalWorldTime was that it didn't add values when someone used the time command. Which was important when I was counting days but that doesn't matter now. I got them both mixed up. Thaanks. Quote Here could be your advertisement!
Jacky2611 Posted July 23, 2017 Author Posted July 23, 2017 5 minutes ago, diesieben07 said: Not sure what you mean by the server shutting down. getTotalWorldTime is preserved by the game. getTotalWorldTime is also not influenced by the time command. I meant that I couldn't use the system time. And yeah, in retrospect it is obvious that I can and should use getTotalWorldTime. I did something similar a few days ago and for some reason thought that I couldn't use the total world time for the same reason I couldn't use it back then. Quote Here could be your advertisement!
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.