Search in sources :

Example 1 with ILiquidExport

use of pneumaticCraft.common.progwidgets.ILiquidExport in project PneumaticCraft by MineMaarten.

the class DroneAILiquidExport method fillTank.

private boolean fillTank(ChunkPosition pos, boolean simulate) {
    if (drone.getTank().getFluidAmount() == 0) {
        drone.addDebugEntry("gui.progWidget.liquidExport.debug.emptyDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if (te instanceof IFluidHandler) {
            IFluidHandler tank = (IFluidHandler) te;
            FluidStack exportedFluid = drone.getTank().drain(Integer.MAX_VALUE, false);
            if (exportedFluid != null && ((ILiquidFiltered) widget).isFluidValid(exportedFluid.getFluid())) {
                for (int i = 0; i < 6; i++) {
                    if (((ISidedWidget) widget).getSides()[i]) {
                        int filledAmount = tank.fill(ForgeDirection.getOrientation(i), exportedFluid, false);
                        if (filledAmount > 0) {
                            if (((ICountWidget) widget).useCount())
                                filledAmount = Math.min(filledAmount, getRemainingCount());
                            if (!simulate) {
                                decreaseCount(tank.fill(ForgeDirection.getOrientation(i), drone.getTank().drain(filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
                drone.addDebugEntry("gui.progWidget.liquidExport.debug.filledToMax", pos);
            } else {
                drone.addDebugEntry("gui.progWidget.liquidExport.debug.noValidFluid");
            }
        } else if (((ILiquidExport) widget).isPlacingFluidBlocks() && (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000)) {
            Block fluidBlock = drone.getTank().getFluid().getFluid().getBlock();
            if (drone.getTank().getFluidAmount() >= 1000 && fluidBlock != null && drone.getWorld().isAirBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                if (!simulate) {
                    decreaseCount(1000);
                    drone.getTank().drain(1000, true);
                    drone.getWorld().setBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, fluidBlock);
                }
                return true;
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ILiquidExport(pneumaticCraft.common.progwidgets.ILiquidExport) Block(net.minecraft.block.Block) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

Block (net.minecraft.block.Block)1 TileEntity (net.minecraft.tileentity.TileEntity)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1 ICountWidget (pneumaticCraft.common.progwidgets.ICountWidget)1 ILiquidExport (pneumaticCraft.common.progwidgets.ILiquidExport)1