MrabEzreb Posted November 1, 2014 Posted November 1, 2014 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! Quote
yariplus Posted November 1, 2014 Posted November 1, 2014 Do you mean overriding the item like this? player.inventory.getCurrentItem().stackSize--; player.inventory.addItemStackToInventory(new ItemStack(Items.bucket)); Quote
MrabEzreb Posted November 1, 2014 Author Posted November 1, 2014 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. Quote
yariplus Posted November 1, 2014 Posted November 1, 2014 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. Quote
MrabEzreb Posted November 1, 2014 Author Posted November 1, 2014 But what I want to know is HOW DO I TELL IT TO DO STUFF each tick and when it is destroyed? Quote
MrabEzreb Posted November 1, 2014 Author Posted November 1, 2014 How? Can I have exact code (besides what is inside the method)? Quote
yariplus Posted November 1, 2014 Posted November 1, 2014 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); } } } Quote
yariplus Posted November 1, 2014 Posted November 1, 2014 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. Quote
Recommended Posts
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.