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;
}
}
Aggregations