Search in sources :

Example 6 with IProgWidget

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

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

Example 7 with IProgWidget

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

the class DroneAIExternalProgram method doBlockInteraction.

@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
    IItemHandler inv = IOHelper.getInventoryForTE(drone.world().getTileEntity(pos));
    if (inv == null)
        return false;
    if (curProgramTag != null) {
        if (curSlot < inv.getSlots()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (curProgramTag.equals(stack.getTagCompound())) {
                subAI.onUpdateTasks();
                if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
                    curProgramTag = null;
                    curSlot++;
                }
            } else {
                curProgramTag = null;
                subAI.setWidgets(new ArrayList<>());
            }
        }
        return true;
    } else {
        while (curSlot < inv.getSlots()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack.getItem() instanceof IProgrammable) {
                IProgrammable programmable = (IProgrammable) stack.getItem();
                if (programmable.canProgram(stack) && programmable.usesPieces(stack)) {
                    List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(stack);
                    boolean areWidgetsValid = true;
                    for (IProgWidget widget : widgets) {
                        if (!drone.isProgramApplicable(widget)) {
                            areWidgetsValid = false;
                            break;
                        }
                    }
                    if (areWidgetsValid) {
                        if (widget.shareVariables)
                            mainAI.connectVariables(subAI);
                        subAI.getDrone().getAIManager().setLabel("Main");
                        subAI.setWidgets(widgets);
                        curProgramTag = stack.getTagCompound();
                        if (!subAI.isIdling()) {
                            return true;
                        }
                    }
                }
            }
            curSlot++;
        }
        return false;
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) IItemHandler(net.minecraftforge.items.IItemHandler) IProgrammable(me.desht.pneumaticcraft.api.item.IProgrammable) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IProgWidget

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

the class PacketSyncDroneEntityProgWidgets method handleClientSide.

@Override
public void handleClientSide(PacketSyncDroneEntityProgWidgets message, EntityPlayer player) {
    Entity entity = player.world.getEntityByID(message.entityId);
    if (entity instanceof EntityDrone) {
        EntityDrone drone = (EntityDrone) entity;
        List<IProgWidget> widgets = drone.getProgWidgets();
        widgets.clear();
        widgets.addAll(message.progWidgets);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) EntityDrone(me.desht.pneumaticcraft.common.entity.living.EntityDrone)

Example 9 with IProgWidget

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

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

Example 10 with IProgWidget

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

the class GuiProgrammer method handlePuzzleMargins.

private void handlePuzzleMargins() {
    // Check for connection to the left of the dragged widget.
    Class<? extends IProgWidget> returnValue = draggingWidget.returnType();
    if (returnValue != null) {
        for (IProgWidget widget : te.progWidgets) {
            if (widget != draggingWidget && Math.abs(widget.getX() + widget.getWidth() / 2 - draggingWidget.getX()) <= FAULT_MARGIN) {
                Class<? extends IProgWidget>[] parameters = widget.getParameters();
                if (parameters != null) {
                    for (int i = 0; i < parameters.length; i++) {
                        if (widget.canSetParameter(i) && parameters[i] == returnValue && Math.abs(widget.getY() + i * 11 - draggingWidget.getY()) <= FAULT_MARGIN) {
                            setConnectingWidgetsToXY(draggingWidget, widget.getX() + widget.getWidth() / 2, widget.getY() + i * 11);
                            return;
                        }
                    }
                }
            }
        }
    }
    // check for connection to the right of the dragged widget.
    Class<? extends IProgWidget>[] parameters = draggingWidget.getParameters();
    if (parameters != null) {
        for (IProgWidget widget : te.progWidgets) {
            IProgWidget outerPiece = draggingWidget;
            if (outerPiece.returnType() != null) {
                // When the piece is a parameter pice (area, item filter, text).
                while (outerPiece.getConnectedParameters()[0] != null) {
                    outerPiece = outerPiece.getConnectedParameters()[0];
                }
            }
            if (widget != draggingWidget && Math.abs(outerPiece.getX() + outerPiece.getWidth() / 2 - widget.getX()) <= FAULT_MARGIN) {
                if (widget.returnType() != null) {
                    for (int i = 0; i < parameters.length; i++) {
                        if (draggingWidget.canSetParameter(i) && parameters[i] == widget.returnType() && Math.abs(draggingWidget.getY() + i * 11 - widget.getY()) <= FAULT_MARGIN) {
                            setConnectingWidgetsToXY(draggingWidget, widget.getX() - draggingWidget.getWidth() / 2 - (outerPiece.getX() - draggingWidget.getX()), widget.getY() - i * 11);
                        }
                    }
                } else {
                    Class<? extends IProgWidget>[] checkingPieceParms = widget.getParameters();
                    if (checkingPieceParms != null) {
                        for (int i = 0; i < checkingPieceParms.length; i++) {
                            if (widget.canSetParameter(i + parameters.length) && checkingPieceParms[i] == parameters[0] && Math.abs(widget.getY() + i * 11 - draggingWidget.getY()) <= FAULT_MARGIN) {
                                setConnectingWidgetsToXY(draggingWidget, widget.getX() - draggingWidget.getWidth() / 2 - (outerPiece.getX() - draggingWidget.getX()), widget.getY() + i * 11);
                            }
                        }
                    }
                }
            }
        }
    }
    // check for connection to the top of the dragged widget.
    if (draggingWidget.hasStepInput()) {
        for (IProgWidget widget : te.progWidgets) {
            if (widget.hasStepOutput() && Math.abs(widget.getX() - draggingWidget.getX()) <= FAULT_MARGIN && Math.abs(widget.getY() + widget.getHeight() / 2 - draggingWidget.getY()) <= FAULT_MARGIN) {
                setConnectingWidgetsToXY(draggingWidget, widget.getX(), widget.getY() + widget.getHeight() / 2);
            }
        }
    }
    // check for connection to the bottom of the dragged widget.
    if (draggingWidget.hasStepOutput()) {
        for (IProgWidget widget : te.progWidgets) {
            if (widget.hasStepInput() && Math.abs(widget.getX() - draggingWidget.getX()) <= FAULT_MARGIN && Math.abs(widget.getY() - draggingWidget.getY() - draggingWidget.getHeight() / 2) <= FAULT_MARGIN) {
                setConnectingWidgetsToXY(draggingWidget, widget.getX(), widget.getY() - draggingWidget.getHeight() / 2);
            }
        }
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

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