Jump to content

Time


ZTheDragonz

Recommended Posts

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

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



×
×
  • Create New...

Important Information

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