Search in sources :

Example 1 with ILiquidFiltered

use of me.desht.pneumaticcraft.common.progwidgets.ILiquidFiltered in project pnc-repressurized by TeamPneumatic.

the class DroneAILiquidImport method emptyTank.

private boolean emptyTank(BlockPos pos, boolean simulate) {
    if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.world().getTileEntity(pos);
        if (te != null) {
            for (int i = 0; i < 6; i++) {
                if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i))) {
                    IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i));
                    FluidStack importedFluid = handler.drain(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(handler.drain(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.world().getBlockState(pos).getBlock());
            if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.world(), pos)) {
                if (!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.world().setBlockToAir(pos);
                }
                return true;
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedWidget(me.desht.pneumaticcraft.common.progwidgets.ISidedWidget) ILiquidFiltered(me.desht.pneumaticcraft.common.progwidgets.ILiquidFiltered) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ICountWidget(me.desht.pneumaticcraft.common.progwidgets.ICountWidget) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

ICountWidget (me.desht.pneumaticcraft.common.progwidgets.ICountWidget)1 ILiquidFiltered (me.desht.pneumaticcraft.common.progwidgets.ILiquidFiltered)1 ISidedWidget (me.desht.pneumaticcraft.common.progwidgets.ISidedWidget)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1