/clear turns items held by mouse into ghost items
The bug
Using /clear while an inventory is open and you are holding an item with your mouse causes an inventory desync and turns this item into a "ghost" item. You can place it in your inventory, but using it will fail in Creative mode and in Adventure and Survival mode additionally removes the item.
Expected would be that /clear successfully clears the held item client-side as well.
How to reproduce
- Put a repeating command block down with
/clear @p torch
- Switch to Creative mode
/gamemode creative
- Grab a stack of torches for example from your Creative inventory and put it in your hotbar
- Try placing down torches
→
The torches are not placed
Code analysis (outdated for 1.13+)
The following is based on a decompiled version of Minecraft 1.8 using MCP. All method and class names are the ones used in the decompiled version.
The reason for this is a piece of code in the public void processCommand(ICommandSender sender, String[] args) method of the net.minecraft.command.CommandClearInventory class that only updates the held item once the /clear command was used, if the player is not in Creative mode:
public void processCommand(ICommandSender sender, String[] args) throws CommandException { EntityPlayerMP var3 = args.length == 0 ? getCommandSenderAsPlayer(sender) : getPlayer(sender, args[0]); // ... if (args.length >= 2 && var4 == null) { throw new CommandException("commands.clear.failure", new Object[] {var3.getName()}); } else { int var8 = var3.inventory.func_174925_a(var4, var5, var6, var7); var3.inventoryContainer.detectAndSendChanges(); //This prevents the update if (!var3.capabilities.isCreativeMode) { var3.updateHeldItem(); } //... } }
2013-11-28, 09:20 PM
2020-06-05, 06:42 PM
2019-03-20, 12:36 PM
80
49
/clear, inventory-desync, item
Minecraft 13w48b - Minecraft 19w06a
Minecraft 13w48b, Minecraft 1.7.10, Minecraft 14w30c, Minecraft 14w32a, Minecraft 1.8-pre1, Minecraft 1.8-pre2, Minecraft 1.8, Minecraft 1.8.2-pre6, Minecraft 15w34c, Minecraft 15w44b, Minecraft 15w45a, Minecraft 1.8.9, Minecraft 16w04a, Minecraft 16w05b, Minecraft 1.9 Pre-Release 1, Minecraft 1.9 Pre-Release 2, Minecraft 1.9, Minecraft 1.9.2, Minecraft 1.10, Minecraft 1.10.2, Minecraft 16w32a, Minecraft 16w32b, Minecraft 16w33a, Minecraft 16w36a, Minecraft 16w39b, Minecraft 16w39c, Minecraft 16w42a, Minecraft 1.11 Pre-Release 1, Minecraft 1.11.2, Minecraft 17w17b, Minecraft 1.12 Pre-Release 2, Minecraft 1.12, Minecraft 1.12.2, Minecraft 18w05a, Minecraft 18w06a, Minecraft 18w10c, Minecraft 18w15a, Minecraft 18w19a, Minecraft 18w21b, Minecraft 18w22c, Minecraft 1.13-pre1, Minecraft 1.13-pre2, Minecraft 1.13-pre3, Minecraft 1.13-pre4, Minecraft 1.13-pre5, Minecraft 1.13-pre6, Minecraft 1.13-pre8, Minecraft 1.13, Minecraft 18w30b, Minecraft 18w31a, Minecraft 1.13.1-pre1, Minecraft 1.13.1-pre2, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w43b, Minecraft 18w43c, Minecraft 18w44a, Minecraft 18w45a, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 18w50a, Minecraft 19w02a, Minecraft 19w03c, Minecraft 19w04b, Minecraft 19w05a, Minecraft 19w06a