Posted January 14, 20187 yr Forge 1.10.2-12.18.3.2511 I have a custom block with custom harvesting behavior. I override onBlockDestroyedByPlayer and do a bunch of checks on the block. One of them is applying more than typical damage to the tool being used. In my onBlockDestroyedByPlayer I do not pass the event up unless the block in question is not mine. I had thought damaging the tool would be as simple as calling: playerTool.damageItem(toolDamage, player); However although this does damage the tool, the tool is not removed when durability reaches zero. I assume because there is some additional cleanup code handled somewhere that I am not calling. Instead the behavior is that the stack count goes to 0, the icon is still rendered, the durability looks graphically to be 0 and then the tool can be used again from scratch gaining a new durability setting on a new use. I have searched pretty extensively and can't find anything related to my issue. If anyone has any insight that would be greatly appreciated. -- Before posting this I figured-out the answer. Leaving it here in case anyone else runs into the same issue. I had to add the following: if (playerTool.getItemDamage() <= 0) player.inventory.removeStackFromSlot(player.inventory.currentItem); Edited January 15, 20187 yr by mmcmain Fixed last code snippet.
January 14, 20187 yr 2 hours ago, mmcmain said: Instead the behavior is that the stack count goes to 0, the icon is still rendered, the durability looks graphically to be 0 and then the tool can be used again from scratch gaining a new durability setting on a new use. What version are you on? Because in the current versions, this problem no longer exists (stack size 0 stacks are treated the same as AIR / EMPTY). Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 14, 20187 yr Author Sorry should have noted the version in my original post. Just updated that. 1.10.2-12.18.3.2511 At the time I started it was the latest "release" for 1.10.2 but I haven't checked in a few days.
January 14, 20187 yr Ok, the ItemStack.EMPTY was added in 1.11 I believe. Yes, in 1.10 you still need to manage your own destroyed stacks. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 14, 20187 yr Author Ok thanks. I just realized that I should change: if (toolDamage >= playerTool.getMaxDamage()) player.inventory.removeStackFromSlot(player.inventory.currentItem); to if (playerTool.getItemDamage() >= playerTool.getMaxDamage()) player.inventory.removeStackFromSlot(player.inventory.currentItem); because if I update to 1.11+ where the fix is then I would potentially be destroying a new tool if someone was using a mod that replaces broken items on your hotbar.
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.