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

How to set a timer so every time the player right click an item start and when it get to a specific value something happens

For items, you cannot add a timer directly to the Item class due to the fact there is only 1 item instance of each item you declare, so you need to store any mutable information in the ItemStack NBT tag.

 

For a timer, you have two options: actually use a ticking timer that needs updating each tick, OR set one time value that is X ticks in the future, and check for when the world time reaches it. The second is nice because it avoids the NBT update - when the ItemStack NBT updates, it usually causes a rendering 'glitch'.

 

So:

1. Override Item#onItemRightClick

    a. Add an NBTTagCompound to the ItemStack given if it doesn't already have one

    b. Set a Long value (that's what Minecraft time uses) in the tag with world.getWorldTime() + X, where X is number of ticks (20 ticks = 1 second)

 

2. Override Item#onUpdate

    a. Check if the ItemStack in question has an NBTTagCompound and the correct tag (and the value is > 0)

    b. If so, check if the current world time is >= the value stored in the tag

    c. If so, do whatever you wanted to do, and either remove the time tag or set it back to zero

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.