Search in sources :

Example 11 with IProgWidget

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

the class DroneAIManager method setWidgets.

public void setWidgets(List<IProgWidget> progWidgets) {
    this.progWidgets = progWidgets;
    for (IProgWidget widget : progWidgets) {
        if (widget instanceof IVariableWidget) {
            ((IVariableWidget) widget).setAIManager(this);
        }
    }
    gotoFirstWidget();
}
Also used : IVariableWidget(pneumaticCraft.common.progwidgets.IVariableWidget) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget)

Example 12 with IProgWidget

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

the class TileEntityProgrammer method getAllVariables.

/**
     * Returns a set with all variables that are used in the program.
     * @return
     */
public Set<String> getAllVariables() {
    Set<String> variables = new HashSet<String>();
    for (IProgWidget widget : progWidgets) {
        if (widget instanceof IVariableWidget)
            ((IVariableWidget) widget).addVariables(variables);
    }
    variables.remove("");
    return variables;
}
Also used : IVariableWidget(pneumaticCraft.common.progwidgets.IVariableWidget) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) HashSet(java.util.HashSet)

Example 13 with IProgWidget

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

the class TileEntityProgrammer method updatePuzzleConnections.

public static void updatePuzzleConnections(List<IProgWidget> progWidgets) {
    for (IProgWidget widget : progWidgets) {
        widget.setParent(null);
        Class<? extends IProgWidget>[] parameters = widget.getParameters();
        if (parameters != null) {
            for (int i = 0; i < parameters.length * 2; i++) {
                widget.setParameter(i, null);
            }
        }
        if (widget.hasStepOutput())
            widget.setOutputWidget(null);
    }
    for (IProgWidget checkedWidget : progWidgets) {
        //check for connection to the right of the checked widget.
        Class<? extends IProgWidget>[] parameters = checkedWidget.getParameters();
        if (parameters != null) {
            for (IProgWidget widget : progWidgets) {
                if (widget != checkedWidget && checkedWidget.getX() + checkedWidget.getWidth() / 2 == widget.getX()) {
                    for (int i = 0; i < parameters.length; i++) {
                        if (checkedWidget.canSetParameter(i) && parameters[i] == widget.returnType() && checkedWidget.getY() + i * 11 == widget.getY()) {
                            checkedWidget.setParameter(i, widget);
                            widget.setParent(checkedWidget);
                        }
                    }
                }
            }
        }
        //check for connection to the bottom of the checked widget.
        if (checkedWidget.hasStepOutput()) {
            for (IProgWidget widget : progWidgets) {
                if (widget.hasStepInput() && widget.getX() == checkedWidget.getX() && widget.getY() == checkedWidget.getY() + checkedWidget.getHeight() / 2) {
                    checkedWidget.setOutputWidget(widget);
                }
            }
        }
    }
    //go again for the blacklist (as those are mirrored)
    for (IProgWidget checkedWidget : progWidgets) {
        if (checkedWidget.returnType() == null) {
            //if it's a program (import/export inventory, attack entity) rather than a parameter (area, item filter).
            Class<? extends IProgWidget>[] parameters = checkedWidget.getParameters();
            if (parameters != null) {
                for (int i = 0; i < parameters.length; i++) {
                    if (checkedWidget.canSetParameter(i)) {
                        for (IProgWidget widget : progWidgets) {
                            if (parameters[i] == widget.returnType()) {
                                if (widget != checkedWidget && widget.getX() + widget.getWidth() / 2 == checkedWidget.getX() && widget.getY() == checkedWidget.getY() + i * 11) {
                                    IProgWidget root = widget;
                                    while (root.getParent() != null) {
                                        root = root.getParent();
                                    }
                                    checkedWidget.setParameter(i + parameters.length, root);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget)

Example 14 with IProgWidget

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

the class TileEntityProgrammer method setWidgetsToNBT.

public static void setWidgetsToNBT(List<IProgWidget> widgets, NBTTagCompound tag) {
    NBTTagList widgetTags = new NBTTagList();
    for (IProgWidget widget : widgets) {
        NBTTagCompound widgetTag = new NBTTagCompound();
        widget.writeToNBT(widgetTag);
        widgetTags.appendTag(widgetTag);
    }
    tag.setTag("widgets", widgetTags);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 15 with IProgWidget

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

the class ProgrammedDroneUtils method deliverFluidAmazonStyle.

public static EntityCreature deliverFluidAmazonStyle(World world, int x, int y, int z, FluidStack deliveredFluid) {
    if (world.isRemote)
        return null;
    if (deliveredFluid == null)
        throw new IllegalArgumentException("Can't deliver a null FluidStack");
    if (deliveredFluid.amount <= 0)
        throw new IllegalArgumentException("Can't deliver a FluidStack with an amount of <= 0");
    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);
    ProgWidgetLiquidExport export = new ProgWidgetLiquidExport();
    export.setX(92);
    export.setY(52);
    widgets.add(export);
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(74);
    widgets.add(gotoPiece);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(85);
    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 + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    drone.getTank().fill(deliveredFluid, true);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetLiquidExport(pneumaticCraft.common.progwidgets.ProgWidgetLiquidExport) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Aggregations

IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)36 Point (java.awt.Point)8 ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)8 ArrayList (java.util.ArrayList)6 ItemStack (net.minecraft.item.ItemStack)6 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)6 ProgWidgetArea (pneumaticCraft.common.progwidgets.ProgWidgetArea)5 PacketProgrammerUpdate (pneumaticCraft.common.network.PacketProgrammerUpdate)4 ProgWidgetGoToLocation (pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation)4 ProgWidgetSuicide (pneumaticCraft.common.progwidgets.ProgWidgetSuicide)4 HashSet (java.util.HashSet)3 GuiScreen (net.minecraft.client.gui.GuiScreen)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChunkPosition (net.minecraft.world.ChunkPosition)3 Rectangle (java.awt.Rectangle)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entity (net.minecraft.entity.Entity)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IProgrammable (pneumaticCraft.api.item.IProgrammable)2