mojira.dev
MC-41113

/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

  1. Put a repeating command block down with

    /clear @p torch
  2. Switch to Creative mode

    /gamemode creative
  3. Grab a stack of torches for example from your Creative inventory and put it in your hotbar

  4. 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();
		}

		//...
	}
}

Linked issues

Attachments

Comments 53

Talven81

Is this still a concern in the current Minecraft version 1.7.4 / Launcher version 1.3.8 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Deleted account

Is this still a concern in the current Minecraft version 14w11b / Launcher version 1.3.11 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Deleted account

Is this still a concern in the current Minecraft version 14w20b / Launcher version 1.3.11 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

trazlander

Just tested, confirmed as of 14w21b

marcono1234

Confirmed for 14w30c

This also happens sometimes when you press the mouse wheel to select a block

43 more comments
Charlie Gallie

For any map creators, you could use this while it lasts. It could create a false adventure mode cause you can add nbt to items and specify what type of items for this to work on, also, dropping the item just removes the item from your hotbar and doesn't actually drop them. But although it could be used like that, it is a bug and should be removed.

Charlie Gallie

Whenever you open a chest, furnace or any other objects like that, it updates and removes the torches.
https://bit.ly/2Hz9UGa

CreeperMagnet_

Just wondering, how exactly was this bug fixed? Can command blocks clear & detect items 'on the mouse' anymore, or not? Or is it a new slot or something of the like?

1Just_Vlad1

Love you Mojang! One of the most annoying bugs in mapmaking is fixed

boq

@unknownIt was always cleared on server, but client was not informed about it. So fix was to trigger update.

AgentM

boq

Confirmed

/clear, inventory-desync, item

Minecraft 13w48b, Minecraft 1.7.10, Minecraft 14w30c, Minecraft 14w32a, Minecraft 1.8-pre1, ..., Minecraft 19w02a, Minecraft 19w03c, Minecraft 19w04b, Minecraft 19w05a, Minecraft 19w06a

Minecraft 19w12a

Retrieved