mojira.dev
MC-73710

Holding items enchanted with thorns in your hand works as if you were wearing them

The Bug:

Holding items enchanted with thorns in your hand works as if you were wearing them.

Steps to Reproduce:

  1. Switch into survival mode and hold an item enchanted with thorns by using the command provided below.

    /item replace entity @s weapon.mainhand with minecraft:golden_helmet{Enchantments:[{id:"minecraft:thorns",lvl:3}]}
  2. Summon an entity that will attack you, for example, a husk.

  3. Let it damage you a couple of times.

  4. Take note as to whether or not holding items enchanted with thorns in your hand works as if you were wearing them.

Observed Behavior:

Holding items enchanted with thorns in your hand works as if you were wearing them.

Expected Behavior:

Holding items enchanted with thorns in your hand would not work as if you were wearing them.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 19

Samuel Klumpers

This works for all types of gear and items.
If you get a hopper and give it a low movement speed tag (or something like that, I forgot what it exactly was) you can use them as spyglasses πŸ™‚.
I think this is intended.

Confirmed for

  • 16w15b

Thorns is defined as enchantment for armor, but not for held items. This report is very likely valid

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta.

The reason why this happens is because the methods net.minecraft.enchantment.EnchantmentHelper.applyThornEnchantments(EntityLivingBase, Entity) and net.minecraft.enchantment.EnchantmentHelper.applyArthropodEnchantments(EntityLivingBase, Entity) call both the method net.minecraft.entity.Entity.func_184209_aF() which gets for players all items in armor and hand slots. This behaviour might be intended partwise but the developers should definitely have a look at it again because calling this method is probably not what they want considering that after this for players the enchantment influence is calculated again only for the mainhand (which was included already before).

The problem that the item enchanted with the Thorns enchantment is not damaged is because the method net.minecraft.enchantment.EnchantmentThorns.onUserHurt(EntityLivingBase, Entity, int) tries to get the item which has the Thorns enchantment from all slots which can have this enchantment. As hand items cannot have this enchantment the item is null and no item is damaged.

Confirmed for 1.13.1-pre1

Confirmed for 1.13.1

9 more comments

Can confirm in 21w16a.

Can confirm in 21w17a.

Can confirm in 1.17.1.

Can confirm this behavior in 21w41a. Here are some extra details regarding this problem.

The Bug:

Holding items enchanted with thorns in your hand works as if you were wearing them.

Steps to Reproduce:

  • Switch into survival mode and hold an item enchanted with thorns.

/item replace entity @s weapon.mainhand with minecraft:golden_helmet{Enchantments:[{id:"thorns",lvl:3}]}
  • Summon an entity that will attack you, for example, a husk.

  • Let it damage you a couple of times.

  • Take note as to whether or not holding items enchanted with thorns in your hand works as if you were wearing them.

Observed Behavior:

Holding items enchanted with thorns in your hand works as if you were wearing them.

Expected Behavior:

Holding items enchanted with thorns in your hand would not work as if you were wearing them.

How come this was this marked as resolved? I can confirm it’s still happening in 1.21.5.

I just ran into this while working on a mod and at first I thought it was my fault, but it turns out that this is (still) just the current vanilla behaviour.

Colton Bradburn

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Items

thorns

Minecraft 1.8, Minecraft 16w15b, Minecraft 1.10.2, Minecraft 16w43a, Minecraft 1.13, ..., 22w43a, 1.19.3, 1.19.4, 1.20, 1.20.1

Retrieved