Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12, latest][Solved]Item switch animation when nbt changes.
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
Jacky2611

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

By Jacky2611, July 23, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

Choonster    1620

Choonster

Choonster    1620

  • Reality Controller
  • Choonster
  • Forge Modder
  • 1620
  • 5047 posts
Posted July 23, 2017

Override Item#shouldCauseReequipAnimation.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

pWn3d    4

pWn3d

pWn3d    4

  • Tree Puncher
  • pWn3d
  • Forge Modder
  • 4
  • 39 posts
Posted July 23, 2017

If you return false it will not be played

  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45590 posts
Posted July 23, 2017
1 hour ago, Jacky2611 said:

Yeah, I misspelled the method name. I wrote that yesterday evening when I was way too tired.

This is why you use @Override. And this is also why you have an IDE. It will happily generate method overrides for you.

  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45590 posts
Posted July 23, 2017

Eclipse and IntelliJ both do it. Just type the name of the method into the class body and invoke auto-complete (ctrl-space).

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
Posted July 23, 2017

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!

  • Quote

Share this post


Link to post
Share on other sites

XFactHD    15

XFactHD

XFactHD    15

  • Diamond Finder
  • XFactHD
  • Members
  • 15
  • 364 posts
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

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

XFactHD    15

XFactHD

XFactHD    15

  • Diamond Finder
  • XFactHD
  • Members
  • 15
  • 364 posts
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

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

XFactHD    15

XFactHD

XFactHD    15

  • Diamond Finder
  • XFactHD
  • Members
  • 15
  • 364 posts
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

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45590 posts
Posted July 23, 2017

Usually you should use World::getTotalWorldTime, so that the countdown stops when you pause the game. But yes, the general concept of what XFact described is how you should implement a countdown.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45590 posts
Posted July 23, 2017

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.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Choonster    1620

Choonster

Choonster    1620

  • Reality Controller
  • Choonster
  • Forge Modder
  • 1620
  • 5047 posts
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).

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
Share on other sites

Jacky2611    42

Jacky2611

Jacky2611    42

  • Diamond Finder
  • Jacky2611
  • Members
  • 42
  • 499 posts
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

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • noneofyourbusiness1
      lattest stable forge not showing up in launcher

      By noneofyourbusiness1 · Posted 17 minutes ago

      what is happening is that when i installed forge, the installation works but when i open my launcher it does not appear in the versions but when i go to the .minecraft folder and i click on versions the forge folder with the .jar file and everything alright but doesn't appear in launcher   WARNING: I am using a pirate launcher I do not approve of the practice and I have no money to buy the game but if I could I would buy the game. the launcher i'm using is (Shiginima Launcher Sponge Edition V4300 which is the latest version of the launcher) and the latest version of (java 64 bit) i would be very grateful if anyone could help me forge-1.14.4-28.1.103-installer.jar.log
    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 24 minutes ago

      The method registerMessage(int, Class<MSG>, BiConsumer<MSG,PacketBuffer>, Function<PacketBuffer,MSG>, BiConsumer<MSG,Supplier<NetworkEvent.Context>>) in the type SimpleChannel is not applicable for the arguments (int, Class<PacketButtonClicked>, PacketButtonClicked::encode, PacketButtonClicked::decode, PacketButtonClicked.Handler::handle)   there's also errors over each portion "The type PacketButtonClicked does not define encode(MSG, PacketBuffer) that is applicable here"
    • loordgek
      on/off button for custom furnace

      By loordgek · Posted 26 minutes ago

      what does the error say, mouse over the error and the IDE tells whats wrong
    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 28 minutes ago

      thank you. is that all i need to put in those methods because i am still getting errors in the packet handler class     public static void Register()     {         int MId = 0;         INSTANCE.registerMessage(MId++, PacketButtonClicked.class, PacketButtonClicked::encode, PacketButtonClicked::decode, PacketButtonClicked.Handler::handle);              }
    • loordgek
      on/off button for custom furnace

      By loordgek · Posted 33 minutes ago

      return new PacketButtonClicked(buf.readBlockPos());
  • Topics

    • noneofyourbusiness1
      0
      lattest stable forge not showing up in launcher

      By noneofyourbusiness1
      Started 17 minutes ago

    • plugsmustard
      47
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 03:11 PM

    • JetCobblestone
      6
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 1 hour ago

    • matt1999rd
      1
      [1.14-newer] how to keep value when closing minecraft

      By matt1999rd
      Started 1 hour ago

    • matt1999rd
      9
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

  • Who's Online (See full list)

    • Cerandior
    • plugsmustard
    • Ugdhar
    • Epicmoofish
    • Lea9ue
    • Redstoneguy129
    • paveleroles
    • cookiedragon234
    • MoeBoy76
    • Tameet
    • noneofyourbusiness1
    • matt1999rd
    • Simon_kungen
    • lehjr
    • JetCobblestone
    • loordgek
    • J0WAY
    • Nuparu00
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12, latest][Solved]Item switch animation when nbt changes.
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community