HeldItemChange
com.jsmacrosce.jsmacros.client.api.event.impl.player.EventHeldItemChange
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
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 benulloldItem: previous raw stack; may benulloffHand:truefor the off hand,falsefor the main hand
Fields
item
The current stack in the changed hand. An empty hand is represented by an empty ItemStackHelper, not
null.offHand
Whether the changed stack is in the off hand;
false indicates the main hand.oldItem
The previous stack in the changed hand; an empty hand is represented by an empty ItemStackHelper, not
null.Methods
toString
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