Search in sources :

Example 6 with ProgWidgetStart

use of pneumaticCraft.common.progwidgets.ProgWidgetStart in project PneumaticCraft by MineMaarten.

the class GuiProgrammer method actionPerformed.

/**
     * Fired when a control is clicked. This is the equivalent of
     * ActionListener.actionPerformed(ActionEvent e).
     */
@Override
protected void actionPerformed(GuiButton button) {
    switch(button.id) {
        case // redstone button
        0:
            //          redstoneBehaviourStat.closeWindow();
            break;
        case 3:
            if (--widgetPage < 0)
                widgetPage = maxPage;
            updateVisibleProgWidgets();
            return;
        case 4:
            if (++widgetPage > maxPage)
                widgetPage = 0;
            updateVisibleProgWidgets();
            return;
        case 5:
            for (IProgWidget widget : te.progWidgets) {
                if (widget instanceof ProgWidgetStart) {
                    programmerUnit.gotoPiece(widget);
                    break;
                }
            }
            return;
        case 6:
            if (te.progWidgets.size() > 0) {
                programmerUnit.gotoPiece(te.progWidgets.get(te.progWidgets.size() - 1));
            }
            return;
        case 7:
            NBTTagCompound mainTag = new NBTTagCompound();
            te.writeProgWidgetsToNBT(mainTag);
            FMLClientHandler.instance().showGuiScreen(pastebinGui = new GuiPastebin(this, mainTag));
            break;
        case 11:
            te.progWidgets.clear();
            NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
            break;
        case 12:
            for (IProgWidget widget : te.progWidgets) {
                if (widget instanceof ProgWidgetStart) {
                    generateRelativeOperators((ProgWidgetCoordinateOperator) widget.getOutputWidget(), null, false);
                    break;
                }
            }
            break;
    }
    NetworkHandler.sendToServer(new PacketGuiButton(button.id));
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) PacketGuiButton(pneumaticCraft.common.network.PacketGuiButton) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketProgrammerUpdate(pneumaticCraft.common.network.PacketProgrammerUpdate) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 7 with ProgWidgetStart

use of pneumaticCraft.common.progwidgets.ProgWidgetStart 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)

Example 8 with ProgWidgetStart

use of pneumaticCraft.common.progwidgets.ProgWidgetStart in project PneumaticCraft by MineMaarten.

the class ItemLogisticsDrone method addLogisticsProgram.

private void addLogisticsProgram(int x, int y, int z, List<IProgWidget> widgets) {
    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(0);
    start.setY(0);
    widgets.add(start);
    ProgWidgetLogistics logistics = new ProgWidgetLogistics();
    logistics.setX(0);
    logistics.setY(11);
    widgets.add(logistics);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(15);
    area.setY(11);
    area.x1 = x - 16;
    area.y1 = y - 16;
    area.z1 = z - 16;
    area.x2 = x + 16;
    area.y2 = y + 16;
    area.z2 = z + 16;
    widgets.add(area);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
}
Also used : ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetLogistics(pneumaticCraft.common.progwidgets.ProgWidgetLogistics) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 9 with ProgWidgetStart

use of pneumaticCraft.common.progwidgets.ProgWidgetStart in project PneumaticCraft by MineMaarten.

the class ProgrammedDroneUtils method deliverItemsAmazonStyle.

public static EntityCreature deliverItemsAmazonStyle(World world, int x, int y, int z, ItemStack... deliveredStacks) {
    if (world.isRemote)
        return null;
    if (deliveredStacks.length == 0)
        throw new IllegalArgumentException("You need to deliver at least 1 stack!");
    if (deliveredStacks.length > 65)
        throw new IllegalArgumentException("You can only deliver up to 65 stacks at once!");
    for (ItemStack stack : deliveredStacks) {
        if (stack == null)
            throw new IllegalArgumentException("You can't supply a null stack to be delivered!");
        if (stack.getItem() == null)
            throw new IllegalArgumentException("You can't supply a stack with a null item to be delivered!");
    }
    EntityDrone drone = getChargedDispenserUpgradeDrone(world);
    //Program the drone
    int startY = world.getHeightValue(x + 30, z) + 30;
    drone.setPosition(x + 30, startY, z);
    List<IProgWidget> widgets = drone.progWidgets;
    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(92);
    start.setY(41);
    widgets.add(start);
    ProgWidgetInventoryExport export = new ProgWidgetInventoryExport();
    export.setX(92);
    export.setY(52);
    widgets.add(export);
    ProgWidgetDropItem drop = new ProgWidgetDropItem();
    drop.setX(92);
    drop.setY(74);
    widgets.add(drop);
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(96);
    widgets.add(gotoPiece);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(107);
    widgets.add(suicide);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(52);
    area.x1 = x;
    area.y1 = y;
    area.z1 = z;
    widgets.add(area);
    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(74);
    area.x1 = x;
    area.z1 = z;
    if (drone.isBlockValidPathfindBlock(x, y, z)) {
        for (int i = 0; i < 5 && drone.isBlockValidPathfindBlock(area.x1, i + y + 1, area.z1); i++) {
            area.y1 = y + i;
        }
    } else {
        area.y1 = world.getHeightValue(x, z) + 10;
        //Worst case scenario, there are definately no blocks here.
        if (!drone.isBlockValidPathfindBlock(area.x1, area.y1, area.z1))
            area.y1 = 260;
    }
    widgets.add(area);
    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(96);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    for (int i = 0; i < deliveredStacks.length; i++) {
        drone.getInventory().setInventorySlotContents(i, deliveredStacks[i].copy());
    }
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : ProgWidgetDropItem(pneumaticCraft.common.progwidgets.ProgWidgetDropItem) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetInventoryExport(pneumaticCraft.common.progwidgets.ProgWidgetInventoryExport) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ItemStack(net.minecraft.item.ItemStack) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Aggregations

ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)9 IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)8 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)5 ProgWidgetArea (pneumaticCraft.common.progwidgets.ProgWidgetArea)5 ProgWidgetGoToLocation (pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation)4 ProgWidgetSuicide (pneumaticCraft.common.progwidgets.ProgWidgetSuicide)4 ItemStack (net.minecraft.item.ItemStack)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 Entity (net.minecraft.entity.Entity)1 EntityAIBase (net.minecraft.entity.ai.EntityAIBase)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IGuiScreen (pneumaticCraft.api.client.pneumaticHelmet.IGuiScreen)1 PacketGuiButton (pneumaticCraft.common.network.PacketGuiButton)1 PacketProgrammerUpdate (pneumaticCraft.common.network.PacketProgrammerUpdate)1 ProgWidgetCoordinateOperator (pneumaticCraft.common.progwidgets.ProgWidgetCoordinateOperator)1 ProgWidgetDropItem (pneumaticCraft.common.progwidgets.ProgWidgetDropItem)1 ProgWidgetInventoryExport (pneumaticCraft.common.progwidgets.ProgWidgetInventoryExport)1 ProgWidgetInventoryImport (pneumaticCraft.common.progwidgets.ProgWidgetInventoryImport)1