Search in sources :

Example 1 with FluidStackWrapper

use of pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper in project PneumaticCraft by MineMaarten.

the class LogisticsManager method tryProvide.

//curAI = new DroneAILiquidImport(drone, new FakeWidgetLogistics(provider.getPos(), providingStack));
// transportingFluid = new FluidStackWrapper(providingStack);
private void tryProvide(SemiBlockLogistics provider, SemiBlockLogistics requester, PriorityQueue<LogisticsTask> tasks) {
    IInventory providingInventory = IOHelper.getInventoryForTE(provider.getTileEntity());
    if (providingInventory != null) {
        if (requester instanceof IProvidingInventoryListener)
            ((IProvidingInventoryListener) requester).notify(provider.getTileEntity());
        for (int i = 0; i < providingInventory.getSizeInventory(); i++) {
            ItemStack providingStack = providingInventory.getStackInSlot(i);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && IOHelper.canExtractItemFromInventory(providingInventory, providingStack, i, 0)) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    ItemStack stack = providingStack.copy();
                    stack.stackSize = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, stack));
                }
            }
        }
    }
    if (provider.getTileEntity() instanceof IFluidHandler) {
        IFluidHandler providingTank = (IFluidHandler) provider.getTileEntity();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            FluidStack providingStack = providingTank.drain(d, 16000, false);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && providingTank.canDrain(d, providingStack.getFluid())) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    FluidStack stack = providingStack.copy();
                    stack.amount = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(stack)));
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificProvider(pneumaticCraft.common.semiblock.ISpecificProvider) IProvidingInventoryListener(pneumaticCraft.common.semiblock.IProvidingInventoryListener) FluidStackWrapper(pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 2 with FluidStackWrapper

use of pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper in project PneumaticCraft by MineMaarten.

the class LogisticsManager method getTasks.

public PriorityQueue<LogisticsTask> getTasks(Object holdingStack) {
    ItemStack item = holdingStack instanceof ItemStack ? (ItemStack) holdingStack : null;
    FluidStack fluid = holdingStack instanceof FluidStack ? (FluidStack) holdingStack : null;
    PriorityQueue<LogisticsTask> tasks = new PriorityQueue<LogisticsTask>();
    for (int priority = logistics.length - 1; priority >= 0; priority--) {
        for (SemiBlockLogistics requester : logistics[priority]) {
            for (int i = 0; i < priority; i++) {
                for (SemiBlockLogistics provider : logistics[i]) {
                    if (provider.shouldProvideTo(priority)) {
                        if (item != null) {
                            int requestedAmount = getRequestedAmount(requester, item);
                            if (requestedAmount > 0) {
                                ItemStack stack = item.copy();
                                stack.stackSize = requestedAmount;
                                tasks.add(new LogisticsTask(provider, requester, stack));
                                return tasks;
                            }
                        } else if (fluid != null) {
                            int requestedAmount = getRequestedAmount(requester, fluid);
                            if (requestedAmount > 0) {
                                fluid = fluid.copy();
                                fluid.amount = requestedAmount;
                                tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(fluid)));
                                return tasks;
                            }
                        } else {
                            tryProvide(provider, requester, tasks);
                        }
                    }
                }
            }
        }
    }
    return tasks;
}
Also used : SemiBlockLogistics(pneumaticCraft.common.semiblock.SemiBlockLogistics) FluidStack(net.minecraftforge.fluids.FluidStack) FluidStackWrapper(pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper) ItemStack(net.minecraft.item.ItemStack) PriorityQueue(java.util.PriorityQueue)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 FluidStackWrapper (pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper)2 PriorityQueue (java.util.PriorityQueue)1 IInventory (net.minecraft.inventory.IInventory)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1 IProvidingInventoryListener (pneumaticCraft.common.semiblock.IProvidingInventoryListener)1 ISpecificProvider (pneumaticCraft.common.semiblock.ISpecificProvider)1 SemiBlockLogistics (pneumaticCraft.common.semiblock.SemiBlockLogistics)1