use of pneumaticCraft.common.progwidgets.ICountWidget 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;
}
}
use of pneumaticCraft.common.progwidgets.ICountWidget in project PneumaticCraft by MineMaarten.
the class DroneEntityAIInventoryExport method export.
private boolean export(ChunkPosition pos, boolean simulate) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack droneStack = drone.getInventory().getStackInSlot(i);
if (droneStack != null) {
if (widget.isItemValidForFilters(droneStack)) {
for (int side = 0; side < 6; side++) {
droneStack = drone.getInventory().getStackInSlot(i);
if (((ISidedWidget) widget).getSides()[side] && droneStack != null) {
droneStack = droneStack.copy();
int oldCount = droneStack.stackSize;
if (((ICountWidget) widget).useCount())
droneStack.stackSize = Math.min(droneStack.stackSize, getRemainingCount());
ItemStack remainder = IOHelper.insert(inv, droneStack.copy(), side, simulate);
int stackSize = drone.getInventory().getStackInSlot(i).stackSize - (remainder == null ? droneStack.stackSize : droneStack.stackSize - remainder.stackSize);
droneStack.stackSize = stackSize;
int exportedItems = oldCount - stackSize;
if (!simulate) {
drone.getInventory().setInventorySlotContents(i, stackSize > 0 ? droneStack : null);
decreaseCount(exportedItems);
}
if (simulate && exportedItems > 0)
return true;
//doing it for every side for no side sensitive inventories would be a waste.
if (!(inv instanceof ISidedInventory))
break;
}
}
if (droneStack == null && !simulate)
drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
else
drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
} else {
drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
}
}
}
} else {
drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
}
return false;
}
use of pneumaticCraft.common.progwidgets.ICountWidget in project PneumaticCraft by MineMaarten.
the class DroneEntityAIInventoryImport method importItems.
private boolean importItems(ChunkPosition pos, boolean simulate) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
for (Integer i : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && IOHelper.canExtractItemFromInventory(inv, stack, i, ((ISidedWidget) widget).getSides())) {
if (widget.isItemValidForFilters(stack)) {
ItemStack importedStack = stack.copy();
if (((ICountWidget) widget).useCount())
importedStack.stackSize = Math.min(importedStack.stackSize, getRemainingCount());
ItemStack remainder = IOHelper.insert(drone.getInventory(), importedStack.copy(), 0, simulate);
int removedItems = importedStack.stackSize - (remainder != null ? remainder.stackSize : 0);
if (!simulate) {
ItemStack newStack = stack.copy();
newStack.stackSize = stack.stackSize - removedItems;
inv.setInventorySlotContents(i, newStack.stackSize > 0 ? newStack : null);
decreaseCount(removedItems);
drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
if (((ICountWidget) widget).useCount() && getRemainingCount() <= 0)
return false;
} else if (removedItems > 0) {
return true;
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.filledToMax", pos);
}
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.stackdoesntPassFilter", pos);
}
}
}
} else {
drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
}
return false;
}
use of pneumaticCraft.common.progwidgets.ICountWidget 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