mojira.dev
MC-99075

Cancelled block place (spawn protection) causes inventory desync

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.

Linked issues

Comments 13

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 returned EnumActionResult by the call to the method net.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

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?

3 more comments

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

md_5

(Unassigned)

Confirmed

Platform

Important

Networking

desync, spawn-protection

Minecraft 1.9, Minecraft 1.10.2, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w48a, ..., 1.19.4, 1.20.1, 1.21, 1.21.4, 1.21.7

Retrieved