mojira.dev

How to reproduce

In creative mode with cheats enabled:

  1. Summon a hopper minecart at your position by using the command provided below.

    /summon minecraft:hopper_minecart ~ ~1 ~ {NoGravity:1b}
  2. Give yourself an apple by using the command provided below.

    /give @s minecraft:apple
  3. Notice how there's an apple in your inventory and an apple inside the hopper minecart.

Expected result

The player picks up the item, and the hopper minecart does not.

Actual result

Both the player and the hopper minecart pick up the item, duplicating it.

Suggestions

  • Have the item entity determine when it can be picked up, and which entity/block entity to transfer its contents to

  • When an entity/block entity attempts to pick up an item, make a temporary copy of the item stack, attempt to delete the item entity, and give up if the item entity is already deleted

  • When any entity/block entity attempts to take an item from an item entity, make the operation atomic - do not allow any other attempts to interact with the item entity until the first attempt is complete

Unlisted video demonstrating the bug

Code analysis

The following is based on a decompiled version of Minecraft 1.12 using MCP 9.40pre-1. – @unknown

The /give command puts the item specified in the second argument of the command into the inventory of the player specified in the first argument of the command. With that, it also summons a so called "fake item" with an infinite pickup delay (32767) and an age of 5999 at the position of the player. The issue here is that net.minecraft.tileentity.TileEntityHopper and net.minecraft.entity.item.EntityMinecartHopper don't check an item for its pickup delay, the Minecart with a hopper at the position of the player's head therefore captures the fake item, which it obviously shouldn't.

I managed to fix this bug by creating a public getter for the delayBeforeCanPickup field in the net.minecraft.entity.item.EntityItem class, adding a for-loop to check if the picked up item has a pickup delay other than 32767 to the captureDroppedItems() method of net.minecraft.entity.item.EntityMinecartHopper, and adding a simple if-statement to the already existing for-loop in the captureDroppedItems() method of net.minecraft.tileentity.TileEntityHopper.

net.minecraft.entity.item.EntityMinecartHopper

public boolean captureDroppedItems()
{
	// ...
	List<EntityItem> list = this.world.<EntityItem>getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(0.25D, 0.0D, 0.25D), EntitySelectors.IS_ALIVE);
	List<EntityItem> list2 = new ArrayList<EntityItem>();
	for(EntityItem ei : list) {
		if(ei.getPickupDelay() != 32767) {
			list2.add(ei);
		}
	}
	if (!list2.isEmpty())
	{
		TileEntityHopper.putDropInInventoryAllSlots((IInventory)null, this, list2.get(0));
	}
	// ...
}

net.minecraft.tileentity.TileEntityHopper

public static boolean captureDroppedItems(IHopper hopper)
{
	// ...
	for (EntityItem entityitem : getCaptureItems(hopper.getWorld(), hopper.getXPos(), hopper.getYPos(), hopper.getZPos()))
	{
		if(entityitem.getPickupDelay() != 32767) {
			if (putDropInInventoryAllSlots((IInventory)null, hopper, entityitem))
			{
				return true;
			}
		}
	}
	// ...
}

Linked issues

Attachments

Comments 16

This doesn't need to be private as you need permissions to use this.

It isn't a problem for normal worlds, but it is a problem for mapmakers using /give.

Confirmed for 20w06a, please update the reproduce steps to use sand instead of pistons as that pushes you up a block.

Can confirm that this is still an issue in 20w51a.

Can confirm in 21w03a.

6 more comments

Can confirm in 1.17.1. Video attached.

Can confirm in 1.18.1.

Can confirm in 1.18.2. For ease and convenience of reproducing this, you can simply execute the following commands and observe how you can duplicate items using the "/give" command.

/summon minecraft:hopper_minecart ~ ~1 ~ {NoGravity:1b}
/give @s minecraft:apple

Can confirm in 1.19.

Can confirm in 1.19.2.

NickNackGus

(Unassigned)

Confirmed

Platform

Normal

Commands, Data Packs

/give, duplication, hopper_minecart

Minecraft 1.12, Minecraft 1.12.1 Pre-Release 1, Minecraft 1.12.1, Minecraft 1.13, Minecraft 1.13.1, ..., 1.20.4, 1.20.5 Pre-Release 3, 1.20.5 Pre-Release 4, 1.21, 1.21.4

Retrieved