Skip to content

HeldItemChange ​

com.jsmacrosce.jsmacros.client.api.event.impl.player.EventHeldItemChange

Since1.2.7Not cancellable

Fires when polling detects a change to the local player's main- or off-hand stack, at most once per client tick. It does not fire for an empty-to-empty transition. If only damage changes,
EventItemDamage fires first.

js
JsMacros.on("HeldItemChange", JavaWrapper.methodToJava(function (event) {
  const hand = event.offHand ? "off hand" : "main hand";  
  const now = event.item.isEmpty() ? "empty" : `${event.item.getItemId()} x${event.item.getCount()}`;  
  const before = event.oldItem.isEmpty() ? "empty" : `${event.oldItem.getItemId()} x${event.oldItem.getCount()}`;  
  Chat.log(`${hand}: ${before} to ${now}`);  
}))

Constructors ​

new EventHeldItemChange ​

new EventHeldItemChange(ItemStack item, ItemStack oldItem, boolean offHand)#
Wraps the supplied current and previous raw stacks and records which hand they describe. This constructor does not detect or dispatch a hand change. Each argument is retained as the corresponding helper's raw value; a null stack therefore produces a non-null helper wrapping null.

Parameters:

  • item: current raw stack; may be null
  • oldItem: previous raw stack; may be null
  • offHand: true for the off hand, false for the main hand

Fields ​

item ​

item: ItemStackHelperread-only#
The current stack in the changed hand. An empty hand is represented by an empty ItemStackHelper, not null.

offHand ​

offHand: booleanread-only#
Whether the changed stack is in the off hand; false indicates the main hand.

oldItem ​

oldItem: ItemStackHelperread-only#
The previous stack in the changed hand; an empty hand is represented by an empty ItemStackHelper, not null.

Methods ​

toString ​

toString(): String#
Formats the event name and current stack helper as %s:{"item": %s}; the previous stack and hand indicator are omitted. Formatting dereferences the current raw stack, so a current stack wrapped from null causes a NullPointerException.
Returns: the formatted event name and current stack representation