Jump to content

Item's having a seizure (Animation on updating NBT)


Recommended Posts

I've realized a major flaw in my item: every 1200 ticks, it does something (this thing doesn't matter in this context). I check if 12000 ticks happened by using a NBT value that updates every tick using the method OnUpdate.


It works nicely, but sadly the item will make the weird animation where it just goes up and down every tick. I believe this is due to the NBT being updated (or set if you want)


I hope someone knows what I'm talking about

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz


Link to comment
Share on other sites

When overriding that method, make sure to still return true for some cases, e.g.

public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return !ItemStack.areItemsEqual(oldStack, newStack); // maybe also add || slotChanged

A better solution, however, is to avoid updating NBT every tick and instead store the world time at which the next event should happen, then simply compare the current time against the NBT each tick:

// whenever time should be set:
long next = world.getTotalWorldTime() + 12000;
stack.getTagCompound().setLong('nextWhatever', next);

// checking each tick:
if (world.getTotalWorldTime() > stack.getTagCompound().getLong('nextWhatever')) {
// do whatever you need to do, then set the next time again

Not only will you not have to bother with shouldCauseReequipAnimation, but it is also more efficient as you only write to NBT once per cycle, rather than every single tick.

Link to comment
Share on other sites

Well, if we are talking about BEST ways - the one is to use damn @Capability.


Timestamps are not dimension-safe and still require NBT interactions. Caps don't (only once).

1.7.10 is no longer supported by forge, you are on your own.

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.

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.


  • Create New...

Important Information

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