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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • The durability of my custom Item goes down only for a second then goes back to where it was before I clicked. I'd really appreciate if someone can point me in the right direction to get this working. @Override public ActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { ItemStack stack = playerEntity.getItemInHand(hand); if (!world.isClientSide) { ItemStack newStack = new ItemStack(stack.getItem()); newStack.setDamageValue(stack.getDamageValue() + 1); return ActionResult.success(newStack); } else return super.use(world, playerEntity, hand); }
    • biome.getRegistryName().equals(Biomes.SWAMP.location())  
    • Java 16 is not yet supported.
    • It is about the Java version. You cannot use Java 16. 
    • C:\Users\rauno\OneDrive\Töölaud\Uus kaust>java -Xmx2048M -Xms2048M -jar forgeserver.jar nogui 2021-06-21 10:09:17,374 main WARN Advanced terminal features are not available in this environment [10:09:17] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.1.0, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [10:09:17] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 16.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x29f69090) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x29f69090         at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41)         at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95)         at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41)         at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55)         at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47)         at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62)         at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55)         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63)         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60)         at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) C:\Users\rauno\OneDrive\Töölaud\Uus kaust>PAUSE is it saying for me when i am first opening it 
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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