Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

Item#shouldCauseReequipAnimation

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

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

@Override
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.

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.