Jump to content

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


Jacky2611

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Post logs as per https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ They may have information that will answer these questions.
    • I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon DIGITAL HACK RECOVERY, a beacon of hope in my darkest hour. Despite my initial doubts, I decided to take a leap of faith and give them a shot as a final lifeline. The experts at DIGITAL HACK RECOVERY proved to be masters of their craft, guiding me through their exclusive process with precision and expertise. Utilizing cutting-edge blockchain analysis methods, they were able to track down the elusive trail of my missing funds and identify the exact point of failure. Their forensic talents were unparalleled as they tirelessly combed through the intricate web of blockchain data to locate my cryptocurrency. With each step they took, they kept me informed of their progress, never wavering in their belief that my funds could be rescued. After several painstaking weeks, DIGITAL HACK RECOVERY finally located and restored my $166,000 worth of cryptocurrency. I was awestruck that they were able to salvage what I had thought was lost forever. The whole experience restored my faith in the crypto space and proved that even in the worst situations, recovery is possible with the right experts on your side. I will be forever grateful to DIGITAL HACK RECOVERY for giving me back my life savings when I needed it most. Their tireless efforts and technical mastery turned what could have been a devastating loss into an uplifting success story. Book a time with DIGITAL HACK RECOVERY through: digital hack recovery @ techie . com &  +12018871705
    • public class ParticleReboundRecipe implements Recipe<CraftingContainer> { private List<ParticleReboundIngredient> inputs; private ParticleReboundFuel fuel; private ItemStack output; public ParticleReboundRecipe(List<ParticleReboundIngredient> inputs, ParticleReboundFuel fuel, ItemStack output) { this.inputs = inputs; this.fuel = fuel; this.output = output; } // TODO: Implement interface ... // TODO: Move to separate file if desired public record ParticleReboundIngredient(Ingredient ingredient, int count) { public static final Codec<ParticleReboundIngredient> CODEC = RecordCodecBuilder.create( builder -> builder.group( Ingredient.CODEC.fieldOf("ingredient").forGetter((i) -> i.ingredient), Codec.INT.fieldOf("count").forGetter(i -> i.count) ).apply(builder, ParticleReboundIngredient::new) ); } // TODO: Move to separate file if desired public record ParticleReboundFuel(String tag) { public static final Codec<ParticleReboundFuel> CODEC = RecordCodecBuilder.create( builder -> builder.group(Codec.STRING.fieldOf("tag").forGetter(f -> f.tag)).apply(builder, ParticleReboundFuel::new) ); public boolean isFuel(ItemStack stack) { // TODO: Check if fuel item matches the tag } } public class Serializer implements RecipeSerializer<ParticleReboundRecipe> { public static final Codec<ParticleReboundRecipe> CODEC = RecordCodecBuilder.create( builder -> builder.group( ParticleReboundIngredient.CODEC.listOf().fieldOf("inputs").forGetter(r -> r.inputs), ParticleReboundFuel.CODEC.fieldOf("fuel").forGetter(r -> r.fuel), ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output) ).apply(builder, ParticleReboundRecipe::new) ); @Override public @NotNull Codec<ParticleReboundRecipe> codec() { return CODEC; } // TODO: The rest ... } }   ?
    • I'm sure load and SaveAdditional are what you are looking for, probably. Mind sharing your BE class code? You also need to override onLoad method if you haven't
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.