Example usage for net.minecraftforge.fluids IFluidTank fill

List of usage examples for net.minecraftforge.fluids IFluidTank fill

Introduction

In this page you can find the example usage for net.minecraftforge.fluids IFluidTank fill.

Prototype

int fill(FluidStack resource, FluidAction action);

Source Link

Usage

From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java

/**
 * Pulls fluids from container and insert into tank
 *///from   ww w.  j  av a  2 s .  c om
protected void fillTank(final int slot, final IFluidTank inputTank) {
    final ItemStack itemStack = getStackInSlot(slot);
    if (itemStack != null) {
        if (itemStack.getItem() instanceof IFluidContainerItem) {
            IFluidContainerItem fluidContainerItem = (IFluidContainerItem) itemStack.getItem();

            FluidStack fluidStack = fluidContainerItem.getFluid(itemStack);
            if (fluidStack != null && getRecipeList().isComponent(this, fluidStack.getFluid())) {
                fluidStack = fluidContainerItem.drain(itemStack,
                        inputTank.getCapacity() - inputTank.getFluidAmount(), false);
                int amount = inputTank.fill(fluidStack, true);
                fluidContainerItem.drain(itemStack, amount, true);
                setInventorySlotContents(slot, itemStack);
            }
        } else if (FluidContainerRegistry.isFilledContainer(itemStack)) {
            FluidStack stack = FluidContainerRegistry.getFluidForFilledItem(itemStack);
            if (stack != null && getRecipeList().isComponent(this, stack.getFluid())) {
                inputTank.fill(stack, true);
                decrStackSize(slot, 1);

                ItemStack container = itemStack.getItem().getContainerItem(itemStack);
                if (container != null) {
                    if (getStackInSlot(slot) == null) {
                        setInventorySlotContents(slot, container);
                    } else {
                        //TODO add fluid container output slot
                        EntityItem item = new EntityItem(worldObj);
                        item.setPosition(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
                        item.setEntityItemStack(container);
                        worldObj.spawnEntityInWorld(item);
                    }
                }
            }
        }
    }
}

From source file:com.buuz135.industrial.proxy.block.upgrade.ConveyorExtractionUpgrade.java

License:Open Source License

@Override
public void update() {
    if (getWorld().isRemote)
        return;//from  w w w  .  j av a 2 s  .c om
    items.removeIf(entityItem -> entityItem.getItem().isEmpty() || entityItem.isDead);
    if (items.size() >= 20)
        return;
    if (getWorld().getTotalWorldTime() % (fast ? 10 : 20) == 0) {
        IItemHandler itemHandler = getHandlerCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
        if (itemHandler != null) {
            for (int i = 0; i < itemHandler.getSlots(); i++) {
                ItemStack stack = itemHandler.extractItem(i, 4, true);
                if (stack.isEmpty() || whitelist != filter.matches(stack))
                    continue;
                EntityItem item = new EntityItem(getWorld(), getPos().getX() + 0.5, getPos().getY() + 0.5,
                        getPos().getZ() + 0.5);
                item.motionX = 0;
                item.motionY = 0;
                item.motionZ = 0;
                item.setPickupDelay(40);
                item.setItem(itemHandler.extractItem(i, 4, false));
                if (getWorld().spawnEntity(item)) {
                    items.add(item);
                }
                break;
            }
        }
    }
    if (getContainer() instanceof TileEntityConveyor) {
        IFluidTank tank = ((TileEntityConveyor) getContainer()).getTank();
        IFluidHandler fluidHandler = getHandlerCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY);
        if (fluidHandler != null && fluidHandler.drain(250, false) != null
                && ((FluidTank) tank).canFillFluidType(fluidHandler.drain(250, false))
                && whitelist == filter.matches(fluidHandler.drain(250, false))) {
            FluidStack drain = fluidHandler.drain(tank.fill(fluidHandler.drain(250, false), true), true);
            if (drain != null && drain.amount > 0)
                getContainer().requestFluidSync();
        }
    }
}

From source file:com.buuz135.industrial.utils.ItemStackUtils.java

License:Open Source License

public static void fillTankFromItem(ItemStackHandler fluidItems, IFluidTank tank) {
    ItemStack stack = fluidItems.getStackInSlot(0).copy();
    if (!stack.isEmpty()) {
        if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
            IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY,
                    null);//from   w  w w .  ja v  a2s  . c om
            FluidStack fluidStack = cap.drain(1000, false);
            if (fluidStack != null && tank.fill(fluidStack, false) == 0)
                return;
            FluidActionResult result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, 1000, null,
                    false);
            if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty()
                    || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1))
                            && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result
                                    .getResult().getMaxStackSize()))) {
                result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null,
                        true);
                if (fluidItems.getStackInSlot(1).isEmpty()) {
                    fluidItems.setStackInSlot(1, result.getResult());
                } else {
                    fluidItems.getStackInSlot(1).grow(1);
                }
                fluidItems.getStackInSlot(0).shrink(1);
            }
        }
    }
}