Posted November 1, 201410 yr 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!
November 1, 201410 yr Do you mean overriding the item like this? player.inventory.getCurrentItem().stackSize--; player.inventory.addItemStackToInventory(new ItemStack(Items.bucket));
November 1, 201410 yr 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.
November 1, 201410 yr 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.
November 1, 201410 yr Author But what I want to know is HOW DO I TELL IT TO DO STUFF each tick and when it is destroyed?
November 1, 201410 yr 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); } } }
November 1, 201410 yr Well, he did ask for it. 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.