Java 类net.minecraft.tileentity.IHopper 实例源码

项目:CustomWorldGen    文件:VanillaInventoryCodeHooks.java   
public static Boolean extractHook(IHopper dest)
{
    TileEntity tileEntity = dest.getWorld().getTileEntity(new BlockPos(dest.getXPos(), dest.getYPos() + 1, dest.getZPos()));

    if (tileEntity == null || !tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN))
        return null;

    IItemHandler handler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);

    for (int i = 0; i < handler.getSlots(); i++)
    {
        ItemStack extractItem = handler.extractItem(i, 1, true);
        if (extractItem != null)
        {
            for (int j = 0; j < dest.getSizeInventory(); j++)
            {
                ItemStack destStack = dest.getStackInSlot(j);
                if (dest.isItemValidForSlot(j, extractItem) && (destStack == null || destStack.stackSize < destStack.getMaxStackSize() && destStack.stackSize < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack)))
                {
                    extractItem = handler.extractItem(i, 1, false);
                    if (destStack == null)
                        dest.setInventorySlotContents(j, extractItem);
                    else
                    {
                        destStack.stackSize++;
                        dest.setInventorySlotContents(j, destStack);
                    }
                    dest.markDirty();
                    return true;
                }
            }
        }
    }

    return false;
}
项目:CustomWorldGen    文件:VanillaInventoryCodeHooks.java   
public static boolean insertHook(IHopper hopper, EnumFacing facing)
{
    TileEntity tileEntity = hopper.getWorld().getTileEntity(
            new BlockPos(hopper.getXPos(), hopper.getYPos(), hopper.getZPos()).offset(facing));

    if (tileEntity == null)
        return false;
    if (!tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()))
        return false;

    IItemHandler handler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());

    for (int i = 0; i < hopper.getSizeInventory(); i++)
    {
        ItemStack stackInSlot = hopper.getStackInSlot(i);
        if (stackInSlot != null)
        {
            ItemStack insert = stackInSlot.copy();
            insert.stackSize = 1;
            ItemStack newStack = ItemHandlerHelper.insertItem(handler, insert, true);
            if (newStack == null || newStack.stackSize == 0)
            {
                ItemHandlerHelper.insertItem(handler, hopper.decrStackSize(i, 1), false);
                hopper.markDirty();
                return true;
            }
        }
    }

    return true;
}
项目:NeptuneMod    文件:MixinTileEntityHopper.java   
@Override
public Inventory getInputInventory() {
    return (Inventory) TileEntityHopper.getHopperInventory((IHopper) this);
}