Search in sources :

Example 1 with DroneAIBlockCondition

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;
        }
    };
}
Also used : IInventory(net.minecraft.inventory.IInventory) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) ChunkPosition(net.minecraft.world.ChunkPosition) ItemStack(net.minecraft.item.ItemStack)

Example 2 with DroneAIBlockCondition

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();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 3 with DroneAIBlockCondition

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;
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 4 with DroneAIBlockCondition

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();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyProvider(cofh.api.energy.IEnergyProvider) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) ICondition(pneumaticCraft.common.progwidgets.ICondition)

Aggregations

ChunkPosition (net.minecraft.world.ChunkPosition)4 DroneAIBlockCondition (pneumaticCraft.common.ai.DroneAIBlockCondition)4 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 IEnergyProvider (cofh.api.energy.IEnergyProvider)1 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)1 ArrayList (java.util.ArrayList)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1 IAirHandler (pneumaticCraft.api.tileentity.IAirHandler)1 IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)1 ICondition (pneumaticCraft.common.progwidgets.ICondition)1