@Override
  public void updatePosition(int parentX, int parentY, int parentSizeX, int parentSizeY) {
    // at most as big as the parent
    this.ySize = calcCappedYSize(parentSizeY - 10);
    // slider needed?
    if (getDisplayedRows() < getTotalRows()) {
      slider.enable();
      this.xSize = columns * slot.w + slider.width + 2 * border.w;
    } else {
      slider.disable();
      this.xSize = columns * slot.w + border.w * 2;
    }

    // update position
    super.updatePosition(parentX, parentY, parentSizeX, parentSizeY);

    // connected needs to move to the side
    if (connected) {
      if (yOffset == 0) {
        if (right) {
          border.cornerTopLeft = overlapTop;
        } else {
          border.cornerTopRight = overlapTop;
        }
      }

      xOffset = (border.w - 1) * (right ? -1 : 1);
      guiLeft += xOffset;
    } else {
      xOffset = 0;
    }

    // move it a bit
    this.guiTop += yOffset;

    border.setPosition(guiLeft, guiTop);
    border.setSize(xSize, ySize);

    int y = guiTop + border.h;
    int h = ySize - border.h * 2;

    if (shouldDrawName()) {
      y += textBackground.h;
      h -= textBackground.h;
    }
    slider.setPosition(guiLeft + columns * slot.w + border.w, y);
    slider.setSize(h);
    slider.setSliderParameters(0, getTotalRows() - getDisplayedRows(), 1);

    updateSlots();
  }
  public GuiSideInventory(
      GuiMultiModule parent,
      Container container,
      int slotCount,
      int columns,
      boolean rightSide,
      boolean connected) {
    super(parent, container, rightSide, false);

    this.connected = connected;

    this.columns = columns;
    this.slotCount = slotCount;

    this.xSize = columns * slot.w + border.w * 2;
    this.ySize = calcCappedYSize(slot.h * 10);

    if (connected) {
      if (right) {
        border.cornerTopLeft = overlapTopLeft;
        border.borderLeft = overlap;
        border.cornerBottomLeft = overlapBottomLeft;
      } else {
        border.cornerTopRight = overlapTopRight;
        border.borderRight = overlap;
        border.cornerBottomRight = overlapBottomRight;
      }
    }

    yOffset = 0;

    updateSlots();
  }
  private int calcCappedYSize(int max) {
    int h = slot.h * getTotalRows();

    h = border.getHeightWithBorder(h);

    if (shouldDrawName()) {
      h += textBackground.h;
    }

    // not higher than the max
    while (h > max) {
      h -= slot.h;
    }
    return h;
  }
  @Override
  protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    guiLeft += border.w;
    guiTop += border.h;

    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.getTextureManager().bindTexture(GUI_INVENTORY);

    int x = guiLeft; // + border.w;
    int y = guiTop; // + border.h;
    int midW = xSize - border.w * 2;
    int midH = ySize - border.h * 2;

    border.draw();

    if (shouldDrawName()) {
      textBackground.drawScaledX(x, y, midW);
      y += textBackground.h;
    }

    this.mc.getTextureManager().bindTexture(GUI_INVENTORY);
    drawSlots(x, y);
    /*
        // draw the connection to the main thing
        if(right) {
          x = guiLeft;
          y = guiTop;

          if(guiTop == parent.cornerY) {
            borderTop.drawScaledX(x, y, overlapTopLeft.w);
          }
          else {
            overlapTopLeft.draw(x, y);
          }
          y += cornerTopLeft.h;
          overlap.drawScaledY(x, y, midH);
          y += midH;
          if(guiBottom() == parent.cornerX + parent.realHeight) {
            borderBottom.drawScaledX(x, y, overlapBottomLeft.w);
          }
          else {
            overlapBottomLeft.draw(x, y);
          }
        }
        else if(slider.isEnabled()) {
          y = guiTop;

          borderTop.drawScaledX(x, y, cornerTopRight.w);
          y += cornerTopRight.h;
          overlap.drawScaledY(x, y, midH);
          y += midH;
          borderBottom.drawScaledX(x, y, cornerBottomRight.w);

          x = guiRight() - 1;
          y = guiTop;
          if(guiTop == parent.cornerY) {
            borderTop.drawScaledX(x, y, overlapTopRight.w);
          }
          else {
            overlapTopRight.draw(x, y);
          }
          y += cornerTopRight.h;
          overlap.drawScaledY(x, y, midH);
          y += midH;
          if(guiBottom() == parent.cornerX + parent.realHeight) {
            borderBottom.drawScaledX(x, y, overlapBottomRight.w);
          }
          else {
            overlapBottomRight.draw(x, y);
          }
        }
    */
    // slider
    if (slider.isEnabled()) {
      slider.update(
          mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInModule(mouseX, mouseY));
      slider.draw();

      updateSlots();
    }

    guiLeft -= border.w;
    guiTop -= border.h;
  }