use of pneumaticCraft.common.ai.DroneAIBlockCondition in project PneumaticCraft by MineMaarten.
the class ProgWidgetItemInventoryCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
int count = 0;
Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
for (Integer i : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
count += stack.stackSize;
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
}
return false;
}
};
}
use of pneumaticCraft.common.ai.DroneAIBlockCondition in project PneumaticCraft by MineMaarten.
the class ProgWidgetLiquidInventoryCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
int count = 0;
if (te instanceof IFluidHandler) {
List<FluidStack> visitedStacks = new ArrayList<FluidStack>();
IFluidHandler inv = (IFluidHandler) te;
for (int i = 0; i < 6; i++) {
if (((ISidedWidget) widget).getSides()[i]) {
FluidTankInfo[] info = inv.getTankInfo(ForgeDirection.getOrientation(i));
if (info != null) {
for (FluidTankInfo inf : info) {
if (inf.fluid != null && !visitedStacks.contains(visitedStacks) && ProgWidgetLiquidFilter.isLiquidValid(inf.fluid.getFluid(), widget, 1)) {
visitedStacks.add(inf.fluid);
count += inf.fluid.amount;
}
}
}
}
}
} else {
Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
count += 1000;
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
}
};
}
use of pneumaticCraft.common.ai.DroneAIBlockCondition in project PneumaticCraft by MineMaarten.
the class ProgWidgetPressureCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if (te instanceof IPneumaticMachine) {
IAirHandler airHandler = ((IPneumaticMachine) te).getAirHandler();
float pressure = Float.MIN_VALUE;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
pressure = Math.max(airHandler.getPressure(d), pressure);
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? pressure == ((ICondition) widget).getRequiredCount() : pressure >= ((ICondition) widget).getRequiredCount();
}
return false;
}
};
}
use of pneumaticCraft.common.ai.DroneAIBlockCondition in project PneumaticCraft by MineMaarten.
the class ProgWidgetRFCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
int energy = 0;
if (te instanceof IEnergyReceiver) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyReceiver) te).getEnergyStored(d), energy);
}
}
}
if (te instanceof IEnergyProvider) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyProvider) te).getEnergyStored(d), energy);
}
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? energy == ((ICondition) widget).getRequiredCount() : energy >= ((ICondition) widget).getRequiredCount();
}
};
}
Aggregations