Class ItemDisplay

java.lang.Object
com.trevlar.menukit.api.element.AbstractPanelElement
com.trevlar.menukit.api.element.ItemDisplay
All Implemented Interfaces:
PanelElement

public class ItemDisplay extends AbstractPanelElement
An item drawn at a fixed size, with its count and durability bar, and optionally a colored outline. No input, no storage: it only draws.
ItemDisplay.builder().item(() -> player.getMainHandItem()).size(16, 16)
        .outline(() -> locked ? 0xFFFF5555 : 0)
        .build();

Count and durability overlays show by default, as vanilla draws a slot; hideCount() and hideDurability() turn them off. A size other than 16 scales the item through the pose matrix (items are square: the smaller side is used).

Outline

outline(argb) draws a one-pixel line of that color around the item's own silhouette, read every frame (0 for none). It is SlotRendering.drawItemOutline(GuiGraphicsExtractor, ItemStack, int, int, int), the same primitive a slot decoration uses.
  • Field Details

    • DEFAULT_SIZE

      public static final int DEFAULT_SIZE
      Vanilla's item size.
      See Also:
  • Constructor Details

  • Method Details

    • builder

      public static ItemDisplay.Builder builder()
    • getCurrentStack

      public net.minecraft.world.item.ItemStack getCurrentStack()
      The stack the display would draw right now.
    • layoutWithin

      public void layoutWithin(int budget)
      Description copied from class: AbstractPanelElement
      Caps the live width to the room the panel gives, reversibly.
      Specified by:
      layoutWithin in interface PanelElement
      Overrides:
      layoutWithin in class AbstractPanelElement
      Parameters:
      budget - horizontal pixels available to this element, in panel content space. Always >= 1.
    • fillWidth

      public void fillWidth(int width)
      Description copied from class: AbstractPanelElement
      Column fill: the column's widest extent becomes this element's authored width.
      Specified by:
      fillWidth in interface PanelElement
      Overrides:
      fillWidth in class AbstractPanelElement
      Parameters:
      width - the column's widest-child extent to stretch to, in pixels
    • render

      public void render(RenderContext ctx)
      Description copied from interface: PanelElement
      Renders this element at (ctx.originX() + getChildX(), ctx.originY() + getChildY()). When ctx.disabled() is true, an element draws its disabled look.