Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12, latest][Solved]Item switch animation when nbt changes.


Jacky2611
 Share

Recommended Posts

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);
    }

 


 

 

Here could be your advertisement!

Link to comment
Share on other sites

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 by Jacky2611

Here could be your advertisement!

Link to comment
Share on other sites

Whoa! :o

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!

Here could be your advertisement!

Link to comment
Share on other sites

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.)

Here could be your advertisement!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Here could be your advertisement!

Link to comment
Share on other sites

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).

  • Like 1

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.

Link to comment
Share on other sites

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.

Here could be your advertisement!

Link to comment
Share on other sites

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.

Here could be your advertisement!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.