Posted August 7, 201411 yr I have a hammer in my mod which when you left click on stone it makes it cracked stone. The item damages fine but when it reaches 0 durability, the item damage returns to 0 and the stack size is reduced to zero, however the item doesn't go away. Also, the breaking animation and sound is not shown or played. Source code: https://github.com/penguinsfan77/RandomStuff/ The item is damaged and the stone is cracked in the ItemEventHandler class in the events package. The Hammer class is in the items package. Any help is greatly appreciated, thanks.
August 7, 201411 yr I recently looked at the TileEntityFurnace class of Vanilla Minecraft, and they used something like if(hammerItemStack.stackSize >= 0){ hammerItemStack = null; } I'm not sure and haven't tested it, but it might solve the issue with the ItemStack with size 0. Thanks for helping me <3
August 7, 201411 yr Author I recently looked at the TileEntityFurnace class of Vanilla Minecraft, and they used something like if(hammerItemStack.stackSize >= 0){ hammerItemStack = null; } I'm not sure and haven't tested it, but it might solve the issue with the ItemStack with size 0. Thanks for your help. That should fix the issue of the item not going away but I don't think it it will fix the issue of of the item not playing the break sound or particle effect.
August 7, 201411 yr Author I'm going to try making the hammer class extend ItemTool to see if that works. I will post an update once I'm on my computer.
August 8, 201411 yr Author So the hammer class now extends item tool and i discovered that the reason that the item wasn't breaking was because I wasn't actually breaking a block. So i moved my code out of the ItemEventHandler class and into the onBlockDestroyed method. This allows the item to break properly however the stone is not cracking anymore and it seems that the setBlock() method doesn't work. Here is what I have: @Override public boolean onBlockDestroyed(ItemStack item, World world, Block block, int x, int y, int z, EntityLivingBase player) { item.damageItem(1, player); if (block.equals(Blocks.stone)) { world.setBlock(x, y, z, ModBlocks.crackedStone); } return true; } Could someone try to explain why the block that was broken is not replaced by cracked stone?
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.