Search in sources :

Example 1 with StatementParameterItemStack

use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.

the class ActionRobotFilterTool method getGateFilterStacks.

public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
    ArrayList<ItemStack> result = new ArrayList<>();
    for (StatementSlot slot : station.getActiveActions()) {
        if (slot.statement instanceof ActionRobotFilterTool) {
            for (IStatementParameter p : slot.parameters) {
                if (p != null && p instanceof StatementParameterItemStack) {
                    StatementParameterItemStack param = (StatementParameterItemStack) p;
                    ItemStack stack = param.getItemStack();
                    if (stack != null) {
                        result.add(stack);
                    }
                }
            }
        }
    }
    return result;
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) ArrayList(java.util.ArrayList) IStatementParameter(buildcraft.api.statements.IStatementParameter) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with StatementParameterItemStack

use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.

the class ActionRobotGotoStation method actionActivate.

@Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
    IRobotRegistry registry = RobotManager.registryProvider.getRegistry(container.getTile().getWorld());
    List<DockingStation> stations = RobotUtils.getStations(container.getTile());
    for (DockingStation station : stations) {
        if (station.robotTaking() != null) {
            EntityRobot robot = (EntityRobot) station.robotTaking();
            AIRobot ai = robot.getOverridingAI();
            if (ai != null) {
                continue;
            }
            DockingStation newStation = station;
            if (parameters[0] != null) {
                newStation = getStation((StatementParameterItemStack) parameters[0], registry);
            }
            if (newStation != null) {
                robot.overrideAI(new AIRobotGoAndLinkToDock(robot, newStation));
            }
        }
    }
}
Also used : AIRobotGoAndLinkToDock(buildcraft.robotics.ai.AIRobotGoAndLinkToDock) DockingStation(buildcraft.api.robots.DockingStation) EntityRobot(buildcraft.robotics.EntityRobot) IRobotRegistry(buildcraft.api.robots.IRobotRegistry) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) AIRobot(buildcraft.api.robots.AIRobot)

Example 3 with StatementParameterItemStack

use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.

the class ActionRobotGotoStation method getStation.

private DockingStation getStation(StatementParameterItemStack stackParam, IRobotRegistry registry) {
    ItemStack item = stackParam.getItemStack();
    if (item != null && item.getItem() instanceof IMapLocation) {
        IMapLocation map = (IMapLocation) item.getItem();
        BlockPos index = map.getPoint(item);
        if (index != null) {
            EnumFacing side = map.getPointSide(item);
            DockingStation paramStation = registry.getStation(index, side);
            if (paramStation != null) {
                return paramStation;
            }
        }
    }
    return null;
}
Also used : DockingStation(buildcraft.api.robots.DockingStation) EnumFacing(net.minecraft.util.EnumFacing) IMapLocation(buildcraft.api.items.IMapLocation) BlockPos(net.minecraft.util.math.BlockPos) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with StatementParameterItemStack

use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.

the class TriggerInventoryLevel method isTriggerActive.

@Override
public boolean isTriggerActive(TileEntity tile, EnumFacing side, IStatementContainer container, IStatementParameter[] parameters) {
    IItemHandler itemHandler = tile.getCapability(CapUtil.CAP_ITEMS, side.getOpposite());
    if (itemHandler == null) {
        return false;
    }
    IItemHandlerFiltered filters = ObjectUtilBC.castOrNull(itemHandler, IItemHandlerFiltered.class);
    StatementParameterItemStack param = getParam(0, parameters, new StatementParameterItemStack());
    ItemStack searchStack = param.getItemStack();
    int itemSpace = 0;
    int foundItems = 0;
    for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
        ItemStack stackInSlot = itemHandler.getStackInSlot(slot);
        if (stackInSlot.isEmpty()) {
            if (searchStack.isEmpty()) {
                itemSpace += itemHandler.getSlotLimit(slot);
            } else {
                if (searchStack.getItem() instanceof IList) {
                    // Unfortunately lists are too generic to work properly
                    // without a simple filtered inventory.
                    ItemStack filter = filters == null ? ItemStack.EMPTY : filters.getFilter(slot);
                    if (StackUtil.matchesStackOrList(searchStack, filter)) {
                        itemSpace += Math.min(filter.getMaxStackSize(), itemHandler.getSlotLimit(slot));
                    }
                } else {
                    ItemStack stack = searchStack.copy();
                    int count = Math.min(itemHandler.getSlotLimit(slot), searchStack.getMaxStackSize());
                    stack.setCount(count);
                    ItemStack leftOver = itemHandler.insertItem(slot, stack, true);
                    if (leftOver.isEmpty()) {
                        itemSpace += count;
                    } else {
                        itemSpace += count - leftOver.getCount();
                    }
                }
            }
        } else {
            if (searchStack.isEmpty() || StackUtil.matchesStackOrList(searchStack, stackInSlot)) {
                itemSpace += Math.min(stackInSlot.getMaxStackSize(), itemHandler.getSlotLimit(slot));
                foundItems += stackInSlot.getCount();
            }
        }
    }
    if (itemSpace > 0) {
        float percentage = foundItems / (float) itemSpace;
        return percentage < type.level;
    }
    return false;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IItemHandlerFiltered(buildcraft.api.inventory.IItemHandlerFiltered) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack) IList(buildcraft.api.items.IList)

Example 5 with StatementParameterItemStack

use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.

the class ActionRobotFilter method getGateFilterStacks.

public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
    ArrayList<ItemStack> result = new ArrayList<>();
    for (StatementSlot slot : station.getActiveActions()) {
        if (slot.statement instanceof ActionRobotFilter) {
            for (IStatementParameter p : slot.parameters) {
                if (p != null && p instanceof StatementParameterItemStack) {
                    StatementParameterItemStack param = (StatementParameterItemStack) p;
                    ItemStack stack = param.getItemStack();
                    if (stack != null) {
                        result.add(stack);
                    }
                }
            }
        }
    }
    return result;
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) ArrayList(java.util.ArrayList) IStatementParameter(buildcraft.api.statements.IStatementParameter) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

StatementParameterItemStack (buildcraft.api.statements.StatementParameterItemStack)6 ItemStack (net.minecraft.item.ItemStack)5 IStatementParameter (buildcraft.api.statements.IStatementParameter)3 StatementSlot (buildcraft.api.statements.StatementSlot)3 DockingStation (buildcraft.api.robots.DockingStation)2 ArrayList (java.util.ArrayList)2 IItemHandlerFiltered (buildcraft.api.inventory.IItemHandlerFiltered)1 IList (buildcraft.api.items.IList)1 IMapLocation (buildcraft.api.items.IMapLocation)1 AIRobot (buildcraft.api.robots.AIRobot)1 IRobotRegistry (buildcraft.api.robots.IRobotRegistry)1 EntityRobot (buildcraft.robotics.EntityRobot)1 AIRobotGoAndLinkToDock (buildcraft.robotics.ai.AIRobotGoAndLinkToDock)1 ActionRobotFilter (buildcraft.robotics.statements.ActionRobotFilter)1 ItemBlock (net.minecraft.item.ItemBlock)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 IItemHandler (net.minecraftforge.items.IItemHandler)1