Search in sources :

Example 16 with FluidStack

use of net.minecraftforge.fluids.FluidStack 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 17 with FluidStack

use of net.minecraftforge.fluids.FluidStack 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)

Example 18 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.

the class LogisticsManager method getRequestedAmount.

public static int getRequestedAmount(SemiBlockLogistics requester, FluidStack providingStack) {
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.amount;
    if (requestedAmount == 0)
        return 0;
    providingStack = providingStack.copy();
    providingStack.amount = requestedAmount;
    FluidStack remainder = providingStack.copy();
    remainder.amount += requester.getIncomingFluid(remainder.getFluid());
    TileEntity te = requester.getTileEntity();
    if (te instanceof IFluidHandler) {
        IFluidHandler fluidHandler = (IFluidHandler) te;
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            int fluidFilled = fluidHandler.fill(d, remainder, false);
            if (fluidFilled > 0) {
                remainder.amount -= fluidFilled;
                break;
            }
        }
    }
    providingStack.amount -= remainder.amount;
    if (providingStack.amount <= 0)
        return 0;
    return providingStack.amount;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificRequester(pneumaticCraft.common.semiblock.ISpecificRequester) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 19 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.

the class DroneAILiquidImport method emptyTank.

private boolean emptyTank(ChunkPosition pos, boolean simulate) {
    if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if (te instanceof IFluidHandler) {
            IFluidHandler tank = (IFluidHandler) te;
            for (int i = 0; i < 6; i++) {
                if (((ISidedWidget) widget).getSides()[i]) {
                    FluidStack importedFluid = tank.drain(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false);
                    if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) {
                        int filledAmount = drone.getTank().fill(importedFluid, false);
                        if (filledAmount > 0) {
                            if (((ICountWidget) widget).useCount())
                                filledAmount = Math.min(filledAmount, getRemainingCount());
                            if (!simulate) {
                                decreaseCount(drone.getTank().fill(tank.drain(ForgeDirection.getOrientation(i), filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
            }
            drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
        } else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
            if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                if (!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.getWorld().setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                }
                return true;
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILiquidFiltered(pneumaticCraft.common.progwidgets.ILiquidFiltered) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 20 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.

the class DroneAILogistics method doLogistics.

private boolean doLogistics() {
    ItemStack item = drone.getInventory().getStackInSlot(0);
    FluidStack fluid = drone.getTank().getFluid();
    PriorityQueue<LogisticsTask> tasks = manager.getTasks(item != null ? item : fluid);
    if (tasks.size() > 0) {
        curTask = tasks.poll();
        return execute(curTask);
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) LogisticsTask(pneumaticCraft.common.ai.LogisticsManager.LogisticsTask) ItemStack(net.minecraft.item.ItemStack)

Aggregations

FluidStack (net.minecraftforge.fluids.FluidStack)188 ItemStack (net.minecraft.item.ItemStack)63 TileEntity (net.minecraft.tileentity.TileEntity)30 Fluid (net.minecraftforge.fluids.Fluid)28 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)25 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)19 ArrayList (java.util.ArrayList)18 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)16 Block (net.minecraft.block.Block)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)10 Item (net.minecraft.item.Item)9 BlockPos (net.minecraft.util.math.BlockPos)9 HashMap (java.util.HashMap)6 FluidIdentifier (logisticspipes.utils.FluidIdentifier)6 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)5 IBlockState (net.minecraft.block.state.IBlockState)5 EnumFacing (net.minecraft.util.EnumFacing)5