mojira.dev
MC-28289

Switching items at the same time as attacking ignores the item attributes

The bug

If you switch items in your hotbar at the same time as attacking, attributes are not applied on the item you switch to.

  • What I expected to happen
    I expected to kill a cow in one hit after switching to a diamond sword at the same time as I attacked it.

  • What actually happened
    Side effects of using the diamond sword still occurred, except not the item's damage. This means that the sword still lost durability and the fire aspect enchantment still set the cow on fire, but it did not die in one hit (cows have 10 health, the diamond sword has +9999 attack damage).

Steps to reproduce

  1. Spawn a cow

  2. Take a sword enchanted with fire aspect and with a high damage and speed and place it in a certain slot in your hotbar (I used 4, i.e. I hit the 4 key to select it)

    /give @s diamond_sword{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:1000.0,UUID:[I;1,2,3,4]},{AttributeName:"generic.attack_speed",Name:"generic.attack_speed",Amount:1000.0,UUID:[I;5,6,7,8]}],Enchantments:[{id:fire_aspect,lvl:1}]}
  3. Leave another slot with nothing, and select that slot.

  4. Left-click the cow at the exact same time you hit the 4 key (or whatever slot you chose for the sword.)

  5. The cow will be set one fire and the sword will lose durability, but the cow is not instantly dead.

Notes:

  • This works in creative and survival, but it was easier to show the sword's durability loss in survival.

  • The sword doesn't need any enchantment. It's just easier to show that you're actually using the sword when you attack if it has one.

Linked issues

Attachments

Comments 21

Confirmed.

Is this still a concern in the latest Minecraft version 14w30c? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

This is still a problem in 14w31a. I've updated the affected version(s) and added more screenshots to confirm.

Reopened, thanks.

Still a problem in 1.8

11 more comments

Can confirm in 24w44a

In addition, the melee attack charging does not reset in time

I tested and checked out the src, finally found out the solution.

The attributes of living entites only refresh when entities' mob effects change or by tick.

So we can refresh players' attributes when they change their selected item.

Please fix swapping with a mace with breach is completely unbalanced

Breach swapping it's the worst thing that can ever happened, barely needs skill and you can almost one shot a player

Leo Izen

(Unassigned)

Confirmed

(Unassigned)

attribute, hotbar, item, switch

Minecraft 1.6.2, Minecraft 1.7.4, Minecraft 14w31a, Minecraft 1.8.1-pre3, Minecraft 1.8.8, ..., 1.21, 24w44a, 1.21.3, 24w46a, 1.21.4

Retrieved