mojira.dev
MC-112630

Carrot on a stick cannot be broken

The bug

When you ride a pig and right-click with a carrot on a stick, your pig will be fed and will walk faster. Also the durability of the carrot on a stick is decreased by 7 units.

What I expected to happen was:
When the carrot on a stick is nearly broken and I sit on a non-boosted pig and right-click with that carrot on a stick, it should break or become a fishing rod.

What actually happened was:
The carrot on a stick was not broken and the pig did not walk faster than before. Because of this, carrots on sticks cannot be used more often than thrice and are not able to break.

To reproduce

  1. Give yourself an unenchanted minecraft:carrot_on_a_stick with a damage value of 19

    /give @s minecraft:carrot_on_a_stick{Damage:19}
  2. Spawn a pig and equip it with a saddle

  3. Switch into survival mode and ride on that pig

  4. Right-click with the carrot on a stick while riding the pig

  5. Notice that the pig does not get boosted and the carrot on a stick stays the same

Code analysis

From MCP 9.35 for Minecraft 1.11:

ItemCarrotOnAStick.java

public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (worldIn.isRiding() && worldIn.getRidingEntity() instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)worldIn.getRidingEntity();

        // This line causes to check whether the remaining durability is more than seven. If it is not, the item cannot be used.
        if (itemstack.getMaxDamage() - itemstack.getMetadata() >= 7 && entitypig.boost())
        {
            // Because of this line, the carrot on a stick gets damaged by seven durability points. This function also causes the carrot on a stick to break if necessary.
            itemstack.damageItem(7, worldIn);

            // This replaces the carrot on a stick by a fishing rod if it was broken.
            if (itemstack.func_190926_b())
            {
                ItemStack itemstack1 = new ItemStack(Items.FISHING_ROD);
                itemstack1.setTagCompound(itemstack.getTagCompound());
                return new ActionResult(EnumActionResult.SUCCESS, itemstack1);
            }

            return new ActionResult(EnumActionResult.SUCCESS, itemstack);
        }
    }

    worldIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult(EnumActionResult.PASS, itemstack);
}

Possible solutions

  1. The maximum durability of carrots on sticks could be restricted to three or four and when feeding a pig, the durability decreases by one only.

  2. The maximum durability of carrots on sticks could be changed to 21 or 28 and when feeding a pig, the durability decreases by seven still.

  3. The check whether the carrot on a stick has enough damage is removed and you can still use a carrot on a stick if it has less than six durability points remaining.

Comments 7

Swekob

I manually tested if the carrot on a stick could be broken with unbreaking enchantments.
Conclusion: Carrot on a stick can't break with unbreaking level 1, 2 or 3.

Swekob

Affects 17w14a & 17w15a

JUE13

Confirmed for 1.12-pre 7.

Asteraoth

Confirmed for 18w31a

Asteraoth

Confirmed for 18w32a

Asteraoth

Confirmed for 18w33a

Asteraoth

Confirmed for 1.13.1-pre1

violine1101

Felix Jones

Confirmed

(Unassigned)

Minecraft 1.11.2, Minecraft 17w14a, Minecraft 17w15a, Minecraft 1.12 Pre-Release 6, Minecraft 1.12 Pre-Release 7, ..., Minecraft 19w14a, Minecraft 19w14b, 1.14.4, 1.15 Pre-Release 2, 1.15.1

20w06a

Retrieved