Skip to content

Item ​

com.jsmacrosce.jsmacros.client.api.classes.render.components.Item

Since1.0.5

Draws an item stack using its model in a 16-by-16 GUI-pixel box; scale changes its reported dimensions, and rotation affects drawing. The element's color does not tint the icon. Optional game decorations (durability bar, cooldown, and count or custom text) are disabled by default; a null stack draws nothing.

The world-space surface path flattens the item's model depth. In the GUI-context path,
versions newer than Minecraft 1.21.5 use the same item-drawing call for render3D as for render; the older 3D-matrix path also adjusts model depth.

js
const draw = Hud.createDraw2D();  
draw.itemBuilder().item("minecraft:diamond").pos(10, 10).buildAndAdd();  
draw.register();

Available in scripts as RenderElements.Item.

Nested types ​

Constructors ​

new Item ​

new Item(int x, int y, int zIndex, String id, boolean overlay, double scale, float rotation)#
Constructs an icon using the default instance of the identified item. Bare names use the minecraft namespace; an unknown item id resolves to the registry's default item (air in Minecraft 1.21.8). Finite rotations are normalized to [-180, 180).

Parameters:

  • x: the x position
  • y: the y position
  • zIndex: the z-index against the other elements on the overlay
  • id: the item to draw, with the namespace optional
  • overlay: whether to draw the game's decorations over the icon
  • scale: the scale to apply
  • rotation: the rotation in degrees, normalized to [-180, 180)
new Item(int x, int y, int zIndex, ItemStackHelper i, boolean overlay, double scale, float rotation)#
Constructs an icon from a stack, leaving overlay text null so the stack count is shown when greater than one if the overlay is enabled.

Parameters:

  • x: the x position
  • y: the y position
  • zIndex: the z-index against the other elements on the overlay
  • i: the stack whose icon to draw
  • overlay: whether to draw the game's decorations over the icon
  • scale: the scale to apply
  • rotation: the rotation in degrees, normalized to [-180, 180)
new Item(int x, int y, int zIndex, ItemStackHelper itemStack, boolean overlay, double scale, float rotation, String ovText)#
Constructs an icon from a stack with optional overlay text, which replaces rather than supplements the stack count. A null text uses the count instead.

Parameters:

  • x: the x position
  • y: the y position
  • zIndex: the z-index against the other elements on the overlay
  • itemStack: the stack whose icon to draw
  • overlay: whether to draw the game's decorations over the icon
  • scale: the scale to apply
  • rotation: the rotation in degrees, normalized to [-180, 180)
  • ovText: the text to draw over the icon, or null for the count

Fields ​

item ​

the stack whose icon is drawn, or null for no icon.

overlay ​

overlay: boolean#
whether the game's decorations (bar, cooldown, and count or custom text) are drawn. Defaults to the constructor argument, or false in a builder.

ovText ​

ovText: String#
the custom text drawn when the overlay is on, or null to use the stack count. Builders initialize this to an empty string, which requests an empty label.

parent ​

parent: IDraw2D<?>#
the overlay this icon belongs to, or null when unbound. Parent dimensions come from this overlay and fall back to the window when it is null.

rotateCenter ​

rotateCenter: boolean#
whether rotation is about the icon's center; defaults to false for direct construction and true for builder-created icons.

rotation ​

rotation: float#
the rotation in degrees. Constructors and setters normalize finite angles to [-180, 180); direct field writes do not.

scale ​

scale: double#
the scale applied to the fixed 16-by-16 icon; builders default to 1. Negative values are accepted on the element but rejected by its builder.

x ​

x: int#
the x position of this icon, which is the top left of its 16 by 16 box.

y ​

y: int#
the y coordinate of the icon's top-left position.

zIndex ​

zIndex: int#
The overlay draw-order value for this icon; lower values are drawn first.

Methods ​

getItem ​

getItem(): ItemStackHelperSince1.2.0#
Returns the icon's stack wrapped as a helper.
Returns: the stack being drawn, as a helper

getOverlayText ​

getOverlayText(): StringSince1.8.4#
Returns the custom overlay label, or null when the stack count is used.
Returns: the overlay text of this item.

getParentHeight ​

getParentHeight(): int#
Returns the parent overlay's height, or the window's GUI-scaled height when no parent is set.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the parent overlay's width, or the window's GUI-scaled width when no parent is set.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns the stored rotation in degrees. Constructors and setters normalize it; direct writes to the public field do not.
Returns: the rotation of this item.

getScale ​

getScale(): doubleSince1.8.4#
Returns the scale applied to the icon's 16-by-16 base size.
Returns: the scale of this item.

getScaledHeight ​

getScaledHeight(): int#
Returns the icon's scaled height, computed as (int) (scale * 16) (truncated toward zero).
Returns: the scaled height of this element

getScaledLeft ​

