Jump to content

1.10.2 Broken tool isn't removed (Solved)


mmcmain

Recommended Posts

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 by mmcmain
Fixed last code snippet.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :o

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.