Search in sources :

Example 31 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.common.progwidgets.IProgWidget)

Example 32 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.common.progwidgets.IVariableWidget) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget)

Example 33 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

IProgWidget (me.desht.pneumaticcraft.common.progwidgets.IProgWidget)33 Point (java.awt.Point)10 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 PacketProgrammerUpdate (me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate)4 ProgWidgetStart (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)4 GuiScreen (net.minecraft.client.gui.GuiScreen)3 BlockPos (net.minecraft.util.math.BlockPos)3 IProgrammable (me.desht.pneumaticcraft.api.item.IProgrammable)2 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)2 PacketGuiButton (me.desht.pneumaticcraft.common.network.PacketGuiButton)2 PacketUpdateTextfield (me.desht.pneumaticcraft.common.network.PacketUpdateTextfield)2 IVariableWidget (me.desht.pneumaticcraft.common.progwidgets.IVariableWidget)2 ProgWidgetArea (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea)2 ProgWidgetCoordinate (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate)2 ProgWidgetCoordinateOperator (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinateOperator)2 Entity (net.minecraft.entity.Entity)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 Rectangle (java.awt.Rectangle)1