@SideOnly(Side.CLIENT)
public interface Crosshairs {
  Crosshair SQUARE = new Crosshair(Util.getResource("textures/gui/crosshair/square.png"));
  Crosshair X = new CrosshairTriangle(Util.getResource("textures/gui/crosshair/x.png"));
  Crosshair INVERSE = new CrosshairTriangle(Util.getResource("textures/gui/crosshair/inverse.png"));
  Crosshair PLUS = new Crosshair(Util.getResource("textures/gui/crosshair/plus.png"));
}
Example #2
0
public final class GuiGeneric {
  public static final ResourceLocation LOCATION = Util.getResource("textures/gui/generic.png");

  // first one sets default texture w/h
  public static final GuiElement cornerTopLeft = new GuiElement(0, 0, 7, 7, 64, 64);
  public static final GuiElement cornerTopRight = new GuiElement(64 - 7, 0, 7, 7);
  public static final GuiElement cornerBottomLeft = new GuiElement(0, 64 - 7, 7, 7);
  public static final GuiElement cornerBottomRight = new GuiElement(64 - 7, 64 - 7, 7, 7);

  public static final GuiElementScalable borderTop = new GuiElementScalable(7, 0, 64 - 7 - 7, 7);
  public static final GuiElementScalable borderBottom =
      new GuiElementScalable(7, 64 - 7, 64 - 7 - 7, 7);
  public static final GuiElementScalable borderLeft = new GuiElementScalable(0, 7, 7, 64 - 7 - 7);
  public static final GuiElementScalable borderRight =
      new GuiElementScalable(64 - 7, 7, 7, 64 - 7 - 7);

  public static final GuiElementScalable overlap = new GuiElementScalable(21, 45, 7, 14);
  public static final GuiElement overlapTopLeft = new GuiElement(7, 40, 7, 7);
  public static final GuiElement overlapTopRight = new GuiElement(14, 40, 7, 7);
  public static final GuiElement overlapBottomLeft = new GuiElement(7, 47, 7, 7);
  public static final GuiElement overlapBottomRight = new GuiElement(14, 47, 7, 7);

  public static final GuiElementScalable textBackground = new GuiElementScalable(7 + 18, 7, 18, 10);

  public static final GuiElementScalable slot = new GuiElementScalable(7, 7, 18, 18);
  public static final GuiElementScalable slotEmpty = new GuiElementScalable(7 + 18, 7, 18, 18);

  public static final GuiElement sliderNormal = new GuiElement(7, 25, 10, 15);
  public static final GuiElement sliderLow = new GuiElement(17, 25, 10, 15);
  public static final GuiElement sliderHigh = new GuiElement(27, 25, 10, 15);
  public static final GuiElement sliderTop = new GuiElement(43, 7, 12, 1);
  public static final GuiElement sliderBottom = new GuiElement(43, 38, 12, 1);
  public static final GuiElementScalable sliderBackground = new GuiElementScalable(43, 8, 12, 30);

  private GuiGeneric() {}
}
 public MagneticPotion() {
   super(Util.getResource("magnetic"), false, false);
 }
// a side inventory to be displayed to the left or right of another GUI
@SideOnly(Side.CLIENT)
public class GuiSideInventory extends GuiModule {

  protected GuiElementScalable overlap = GuiGeneric.overlap;
  protected GuiElement overlapTopLeft = GuiGeneric.overlapTopLeft;
  protected GuiElement overlapTopRight = GuiGeneric.overlapTopRight;
  protected GuiElement overlapBottomLeft = GuiGeneric.overlapBottomLeft;
  protected GuiElement overlapBottomRight = GuiGeneric.overlapBottomRight;
  protected GuiElement overlapTop =
      new GuiElement(7, 0, 7, 7, 64, 64); // same as borderTop but only 7 wide

  protected GuiElementScalable textBackground = GuiGeneric.textBackground;

  protected GuiElementScalable slot = GuiGeneric.slot;
  protected GuiElementScalable slotEmpty = GuiGeneric.slotEmpty;

  protected GuiElement sliderNormal = GuiGeneric.sliderNormal;
  protected GuiElement sliderLow = GuiGeneric.sliderLow;
  protected GuiElement sliderHigh = GuiGeneric.sliderHigh;
  protected GuiElement sliderTop = GuiGeneric.sliderTop;
  protected GuiElement sliderBottom = GuiGeneric.sliderBottom;
  protected GuiElementScalable sliderBackground = GuiGeneric.sliderBackground;

