mojira.dev
MC-195168

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

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 @unknown 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);
   });
}

Linked issues

Attachments

Comments 16

Cobweb should also be added to this.

Why leaves? Sword does not break leaves any faster

I now removed them, I thought, they would mine them faster.

It seems like swords only break leaves on bedrock faster, but not on java.

6 more comments

Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂

[media][media]

Of all updates to fix this for, the one that add bamboo blocks is a great time to do it.

Swords actually take 2 durability to mine any block, which I'm not sure is intended. All other tools only use one durability mining any material, but the sword takes two for some reason. I think this feature is alright for using a sword on random materials like dirt, since that would tarnish a sharp sword, but taking 2 durability to break bamboo which it's the correct tool for seems inappropriate.

I always thought this was intended, just like how axes use two durability when you attack something. You're using the tool for something other than its intended purpose: swords are made for attacking, not mining; axes are made for cutting wood, not zombies.

That being said, it seems like a rather unintuitive and unnecessary game mechanic, especially now that we have blocks like bamboo that are intended to be mined with a sword. I wouldn't go so far as to call it a bug, but it should still be reviewed and possibly removed or reworked.

bugsbugsbugs

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Items

bamboo, bamboo_sapling, cobweb, sword

1.16.1, 20w29a, 20w30a, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, ..., 24w33a, 1.21.3, 1.21.4, 25w08a, 1.21.7

Retrieved