Posted April 25, 201510 yr 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
April 25, 201510 yr 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 http://i.imgur.com/NdrFdld.png[/img]
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.