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

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!

Do you mean overriding the item like this?

 

player.inventory.getCurrentItem().stackSize--;

player.inventory.addItemStackToInventory(new ItemStack(Items.bucket));

  • Author

I mean that I want it to have a damage value of 600 that goes down one every tick. When it is destroyed, then I want it to be replaced with a new item.

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.

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);
            }
        }
    }

Well, he did ask for it. :P

 

I just figured I'd try to do it since I gave him the wrong answer to start with and I felt bad.

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.