Mojira Archive
MC-87227

Switching a weapon with "low cooldown" to a weapon "high cooldown" resets cool down bar after a bit of charging

The bug

So apparently if you switch from a "short cooldown" item, such as the Hoe, to a "high or medium cool down" item, such as the Sword, both bars, crosshair and hotbar, seems to be buggy. (This does work even if you switch from the hand to a weapon).
By "buggy" i mean that the cool down bar at first seems to charge but it instantly refreshes and re-charge from the beginning. ( If you go into the game you will certainly notice it).

Code analysis

Based on 1.11.2 decompiled using MCP 9.35 rc1

It looks like the value of the field net.minecraft.entity.EntityLivingBase.ticksSinceLastSwing is reset client-side, however attributes like net.minecraft.entity.SharedMonsterAttributes.ATTACK_SPEED are set server-side. Therefor the client probably starts increasing ticksSinceLastSwing with the old attack speed and then receives the attack speed for the new item from the server which makes the recharge progress appear to jump.