Steps to reproduce the issue
Put a diamond sword and a diamond spear in your hot bar
Hold the diamond sword and wait it for full charging
Switch to the diamond spear and left click as soon as possible
Expected result
Spear can only deal damage when it is full charged, but switching items doesn’t recharge the attack cool down. This might be an old bug.
If you enchant a fire aspect on the spear, you can ignite the target when you attack following the steps. This can be found in MC-28289.
Actual result
This technique may be abused in PVP to deal full damage from a greater distance in combat
Environment
Windows 11
Minecraft 25w41a
Linked issues
Attachments
Comments 2
This is not fully a duplicate of MC-28289(also called attribute swapping). Attribute swapping is a purely server-side issue, whereas this bug causes the client to send attack packets when it shouldn’t be able to. Specifically, the issue is that the client performs the raycasting/picking logic before it updates what slot the player is hovering. See the following code snippet from Minecraft::tick:
this.pick(1.0F);
this.tutorial.onLookAt(this.level, this.hitResult);
profiler.push("gui");
this.gui.tick();
if (this.gui.screen() != null) {
this.missTime = 10000;
}
if (this.gui.overlay() == null && this.gui.screen() == null) {
profiler.popPush("Keybindings");
this.handleKeybinds();
[...]The pick() method uses the current held items attack range data component to determine what object the local player is targeting (either a block, entity or nothing) and the handleKeybinds() methods then processes the keyboard inputs of the player to update the held slot. Additionally the players attack strength ticker is also reset after the attack is already processed, so the attack goes through even though a spear normally requires a minimum charge.
If one wanted to achieve the behaviour of swapping a slot at the same time as attacking being treated as attacking with the new item with reset attack strength, one would need to make sure to do the following things in order:
1. update held slot/item if player pressed a different hotkey
2. reset the local players attack strength ticker if held item has changed and perform raytracing/call pick() method (these should be independent).
3. perform attacking/interaction logic
Duplicate of MC-28289.