The bug
Enable spawn protection. Attempt to place a block. The block will not place, however it will be removed from your inventory. Relog, or click the empty slot and it will reappear.
With recent (1.15 snapshots) changes moving item usage to the client-side as well to get correct arm movement, this affects even more items, e.g. fire charges used to ignite camp fires.
Code analysis
Code analysis by @unknown can be found in this comment.
Related issues
is duplicated by
relates to
Comments


How do you enable spawn protection? Also, is this in survival mode?

it's only in a server's propperties, and effects non-ops, no matter what gamemode

And there has to be at least one op, see @unknown's tweet

Is this still an issue in the most recent versions (currently that is 1.12.2, or the latest 1.13 pre-release) of Minecraft?

Is this still a issue in the latest version of the game(currently 1.13.1)?
If so, please add it to the affected versions, thanks!

Affects 20w51a
Placing a candle on a cake in spawn protection will also desync (separate from MC-205212).

Confirmed for 1.17.1.
Can confirm in 1.18.1.
Can confirm in 1.18.2 and 22w15a.
Can confirm in 1.19.
Can confirm in 1.19.2.

Still happens in 1.21.1
The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.
The method
net.minecraft.network.NetHandlerPlayServer.func_184337_a(CPacketPlayerTryUseItem)
should probably synchronize the player inventory based on the returnedEnumActionResult
by the call to the methodnet.minecraft.server.management.PlayerInteractionManager.func_187251_a(EntityPlayer, World, ItemStack, EnumHand, BlockPos, EnumFacing, float, float, float)
, or if it fails because for example the spawn protection prevents placing blocks.This desync is normally only visible if the spawn protection prevents placing a block because this is only tested server-side. Placing a block behind the worldborder or above the build limit is tested client-side as well. The latter situations can create desync if the client receives changes to the worldborder too late or if the built height is lower than the default one (this creates block desync for breaking blocks as well).
But I guess @unknown knows more about this