Search in sources :

Example 1 with IRequestProvider

use of buildcraft.api.robots.IRequestProvider in project BuildCraft by BuildCraft.

the class AIRobotDeliverRequested method delegateAIEnded.

@Override
public void delegateAIEnded(AIRobot ai) {
    if (ai instanceof AIRobotGotoStation) {
        if (!ai.success()) {
            setSuccess(false);
            terminate();
            return;
        }
        IInvSlot slot = InvUtils.getItem(robot, new ArrayStackOrListFilter(requested.getStack()));
        if (slot == null) {
            setSuccess(false);
            terminate();
            return;
        }
        IRequestProvider requester = requested.getRequester(robot.worldObj);
        if (requester == null) {
            setSuccess(false);
            terminate();
            return;
        }
        ItemStack newStack = requester.offerItem(requested.getSlot(), slot.getStackInSlot().copy());
        if (newStack == null || newStack.stackSize != slot.getStackInSlot().stackSize) {
            slot.setStackInSlot(newStack);
        }
        terminate();
    }
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) ArrayStackOrListFilter(buildcraft.lib.inventory.filter.ArrayStackOrListFilter) IRequestProvider(buildcraft.api.robots.IRequestProvider) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IRequestProvider

use of buildcraft.api.robots.IRequestProvider in project BuildCraft by BuildCraft.

the class AIRobotSearchStackRequest method getAvailableRequests.

private Collection<StackRequest> getAvailableRequests(DockingStation station) {
    List<StackRequest> result = new ArrayList<>();
    IRequestProvider provider = station.getRequestProvider();
    if (provider == null) {
        return result;
    }
    for (int i = 0; i < provider.getRequestsCount(); i++) {
        if (provider.getRequest(i) == null) {
            continue;
        }
        StackRequest req = new StackRequest(provider, i, provider.getRequest(i));
        req.setStation(station);
        if (!robot.getRegistry().isTaken(req.getResourceId(robot.worldObj))) {
            result.add(req);
        }
    }
    return result;
}
Also used : IRequestProvider(buildcraft.api.robots.IRequestProvider) ArrayList(java.util.ArrayList) StackRequest(buildcraft.robotics.StackRequest)

Aggregations

IRequestProvider (buildcraft.api.robots.IRequestProvider)2 IInvSlot (buildcraft.api.core.IInvSlot)1 ArrayStackOrListFilter (buildcraft.lib.inventory.filter.ArrayStackOrListFilter)1 StackRequest (buildcraft.robotics.StackRequest)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1