Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12] Item doesn't take damage


Recommended Posts

I have this code in a block:

 

    @Override
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack) {
        if(stack != null) {
            Item i = stack.getItem();
            if(i instanceof ItemTool) {
                stack.damageItem(2, player);
            }
            else if(i instanceof ItemHoe) {
                stack.damageItem(1, player);
            }
        }
    }

 

While in survival mode, breaking the block with a hoe does not result in the item taking damage. When trying to debug, the item sustains the damage, this method returns, and as far as I can tell, no longer has the damage. Any other tool only takes 1 damage (???). I can't figure out what part of vanilla is overriding this effect.

 

I know for a fact that this worked fine in 1.7.10, but I would need to go back and check 1.10 and 1.11

Edited by Draco18s

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 post
Share on other sites

The ItemHoe setBlock() method also calls stack.damageItem(1, player) so you're doing same as vanilla use should do. I'm sure you know how to trace the code as well or better than me, but seems like standard stuff would prevent the damage: if the max damage is less than zero, if the NBT tag has unbreakable boolean set true, if the unbreakable enchantment is in effect, if player is in creative mode.

 

One thing though -- what material is your hoe? The ToolMaterial affects much of these fields. 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to post
Share on other sites
8 hours ago, jabelar said:

The ItemHoe setBlock() method also calls stack.damageItem(1, player) so you're doing same as vanilla use should do. I'm sure you know how to trace the code as well or better than me, but seems like standard stuff would prevent the damage: if the max damage is less than zero, if the NBT tag has unbreakable boolean set true, if the unbreakable enchantment is in effect, if player is in creative mode.

The stack itself takes the damage, at the end of the above function, the stack has the desired 1 damage. When it returns (back to the InteractionManager) it does not.

8 hours ago, jabelar said:

 

One thing though -- what material is your hoe? The ToolMaterial affects much of these fields. 

The type of hoe didn't matter. I tried wooden, iron, and diamond.

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 post
Share on other sites

Nope.

 

Looks like I can use removedByPlayer instead and that correctly deals damage to the item.

Edited by Draco18s

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

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.