Item
com.jsmacrosce.jsmacros.client.api.classes.render.components.Item
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
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 positiony: the y positionzIndex: the z-index against the other elements on the overlayid: the item to draw, with the namespace optionaloverlay: whether to draw the game's decorations over the iconscale: the scale to applyrotation: 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 positiony: the y positionzIndex: the z-index against the other elements on the overlayi: the stack whose icon to drawoverlay: whether to draw the game's decorations over the iconscale: the scale to applyrotation: 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 positiony: the y positionzIndex: the z-index against the other elements on the overlayitemStack: the stack whose icon to drawoverlay: whether to draw the game's decorations over the iconscale: the scale to applyrotation: the rotation in degrees, normalized to[-180, 180)ovText: the text to draw over the icon, ornullfor the count
Fields
item
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
parent
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
Returns the icon's stack wrapped as a helper.
Returns: the stack being drawn, as a helper
getOverlayText
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
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
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
Returns the x coordinate of the icon's box; scaling does not change this position.
Returns: the x position of this element.
getY
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
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
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 intomouseX: the mouse x, not used by this elementmouseY: the mouse y, not used by this elementdelta: the frame delta, not used by this element
setItem
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, ornullfor nothing
Returns: self for chaining.
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 optionalcount: the new stack count
Returns: self for chaining.
setOverlay
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
setParent
setPos
setRotateCenter
setRotation
setScale
setX
setY
setZIndex
shouldShowOverlay
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.