mojira.dev
MC-100584

Dropper into minecart offset by .5 of a block in negative x and z direction

When transfering an item into a minecart chest/hopper, the places the dropper checks are offset in -X and -Z direction. In the attached image (facing north) 3 existing minecarts receive items, but if you put a minecart with chest/hopper on any empty rail, it won't get any items.

Linked issues

Attachments

Comments 4

Kenny Zhang

By looking at Minecraft's source code using Forge, I have determined the issue: Droppers, when looking for an inventory at a position, use the block's -x, -y, -z corner to search, while hoppers use the block's center. Because droppers directly use TileEntityHopper's getInventoryAtPosition method, this causes the dropper's searching location to be offset in the -x and -z direction. The fix is simple, and only requires one line to be changed:

BlockDropper.java:
...
    protected void dispense(World worldIn, BlockPos pos)
    {
        BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
        TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();

        if (tileentitydispenser != null)
        {
            int i = tileentitydispenser.getDispenseSlot();

            if (i < 0)
            {
                worldIn.playAuxSFX(1001, pos, 0);
            }
            else
            {
                ItemStack itemstack = tileentitydispenser.getStackInSlot(i);

                if (itemstack != null && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, tileentitydispenser, i, itemstack))
                {
                    EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
                    BlockPos blockpos = pos.offset(enumfacing);

// ===========================================================================================
//                  IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
                    IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX() + 0.5, (double)blockpos.getY() + 0.5, (double)blockpos.getZ() + 0.5);
// ===========================================================================================

                    ItemStack itemstack1;

                    if (iinventory == null)
                    {
                        itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);

                        if (itemstack1 != null && itemstack1.stackSize <= 0)
                        {
                            itemstack1 = null;
                        }
                    }
                    else
                    {
                        itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());

                        if (itemstack1 == null)
                        {
                            itemstack1 = itemstack.copy();

                            if (--itemstack1.stackSize <= 0)
                            {
                                itemstack1 = null;
                            }
                        }
                        else
                        {
                            itemstack1 = itemstack.copy();
                        }
                    }

                    tileentitydispenser.setInventorySlotContents(i, itemstack1);
                }
            }
        }
    }
...
tryashtar

This was fixed at some point

Kenny Zhang

After trying snapshot after snapshot, it seems like this was fixed in 17w47a

tryashtar

Great work! I've updated the ticket to reflect that 🙂

Kenny Zhang

(Unassigned)

Confirmed

Minecraft 1.9.2, Minecraft 1.10.2, Minecraft 16w40a, Minecraft 16w44a, Minecraft 1.11 Pre-Release 1, ..., Minecraft 17w15a, Minecraft 17w16b, Minecraft 17w17b, Minecraft 17w18b, Minecraft 1.12 Pre-Release 2

Minecraft 17w47a

Retrieved