Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-195168

Swords consume double durability than they normally would when destroying bamboo saplings, bamboo, or cobwebs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.16.1, 20w29a, 20w30a, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1, 1.16.2 Release Candidate 2, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 1, 1.16.4 Pre-release 2, 1.16.4 Release Candidate 1, 1.16.4, 20w45a, 20w46a, 20w48a, 20w49a, 20w51a, 21w03a, 21w05a, 21w05b, 21w06a, 21w07a, 21w08a, 21w08b, 21w10a, 21w11a, 21w13a, 21w14a, 21w15a, 21w16a, 21w17a, 21w18a, 1.17, 1.17.1, 21w40a, 21w41a, 21w42a, 21w43a, 1.18 Release Candidate 3, 1.18, 1.18.1, 22w03a, 22w05a, 22w06a, 22w07a, 1.18.2 Pre-release 2, 1.18.2, 22w17a, 1.19, 1.19.2, 22w43a, 1.19.3, 1.19.4, 1.20, 1.20.1, 24w11a
    • Confirmed
    • Items
    • Normal
    • Gameplay

      The Bug:

      Swords consume double durability than they normally would when destroying bamboo saplings, bamboo, or cobwebs.

      Swords can be used to mine bamboo saplings, bamboo, and cobwebs much faster so it doesn't make much sense that they consume double durability than they normally would when destroying these blocks.

      Steps to Reproduce:

      1. Place down a bamboo sapling, bamboo, or a cobweb.
      2. Give yourself a sword that has two durability by using the command provided below.
        /give @s minecraft:netherite_sword{Damage:2029}
      3. Destroy the bamboo sapling, bamboo, or cobweb using the sword and as you do this, pay close attention to the sword's durability.
      4. Take note as to whether or not swords consume double durability than they normally would when destroying bamboo saplings, bamboo, or cobwebs.

      Observed Behavior:

      Swords consume double durability than they normally would when destroying bamboo saplings, bamboo, or cobwebs.

      Expected Behavior:

      Swords would consume one durability when destroying bamboo saplings, bamboo, or cobwebs.

      Code Analysis:

      Code analysis by Avoma can be found below.

      The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

      net.minecraft.world.item.SwordItem.java
      public class SwordItem extends TieredItem implements Vanishable {
         ...
         public boolean mineBlock(ItemStack itemStack, Level level, BlockState blockState, BlockPos blockPos, LivingEntity livingEntity) {
            if (blockState.getDestroySpeed(level, blockPos) != 0.0F) {
               itemStack.hurtAndBreak(2, livingEntity, (livingEntity1) -> {
                  livingEntity1.broadcastBreakEvent(EquipmentSlot.MAINHAND);
               });
            }
      
            return true;
         }
         ...

      If we look at the above class, we can see that there is only one check that is carried out before allowing the durability of a sword to decrease when using this item to destroy a block. This check is to see if the said block can be instantly destroyed, and if it can, the sword doesn't consume durability, but if it can't, the sword will consume double durability. The game doesn't check if the said block is a bamboo sapling, bamboo, or a cobweb, before allowing the sword to consume double durability, therefore resulting in this problem occurring.

      Fix:

      Simply altering the existing "if" statement to check if the said block is a bamboo sapling, bamboo, or a cobweb, and adding an "if else" statement to then check if the said block can be instantly destroyed before allowing the sword to consume double durability, will resolve this problem.

      Current "if" statement:
      if (blockState.getDestroySpeed(level, blockPos) != 0.0F) {
         itemStack.hurtAndBreak(2, livingEntity, (livingEntity1) -> {
            livingEntity1.broadcastBreakEvent(EquipmentSlot.MAINHAND);
         });
      }
      Fixed "if" statement:
      if (blockState.getBlock() instanceof BambooSaplingBlock || blockState.getBlock() instanceof BambooBlock || blockState.getBlock() instanceof WebBlock) {
         itemStack.hurtAndBreak(1, livingEntity, (livingEntity1) -> {
            livingEntity1.broadcastBreakEvent(EquipmentSlot.MAINHAND);
         });
      } else if (blockState.getDestroySpeed(level, blockPos) != 0.0F) {
         itemStack.hurtAndBreak(2, livingEntity, (livingEntity1) -> {
            livingEntity1.broadcastBreakEvent(EquipmentSlot.MAINHAND);
         });
      }

        1. MC-195168.mp4
          5.02 MB
        2. MC-195168-1.mp4
          6.99 MB
        3. MC-195168 - Cobweb.png
          MC-195168 - Cobweb.png
          1006 kB
        4. MC-195168 - Bamboo.png
          MC-195168 - Bamboo.png
          791 kB
        5. MC-195168 - Current Code.png
          MC-195168 - Current Code.png
          29 kB
        6. MC-195168 - Fixed Code.png
          MC-195168 - Fixed Code.png
          46 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            23 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              CHK: