Search in sources :

Example 1 with CapabilityGPSAreaTool

use of me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool in project pnc-repressurized by TeamPneumatic.

the class ItemGPSAreaTool method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> infoList, ITooltipFlag par4) {
    super.addInformation(stack, worldIn, infoList, par4);
    for (int index = 0; index < 2; index++) {
        BlockPos pos = getGPSLocation(stack, index);
        if (pos != null) {
            infoList.add(String.format("\u00a72P%d: %d, %d, %d", index + 1, pos.getX(), pos.getY(), pos.getZ()));
        }
        String varName = getVariable(stack, index);
        if (!varName.equals("")) {
            infoList.add(I18n.format("gui.tooltip.gpsTool.variable", varName));
        }
    }
    CapabilityGPSAreaTool cap = getCap(stack);
    if (cap != null) {
        ProgWidgetArea area = cap.getWidget();
        area.addAreaTypeTooltip(infoList);
    }
}
Also used : CapabilityGPSAreaTool(me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool) ProgWidgetArea(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with CapabilityGPSAreaTool

use of me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool in project pnc-repressurized by TeamPneumatic.

the class GuiGPSAreaTool method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button.id == CHANGE_AREA_BUTTON_ID) {
        ItemStack stack = mc.player.getHeldItemMainhand();
        CapabilityGPSAreaTool cap = ItemGPSAreaTool.getCap(stack);
        if (cap != null) {
            Runnable returnAction = () -> mc.displayGuiScreen(new GuiGPSAreaTool(stack, index));
            mc.displayGuiScreen(new GuiProgWidgetAreaTool(cap.getWidget(), returnAction));
        }
    } else {
        super.actionPerformed(button);
    }
}
Also used : CapabilityGPSAreaTool(me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CapabilityGPSAreaTool

use of me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool in project pnc-repressurized by TeamPneumatic.

the class PacketUpdateGPSAreaTool method handleServerSide.

@Override
public void handleServerSide(PacketUpdateGPSAreaTool message, EntityPlayer player) {
    ItemStack stack = player.getHeldItemMainhand();
    if (stack.getItem() == Itemss.GPS_AREA_TOOL) {
        CapabilityGPSAreaTool cap = ItemGPSAreaTool.getCap(stack);
        cap.updateAreaFromNBT(message.areaWidgetData);
        NBTUtil.setBoolean(stack, "dummy", !NBTUtil.getBoolean(stack, "dummy"));
    }
}
Also used : CapabilityGPSAreaTool(me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool) ItemStack(net.minecraft.item.ItemStack)

Example 4 with CapabilityGPSAreaTool

use of me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool in project pnc-repressurized by TeamPneumatic.

the class GuiProgrammer method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    drawDefaultBackground();
    bindGuiTexture();
    int xStart = (width - xSize) / 2;
    int yStart = (height - ySize) / 2;
    drawModalRectWithCustomSizedTexture(xStart, yStart, 0, 0, xSize, ySize, xSize, ySize);
    programmerUnit.getScrollBar().setEnabled(showingWidgetProgress == 0);
    super.drawGuiContainerBackgroundLayer(partialTicks, x, y);
    if (showingWidgetProgress > 0)
        programmerUnit.getScrollBar().setCurrentState(programmerUnit.getLastZoom());
    programmerUnit.render(x, y, showFlow.checked, showInfo.checked && showingWidgetProgress == 0, draggingWidget == null);
    int origX = x;
    int origY = y;
    x -= programmerUnit.getTranslatedX();
    y -= programmerUnit.getTranslatedY();
    float scale = programmerUnit.getScale();
    x = (int) (x / scale);
    y = (int) (y / scale);
    if (showingWidgetProgress > 0) {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        bindGuiTexture();
        int width = oldShowingWidgetProgress + (int) ((showingWidgetProgress - oldShowingWidgetProgress) * partialTicks);
        for (int i = 0; i < width; i++) {
            drawModalRectWithCustomSizedTexture(xStart + 320 - i, yStart + 36, 323, 36, 1, 136, xSize, ySize);
        }
        drawModalRectWithCustomSizedTexture(xStart + 319 - width, yStart + 36, 319, 36, 2, 136, xSize, ySize);
        if (showingAllWidgets && draggingWidget != null)
            toggleShowWidgets();
    }
    GlStateManager.enableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
    for (int i = 0; i < visibleSpawnWidgets.size(); i++) {
        IProgWidget widget = visibleSpawnWidgets.get(i);
        GlStateManager.pushMatrix();
        GlStateManager.translate(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
        GlStateManager.scale(0.5, 0.5, 1);
        if (showingAllWidgets && filteredSpawnWidgets != null && !filteredSpawnWidgets.get(i)) {
            GlStateManager.color(1, 1, 1, 0.2f);
        } else {
            GlStateManager.color(1, 1, 1, 1);
        }
        widget.render();
        GlStateManager.popMatrix();
    }
    GlStateManager.disableBlend();
    GlStateManager.pushMatrix();
    GlStateManager.translate(programmerUnit.getTranslatedX(), programmerUnit.getTranslatedY(), 0);
    GlStateManager.scale(scale, scale, 1);
    if (draggingWidget != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(draggingWidget.getX() + guiLeft, draggingWidget.getY() + guiTop, 0);
        GlStateManager.scale(0.5, 0.5, 1);
        draggingWidget.render();
        GlStateManager.popMatrix();
    }
    GlStateManager.popMatrix();
    boolean isLeftClicking = Mouse.isButtonDown(0);
    boolean isMiddleClicking = GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPickBlock);
    if (draggingWidget != null) {
        setConnectingWidgetsToXY(draggingWidget, x - dragMouseStartX + dragWidgetStartX - guiLeft, y - dragMouseStartY + dragWidgetStartY - guiTop);
    }
    if (isLeftClicking && !wasClicking) {
        for (IProgWidget widget : visibleSpawnWidgets) {
            if (origX >= widget.getX() + guiLeft && origY >= widget.getY() + guiTop && origX <= widget.getX() + guiLeft + widget.getWidth() / 2 && origY <= widget.getY() + guiTop + widget.getHeight() / 2) {
                draggingWidget = widget.copy();
                te.progWidgets.add(draggingWidget);
                dragMouseStartX = x - (int) (guiLeft / scale);
                dragMouseStartY = y - (int) (guiTop / scale);
                dragWidgetStartX = (int) ((widget.getX() - programmerUnit.getTranslatedX()) / scale);
                dragWidgetStartY = (int) ((widget.getY() - programmerUnit.getTranslatedY()) / scale);
                break;
            }
        }
        // create area widgets straight from GPS Area Tools
        ItemStack heldItem = mc.player.inventory.getItemStack();
        ProgWidgetArea areaToolWidget = null;
        if (heldItem.hasCapability(CapabilityGPSAreaTool.INSTANCE, null)) {
            CapabilityGPSAreaTool cap = heldItem.getCapability(CapabilityGPSAreaTool.INSTANCE, null);
            areaToolWidget = cap.createWidget();
        }
        if (draggingWidget == null && showingWidgetProgress == 0) {
            IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
            if (widget != null) {
                draggingWidget = widget;
                dragMouseStartX = x - guiLeft;
                dragMouseStartY = y - guiTop;
                dragWidgetStartX = widget.getX();
                dragWidgetStartY = widget.getY();
                if (areaToolWidget != null && widget instanceof ProgWidgetArea) {
                    NBTTagCompound tag = new NBTTagCompound();
                    areaToolWidget.writeToNBT(tag);
                    widget.readFromNBT(tag);
                } else if (heldItem.getItem() == Itemss.GPS_TOOL && widget instanceof ProgWidgetCoordinate) {
                    ((ProgWidgetCoordinate) widget).loadFromGPSTool(heldItem);
                }
            }
        }
        // Create a new widget from a GPS Area tool when nothing was selected
        if (draggingWidget == null) {
            if (areaToolWidget != null) {
                draggingWidget = areaToolWidget;
            } else if (heldItem.getItem() == Itemss.GPS_TOOL) {
                ProgWidgetCoordinate coordWidget = new ProgWidgetCoordinate();
                draggingWidget = coordWidget;
                coordWidget.loadFromGPSTool(heldItem);
            }
            if (draggingWidget != null) {
                draggingWidget.setX(Integer.MAX_VALUE);
                draggingWidget.setY(Integer.MAX_VALUE);
                te.progWidgets.add(draggingWidget);
                dragMouseStartX = draggingWidget.getWidth() / 3;
                dragMouseStartY = draggingWidget.getHeight() / 4;
                dragWidgetStartX = 0;
                dragWidgetStartY = 0;
            }
        }
    } else if (isMiddleClicking && !wasClicking && showingWidgetProgress == 0) {
        IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
        if (widget != null) {
            draggingWidget = widget.copy();
            te.progWidgets.add(draggingWidget);
            dragMouseStartX = 0;
            dragMouseStartY = 0;
            dragWidgetStartX = widget.getX() - (x - guiLeft);
            dragWidgetStartY = widget.getY() - (y - guiTop);
            if (PneumaticCraftRepressurized.proxy.isSneakingInGui())
                copyAndConnectConnectingWidgets(widget, draggingWidget);
        }
    }
    if (!isLeftClicking && !isMiddleClicking && draggingWidget != null) {
        if (programmerUnit.isOutsideProgrammingArea(draggingWidget)) {
            deleteConnectingWidgets(draggingWidget);
        } else {
            handlePuzzleMargins();
            if (!isValidPlaced(draggingWidget)) {
                setConnectingWidgetsToXY(draggingWidget, dragWidgetStartX, dragWidgetStartY);
                if (programmerUnit.isOutsideProgrammingArea(draggingWidget))
                    deleteConnectingWidgets(draggingWidget);
            }
        }
        NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
        TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
        draggingWidget = null;
    }
    wasClicking = isLeftClicking || isMiddleClicking;
    lastMouseX = origX;
    lastMouseY = origY;
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) CapabilityGPSAreaTool(me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool) ProgWidgetArea(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketProgrammerUpdate(me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate) ItemStack(net.minecraft.item.ItemStack) ProgWidgetCoordinate(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate) Point(java.awt.Point)

Aggregations

CapabilityGPSAreaTool (me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool)4 ItemStack (net.minecraft.item.ItemStack)3 ProgWidgetArea (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea)2 Point (java.awt.Point)1 PacketProgrammerUpdate (me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate)1 IProgWidget (me.desht.pneumaticcraft.common.progwidgets.IProgWidget)1 ProgWidgetCoordinate (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1