mojira.dev
MC-124099

Hoppers randomly select minecarts

The bug

Hoppers do not properly iterate through chest-minecarts or hopper-minecarts when trying to transfer items into or out of them. Instead, they select a random minecart each tick. Due to this, item transfer takes longer than expected.

How to reproduce

Place a hopper with a rail on top. Place multiple chest minecarts on the rail, a dozen or so. Place items in a single minecart. Notice how they flow much slower than the typical 2.5 items/s.

Code analysis

The following is from version 1.12 MCP 940, in net.minecraft.tileEntity.TileEntityHopper, in the method getInventoryAtPosition:

if (iinventory == null)
{
    List<Entity> list = worldIn.getEntitiesInAABBexcluding((Entity)null, new AxisAlignedBB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), EntitySelectors.HAS_INVENTORY);
    if (!list.isEmpty())
    {
        iinventory = (IInventory)list.get(worldIn.rand.nextInt(list.size()));
    }
}

The hopper randomly selects one of the inventories from the list, causing the bug. A fix would be to select the first non-full inventory for pushing items, and the first non-empty inventory for sucking items.

Linked issues

Attachments

Comments 5

Confirmed for 1.13.1.

Confirmed for 1.14.4 as well.

confirmed for 1.19.2

Confirmed in 1.19.3.

 

I'm not sure how to define "first" in your solution, but at the very least it could select a random non-empty when pulling and a random non-full when pushing. Currently if you stack tons of hopper minecarts on top of a hopper, by chance it can simply stop pulling items for a second even if one of the carts has items.

Confirmed for versions up to 23w12a.

Added video for 23w12a.

Mathieu Bolduc

(Unassigned)

Confirmed

Redstone

chest_minecart, hopper, hopper_minecart

Minecraft 1.12.2, Minecraft 18w01a, Minecraft 1.13.1, 1.14.4, 1.18.2, ..., 1.19.2, 1.19.3, 1.19.4, 23w12a, 24w20a

Retrieved