Search in sources :

Example 16 with IProgWidget

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

the class ProgrammedDroneUtils method retrieveItemsAmazonStyle.

public static EntityCreature retrieveItemsAmazonStyle(World world, int x, int y, int z, ItemStack... queriedStacks) {
    if (world.isRemote)
        return null;
    if (queriedStacks.length == 0)
        throw new IllegalArgumentException("You need to query at least 1 stack!");
    if (queriedStacks.length > 65)
        throw new IllegalArgumentException("You can only query up to 65 stacks at once!");
    for (ItemStack stack : queriedStacks) {
        if (stack == null)
            throw new IllegalArgumentException("You can't query a null stack!");
        if (stack.getItem() == null)
            throw new IllegalArgumentException("You can't query a stack with a null item!");
    }
    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);
    int yBase = 52;
    for (ItemStack stack : queriedStacks) {
        ProgWidgetInventoryImport im = new ProgWidgetInventoryImport();
        im.setX(92);
        im.setY(yBase);
        im.setCount(stack.stackSize);
        im.setUseCount(true);
        widgets.add(im);
        ProgWidgetArea area = new ProgWidgetArea();
        area.setX(107);
        area.setY(yBase);
        area.x1 = x;
        area.y1 = y;
        area.z1 = z;
        widgets.add(area);
        ProgWidgetItemFilter filter = new ProgWidgetItemFilter();
        filter.setX(107);
        filter.setY(yBase + 11);
        filter.setFilter(stack);
        filter.useMetadata = true;
        filter.useNBT = true;
        widgets.add(filter);
        yBase += 22;
    }
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(yBase);
    widgets.add(gotoPiece);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(yBase + 11);
    widgets.add(suicide);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : ProgWidgetInventoryImport(pneumaticCraft.common.progwidgets.ProgWidgetInventoryImport) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetItemFilter(pneumaticCraft.common.progwidgets.ProgWidgetItemFilter) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ItemStack(net.minecraft.item.ItemStack) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 17 with IProgWidget

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

the class ProgrammedDroneUtils method retrieveFluidAmazonStyle.

public static EntityCreature retrieveFluidAmazonStyle(World world, int x, int y, int z, FluidStack queriedFluid) {
    if (world.isRemote)
        return null;
    if (queriedFluid == null)
        throw new IllegalArgumentException("Can't query a null FluidStack");
    if (queriedFluid.amount <= 0)
        throw new IllegalArgumentException("Can't query 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);
    int yBase = 52;
    ProgWidgetLiquidImport im = new ProgWidgetLiquidImport();
    im.setX(92);
    im.setY(yBase);
    im.setCount(queriedFluid.amount);
    im.setUseCount(true);
    widgets.add(im);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x;
    area.y1 = y;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetLiquidFilter filter = new ProgWidgetLiquidFilter();
    filter.setX(107);
    filter.setY(yBase + 11);
    filter.setFluid(queriedFluid.getFluid());
    widgets.add(filter);
    yBase += 22;
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(yBase);
    widgets.add(gotoPiece);
    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(yBase + 11);
    widgets.add(suicide);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : ProgWidgetLiquidImport(pneumaticCraft.common.progwidgets.ProgWidgetLiquidImport) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetLiquidFilter(pneumaticCraft.common.progwidgets.ProgWidgetLiquidFilter) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 18 with IProgWidget

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

the class ClientEventHandler method onItemTooltip.

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    if (event.itemStack.getItem() instanceof IProgrammable) {
        IProgrammable programmable = (IProgrammable) event.itemStack.getItem();
        if (programmable.canProgram(event.itemStack) && programmable.showProgramTooltip()) {
            boolean hasInvalidPrograms = false;
            List<String> addedEntries = new ArrayList<String>();
            Map<String, Integer> widgetMap = getPuzzleSummary(TileEntityProgrammer.getProgWidgets(event.itemStack));
            for (Map.Entry<String, Integer> entry : widgetMap.entrySet()) {
                IProgWidget widget = ItemProgrammingPuzzle.getWidgetForName(entry.getKey());
                String prefix = "";
                GuiScreen curScreen = Minecraft.getMinecraft().currentScreen;
                if (curScreen instanceof IGuiDrone) {
                    if (!((IGuiDrone) curScreen).getDrone().isProgramApplicable(widget)) {
                        prefix = EnumChatFormatting.RED + "";
                        hasInvalidPrograms = true;
                    }
                }
                addedEntries.add(prefix + "-" + entry.getValue() + "x " + I18n.format("programmingPuzzle." + entry.getKey() + ".name"));
            }
            if (hasInvalidPrograms) {
                event.toolTip.add(EnumChatFormatting.RED + I18n.format("gui.tooltip.programmable.invalidPieces"));
            }
            Collections.sort(addedEntries);
            event.toolTip.addAll(addedEntries);
        }
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) IProgrammable(pneumaticCraft.api.item.IProgrammable) IGuiDrone(pneumaticCraft.client.gui.IGuiDrone) ArrayList(java.util.ArrayList) GuiScreen(net.minecraft.client.gui.GuiScreen) HashMap(java.util.HashMap) Map(java.util.Map) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 19 with IProgWidget

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

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(pneumaticCraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

Example 20 with IProgWidget

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

the class GuiProgrammer method mouseClicked.

@Override
protected void mouseClicked(int x, int y, int par3) {
    ItemStack programmedItem = te.getStackInSlot(TileEntityProgrammer.PROGRAM_SLOT);
    if (nameField.isFocused() && programmedItem != null) {
        programmedItem.setStackDisplayName(nameField.getText());
        NetworkHandler.sendToServer(new PacketUpdateTextfield(te, 0));
    }
    super.mouseClicked(x, y, par3);
    if (par3 == 1 && showingWidgetProgress == 0) {
        IProgWidget widget = programmerUnit.getHoveredWidget(x, y);
        if (widget != null) {
            GuiScreen screen = widget.getOptionWindow(this);
            if (screen != null)
                mc.displayGuiScreen(screen);
        }
    }
}
Also used : PacketUpdateTextfield(pneumaticCraft.common.network.PacketUpdateTextfield) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) GuiScreen(net.minecraft.client.gui.GuiScreen) ItemStack(net.minecraft.item.ItemStack)

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