  // we use the chest gui as a preset for our parts
  protected static final ResourceLocation GUI_INVENTORY =
      Util.getResource("textures/gui/generic.png");

  protected GuiWidgetBorder border = new GuiWidgetBorder();

  protected int columns;
  protected int slotCount;

  protected int firstSlotId;
  protected int lastSlotId;

  protected int yOffset = 5;
  protected int xOffset;
  protected boolean connected;

  protected GuiWidgetSlider slider =
      new GuiWidgetSlider(
          sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground);

  public GuiSideInventory(GuiMultiModule parent, Container container, int slotCount, int columns) {
    this(parent, container, slotCount, columns, false, false);
  }

  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();
  }

  protected boolean shouldDrawName() {
    if (this.inventorySlots instanceof BaseContainer) {
      return ((BaseContainer) this.inventorySlots).getInventoryDisplayName() != null;
    }

    return false;
  }

  @Override
  public boolean shouldDrawSlot(Slot slot) {
    if (slot.getSlotIndex() >= slotCount) {
      return false;
    }
    // all visible
    if (!slider.isEnabled()) {
      return true;
    }

    return firstSlotId <= slot.getSlotIndex() && lastSlotId > slot.getSlotIndex();
  }

  @Override
  public boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) {
    return super.isMouseOverSlot(slotIn, mouseX, mouseY) && shouldDrawSlot(slotIn);
  }

  public void updateSlotCount(int newSlotCount) {
    // don't do extra stuff if it's not needed
    if (slotCount == newSlotCount) {
      return;
    }

    this.slotCount = newSlotCount;
    // called twice to get correct slider calculation
    updatePosition(parent.cornerX, parent.cornerY, parent.realWidth, parent.realHeight);
    updatePosition(parent.cornerX, parent.cornerY, parent.realWidth, parent.realHeight);
  }

  @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();
  }

  private int getDisplayedRows() {
    return slider.height / slot.h;
  }

  private int getTotalRows() {
    int total = slotCount / columns;
    if (slotCount % columns != 0) {
      total++;
    }

    return total;
  }

  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;
  }

  // updates slot visibility
  protected void updateSlots() {
    firstSlotId = slider.getValue() * columns;
    lastSlotId = Math.min(slotCount, firstSlotId + getDisplayedRows() * columns);

    int xd = border.w + xOffset;
    int yd = border.h + yOffset;

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

    for (Object o : inventorySlots.inventorySlots) {
      Slot slot = (Slot) o;
      if (shouldDrawSlot(slot)) {
        // calc position of the slot
        int offset = slot.getSlotIndex() - firstSlotId;
        int x = (offset % columns) * this.slot.w;
        int y = (offset / columns) * this.slot.h;

        slot.xDisplayPosition = xd + x + 1;
        slot.yDisplayPosition = yd + y + 1;

        if (this.right) {
          slot.xDisplayPosition += parent.realWidth;
        } else {
          slot.xDisplayPosition -= this.xSize;
        }
      } else {
        slot.xDisplayPosition = 0;
        slot.yDisplayPosition = 0;
      }
    }
  }

  @Override
  public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    if (shouldDrawName()) {
      String name = ((BaseContainer) inventorySlots).getInventoryDisplayName();
      this.fontRendererObj.drawString(name, border.w, border.h - 1, 0x404040);
    }
  }

  @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;
  }

  protected int drawSlots(int xPos, int yPos) {
    int width = columns * slot.w;
    int height = ySize - border.h * 2;

    int fullRows = (lastSlotId - firstSlotId) / columns;
    int y;
    for (y = 0; y < fullRows * slot.h && y < height; y += slot.h) {
      slot.drawScaledX(xPos, yPos + y, width);
    }

    // draw partial row and unused slots
    int slotsLeft = (lastSlotId - firstSlotId) % columns;
    if (slotsLeft > 0) {
      slot.drawScaledX(xPos, yPos + y, slotsLeft * slot.w);
      // empty slots that don't exist
      slotEmpty.drawScaledX(xPos + slotsLeft * slot.w, yPos + y, width - slotsLeft * slot.w);
    }

    return width;
  }
}