Jump to content

Overriding onUpdate() to change an item after 600 ticks?


MrabEzreb

Recommended Posts

Hey, I am Mrab Ezreb. I am making a mod and I want to make a certain item have a 600 tick (30 second) timer, and after that, change it into a different item. (the idea is that it cools down) I Know everything (I think) that I need to know, except for how to override it, I can't figure that part out.

Thanks!

Link to comment
Share on other sites

Sounds like you want to write a tick handler for the player tick. In the handler check if the item is in the player's inventory, then increment the damage value. Then check if it's over the cooldown time, and if so, set that inventory slot to the new ItemStack, like I did above for buckets.

Link to comment
Share on other sites

This works for me, put it in your item class.

 

    @Override
    public void onUpdate(ItemStack itemStack, World world, Entity entity, int slot, boolean inHand)
    {
        if (!world.isRemote && entity instanceof EntityPlayer)
        {
            int damage = itemStack.getItemDamage() + 1;
            if (damage >= 600)
            {
                EntityPlayer player = ((EntityPlayer) entity);
                player.inventory.setInventorySlotContents(slot, new ItemStack(Blocks.diamond_block));
            }else{
                itemStack.setItemDamage(damage);
            }
        }
    }

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.



×
×
  • Create New...

Important Information

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