getScaledLeft(): int#
Returns the icon's x position; scaling changes its rendered size, not this position.
Returns: the icon's x position

getScaledTop ​

getScaledTop(): int#
Returns the icon's y position; scaling changes its rendered size, not this position.
Returns: the icon's y position

getScaledWidth ​

getScaledWidth(): int#
Returns the icon's scaled width, computed as (int) (scale * 16) (truncated toward zero).
Returns: the scaled width of this element

getX ​

getX(): intSince1.8.4#
Returns the x coordinate of the icon's box; scaling does not change this position.
Returns: the x position of this element.

getY ​

getY(): intSince1.8.4#
Returns the icon's y coordinate; scaling does not change its position.
Returns: the y position of this element.

getZIndex ​

getZIndex(): int#
Returns this element's z-index; lower values are drawn first.
Returns: the z-index of this element

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether rotation is about the icon's center. Directly constructed icons default to false; builder-created icons default to true.
Returns: true if this item should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Item#
Sets this icon's position. Scaling and rotation settings are unchanged.

Parameters:

  • x: the new x position
  • y: the new y position
Returns: self for chaining.

render ​

render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#
Renders this icon using its position, scale, and rotation. The overlay calls this method; a null item draws nothing. Mouse coordinates and frame delta are unused.

Parameters:

  • drawContext: the graphics context to draw into
  • mouseX: the mouse x, not used by this element
  • mouseY: the mouse y, not used by this element
  • delta: the frame delta, not used by this element

setItem ​

setItem(ItemStackHelper i): ItemSince1.0.5#
Sets the icon's stack, or clears the icon when i is null. The helper's underlying stack is used without copying.

Parameters:

  • i: the stack to draw, or null for nothing
Returns: self for chaining.
setItem(String id, int count): ItemSince1.0.5#
Replaces the icon's stack with a newly constructed stack for the given id and count. Bare names use the minecraft namespace; unknown ids resolve to the registry's default item (air in Minecraft 1.21.8).

Parameters:

  • id: the item to draw, with the namespace optional
  • count: the new stack count
Returns: self for chaining.

setOverlay ​

setOverlay(boolean overlay): ItemSince1.2.0#
Enables or disables item decorations. In 2D rendering these include the game's durability bar, cooldown overlay, and stack count or custom text; the custom 3D surface renderer draws the bar and count or text, but not the cooldown overlay. Builder-created icons start with empty overlay text, so set text separately if a label is wanted.

Parameters:

  • overlay: whether to draw the decorations
Returns: self for chaining.

setOverlayText ​

setOverlayText(String ovText): ItemSince1.2.0#
Sets the text used for the overlay label; this does not enable the overlay. When enabled, a non-null value replaces the stack count.

Parameters:

  • ovText: the text to draw over the icon
Returns: self for chaining.

setParent ​

setParent(IDraw2D<?> parent): Item#
Sets the overlay parent used for parent-relative alignment and dimensions. A null parent makes dimensions fall back to the window.

Parameters:

  • parent: the overlay this element is on, or null for the window
Returns: self for chaining.

setPos ​

setPos(int x, int y): ItemSince1.0.5#
Sets both coordinates without changing the stack.

Parameters:

  • x: the new x position
  • y: the new y position
Returns: self for chaining.

setRotateCenter ​

setRotateCenter(boolean rotateCenter): ItemSince1.8.4#
Sets whether rotation is about the center of the 16-by-16 icon box rather than its top-left position.

Parameters:

  • rotateCenter: whether the item should be rotated around its center
Returns: self for chaining.

setRotation ​

setRotation(double rotation): ItemSince1.2.6#
Sets the rotation in degrees, wrapping finite float-converted angles to [-180, 180); for example, 450 becomes 90. Constructors apply the same wrapping.

Parameters:

  • rotation: the angle in degrees
Returns: self for chaining.

setScale ​

setScale(double scale): ItemSince1.2.6#
Sets the icon scale. The base size is 16 by 16; zero is rejected, but negative values are accepted here (the builder rejects them).

Parameters:

  • scale: the scale to apply
Returns: self for chaining.

setX ​

setX(int x): ItemSince1.8.4#
Sets the icon's x position without changing its y position.

Parameters:

  • x: the new x position of this element
Returns: self for chaining.

setY ​

setY(int y): ItemSince1.8.4#
Sets the icon's y position without changing its x position.

Parameters:

  • y: the new y position of this element
Returns: self for chaining.

setZIndex ​

setZIndex(int zIndex): ItemSince1.8.4#
Sets this element's z-index; lower values are drawn first.

Parameters:

  • zIndex: the new z-index for this item
Returns: self for chaining.

shouldShowOverlay ​

shouldShowOverlay(): booleanSince1.8.4#
Returns whether the game's item decorations are enabled. This flag alone does not guarantee visible decoration; for example, a builder's default empty text draws no count label.
Returns: true if decorations are enabled; false otherwise.