Search in sources :

Example 1 with EntityAIBase

use of net.minecraft.entity.ai.EntityAIBase in project PneumaticCraft by MineMaarten.

the class DroneAIManager method removeTask.

/**
     * removes the indicated task from the entity's AI tasks.
     */
public void removeTask(EntityAIBase par1EntityAIBase) {
    Iterator iterator = taskEntries.iterator();
    while (iterator.hasNext()) {
        EntityAITaskEntry entityaitaskentry = (EntityAITaskEntry) iterator.next();
        EntityAIBase entityaibase1 = entityaitaskentry.action;
        if (entityaibase1 == par1EntityAIBase) {
            if (executingTaskEntries.contains(entityaitaskentry)) {
                entityaibase1.resetTask();
                executingTaskEntries.remove(entityaitaskentry);
            }
            iterator.remove();
        }
    }
}
Also used : EntityAIBase(net.minecraft.entity.ai.EntityAIBase) Iterator(java.util.Iterator)

Example 2 with EntityAIBase

use of net.minecraft.entity.ai.EntityAIBase in project PneumaticCraft by MineMaarten.

the class DroneAIManager method setActiveWidget.

private void setActiveWidget(IProgWidget widget) {
    EntityAIBase targetAI = null;
    EntityAIBase ai = null;
    if (widget != null) {
        boolean first = widget instanceof ProgWidgetStart;
        targetAI = widget.getWidgetTargetAI(drone, widget);
        ai = widget.getWidgetAI(drone, widget);
        //Prevent endless loops
        Set<IProgWidget> visitedWidgets = new HashSet<IProgWidget>();
        while (!visitedWidgets.contains(widget) && targetAI == null && ai == null) {
            visitedWidgets.add(widget);
            IProgWidget oldWidget = widget;
            widget = widget.getOutputWidget(drone, progWidgets);
            if (widget == null) {
                if (first) {
                    return;
                } else {
                    if (stopWhenEndReached) {
                        setActiveWidget(null);
                    } else {
                        gotoFirstWidget();
                    }
                    return;
                }
            } else if (oldWidget.getOutputWidget() != widget) {
                if (addJumpBackWidget(oldWidget))
                    return;
            }
            targetAI = widget.getWidgetTargetAI(drone, widget);
            ai = widget.getWidgetAI(drone, widget);
        }
        drone.setActiveProgram(widget);
    } else {
        setLabel("Stopped");
    }
    curActiveWidget = widget;
    if (curWidgetAI != null)
        removeTask(curWidgetAI);
    if (curWidgetTargetAI != null)
        drone.getTargetAI().removeTask(curWidgetTargetAI);
    if (ai != null)
        addTask(2, ai);
    if (targetAI != null)
        drone.getTargetAI().addTask(2, targetAI);
    curWidgetAI = ai;
    curWidgetTargetAI = targetAI;
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart) HashSet(java.util.HashSet)

Aggregations

EntityAIBase (net.minecraft.entity.ai.EntityAIBase)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)1 ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)1