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

Enchantment onTargetDamaged gets called twice for main hand items

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 1.21
    • None
    • Unconfirmed
    • (Unassigned)

      The Enchantment class has an onTargetDamaged method. This method is overridden and implemented solely in the DamageEnchantment class, which is used by Sharpness/Smite/Bane of Arthropods, and applies the Slowness effect from Bane of Arthropods.

      In the PlayerEntity class' attack method EnchantmentHelper.onTargetDamaged(this, target); is called.

      This consumer then calls the onTargetDamaged method as implemented in each enchantment. When the user is a PlayerEntity however, this happens for both the items equipped (item in hands and armor), and the item in the main hand. As a result, when a PlayerEntity uses a Bane of Arthropods weapon on an Arthropod, the slowness effect gets applied twice. This means the random duration of the effect will also be upgraded if the second random call is higher.

      All relevant method definitions included in attachments below.

      Confirmed by running with a debugger with a break point on the DamageEnchantment::onTargetDamaged when hitting an Arthropod with a weapon enchanted with Bane of Arthropods.

      I hope this was clear and understandable, I know it might be a bit confusing

        1. screenshot-1.png
          screenshot-1.png
          32 kB
        2. screenshot-2.png
          screenshot-2.png
          32 kB
        3. screenshot-3.png
          screenshot-3.png
          23 kB
        4. screenshot-4.png
          screenshot-4.png
          11 kB

            Unassigned Unassigned
            PacManMVC PacManMVC
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: