Skip to content

JsMacrosCE 2.2.0 ​

Highlights ​

  • Event delivery now separates requesting a join from actually being joined. A listener joins only when it requests joined handling and the event permits it; otherwise it is not awaited and receives a read-only event.
  • Cancellable events no longer force every listener to join. The simple JsMacros.on, once, and waitForEvent forms do not request joined handling; pass true to join when the event permits it and keep cancellation or payload changes working.
  • cancel() and the event setters now check the delivery. They throw when the callback is not joined or has already released its event lock, instead of changing an event the game has already read.
  • Message, title, name, packet, and sign text fields now have getters and setters. The old fields remain available but are deprecated and planned for removal in 3.0.0. BaseEvent.canModify() reports whether the current callback may change the event.
  • The lock watchdog now removes script listeners that hold an event lock too long, not only profile triggers.
  • Extension authors can compile against a published extension-api, and the new extension guide covers installing and building extensions.

Added ​

Event API

  • BaseEvent.canModify() returns true for a joined delivery that still holds its lock, the raising thread during dispatch, and a custom event's creator between dispatches.
  • BaseEventRegistry.isJoinable(event) reports whether dispatch can wait for a listener on that event, including names registered as joinable without a cancellable flag.
  • IEventListener.joinRequested() replaces joined() as the listener-side join preference. ScriptTrigger.joinRequested replaces joined and keeps the saved config key "joined".
  • New accessors:
    • SendMessage.getMessage() and setMessage(String)
    • RecvMessage.getText() and setText(TextHelper)
    • Title.getMessage() and setMessage(TextHelper)
    • NameChange.getNewName() and setNewName(TextHelper)
    • SendPacket/RecvPacket.getPacket() and setPacket(Packet)
    • SignEdit.shouldCloseScreen(), setShouldCloseScreen(...), isFront(), getSignText(), and setSignText(...)
  • JsMacros.macroTriggers() returns the profile macros and key macros from the macro editor, including disabled ones, so a script can inspect them. ScriptTrigger.setEnabled(...) enables or disables one; the macro stays registered and the change is saved with the profile.
  • SendMessage.setMessage(...) replaces the outgoing text; a leading / selects command submission, and null, an empty string, or cancelling prevents sending.
  • SendPacket/RecvPacket.setPacket(...) replace or drop a packet; null drops it. Packet-buffer edits do not affect the packet until the decoded result is assigned with setPacket(...).
  • RecvMessage.setText(...) marks a changed line as Modified; setting it to null skips the HUD message.
  • SignEdit.setSignText(...) copies the list, uses the first four lines, fills missing entries with empty strings, and treats null as four blank lines. getSignText() returns a live, permission-checked list to a joined delivery and an unmodifiable view otherwise.
  • EventCustom.put* methods now throw when the current delivery cannot change the event. EventCustom.getUnderlyingMap() returns a live map view for the creator or a joined delivery, with writes checked when they happen, and an unmodifiable view otherwise.

Statistics

  • Client.getRegistryManager().getCustomStatIds() lists the registered custom statistic ids, such as minecraft:fly_one_cm.
  • Player.getStatistics().hasCustomStat(id) reports whether a custom statistic id is registered, with or without the minecraft: namespace, so scripts can tell an unknown id from a statistic whose counter is zero.

Extensions and documentation

  • Release builds publish com.jsmacrosce.jsmacros:extension-api to https://maven.jsmacrosce.com/releases, so extensions can be built in their own Gradle projects.
  • The new extension guide covers installing an extension, building a library or language extension, and packaging bundled dependencies. The events and threading guide pages also document read-only delivery and the new accessors.

Changed ​

  • The saved joined setting is now only a request. A cancellable event no longer joins listeners that did not ask for it, and a non-joined listener must treat the event as read-only.
  • JsMacros.on(...), once(...), and waitForEvent(...) do not join unless you pass true. A non-joined listener is not awaited and cannot cancel or change the event.
  • Joined handling is opt-in for every event: pass true where the event permits it. Custom and non-cancellable events follow the same rule.
  • Packet events can join, but the simple JsMacros.on, once, and waitForEvent forms no longer do. Pass true to cancel or replace a packet; a non-joined packet listener observes the packet asynchronously and cannot change it.
  • EventSendPacket.replacePacket(...) now assigns through setPacket(...) and is checked like the other setters.
  • Triggers added in the Events tab start non-joined, matching the simple script API. Use the Joined button to opt in. Existing profiles keep their saved setting.
  • The script API flag for JsMacros.on, once, and waitForEvent is now named requestJoined; positional calls are unchanged.
  • Android: the GraalVM engine now uses its interpreter-only runtime. This avoids the startup crash in Pojav and FCL launchers, where Android refuses GraalVM's native attach library, at the cost of slower script execution on those targets.
  • BaseScriptContext.closeContext() is now final and runs language teardown once. Language extensions use doSubclassClose() or closeRuntime(...) instead of overriding it.
  • Player.getStatistics().getFormattedStatValue(...) and getStatText(...) return null when the key is not in getStatList() instead of throwing.
  • Player.getStatistics() count getters (getRawStatValue, getCustomStat, and the typed methods such as getBlockMined) reject unknown ids or keys with IllegalArgumentException. An unknown block or item id was previously read from that registry's default entry.

Fixed ​

  • Script shutdown: stopping a script no longer interrupts Minecraft's render or network thread while a screen widget or event callback is running, deadlocks when a callback finishes during the stop, or leaves a Graal runtime created just before the stop unclosed. Only threads owned by the script are interrupted.
  • EventCustom keeps write access for the script that created the event between dispatches, so one event instance can still be reused for several triggers.
  • Calling JsMacros.disableScriptListeners() or JsMacros.disableAllListeners() with no event no longer fails when another thread registers an event name at the same time.
  • SendPacket/RecvPacket.getPacketBuffer() now throws IllegalStateException with a clear message when there is no packet, and canGetPacketBuffer() returns false in that case.
  • The lock watchdog now calls IEventListener.off() for script listeners as well as profile triggers when a joined delivery does not release its lock in time.
  • Statistics: Player.getStatistics().getCustomStat("minecraft:fly_one_cm") and getCustomFormattedStat(...) no longer fail with a null-pointer error. Custom stats resolve to the registered statistic, so distance and time values use their real formatters.
  • Rendering: Draw2D.addLine(...) draws fractional widths at their requested thickness instead of rounding them up to the next whole pixel. Very thin lines stay at least one physical pixel wide.
  • Screen text: withCustomClickEvent callbacks on text added to a Hud.createScreen screen now run without a loaded world. Previously the click only worked in-game because the handler required a player.

Upgrading ​

  • Extension authors: BaseScriptContext.closeContext() is final. Override doSubclassClose() for language teardown, or closeRuntime(...) to close a runtime that was built but never published. Overriding closeContext() directly is no longer possible.

  • Replace reads and writes of the fields in the table with their accessors:

    Old fieldNew accessors
    event.message (SendMessage)event.getMessage(), event.setMessage(...)
    event.message (Title)event.getMessage(), event.setMessage(...)
    event.text (RecvMessage)event.getText(), event.setText(...)
    event.newName (NameChange)event.getNewName(), event.setNewName(...)
    event.packet (SendPacket, RecvPacket)event.getPacket(), event.setPacket(...)
    event.closeScreen (SignEdit)event.shouldCloseScreen(), event.setShouldCloseScreen(...)
    event.front (SignEdit)event.isFront()
    event.signText (SignEdit)event.getSignText(), event.setSignText(...)

    The deprecated fields still work, but writing them bypasses the joined/read-only check, so a non-joined write can happen after the game has already read the event.

  • RecvMessage.getText() and the deprecated text field are nullable in the generated typings. Check for null before calling getString().

  • IEventListener.joined() is deprecated in favour of IEventListener.joinRequested(). The old method still works, so existing third-party listeners continue to be honoured until 3.0.0.

  • ScriptTrigger.joined was renamed to joinRequested; the saved config key remains "joined", so existing profiles load unchanged. Scripts and extensions that read or set trigger.joined must switch to trigger.joinRequested.

  • Listeners that call event.cancel() or a checked setter must pass true to JsMacros.on, once, or waitForEvent when the event permits joining, or enable Joined on their trigger. Without it the delivery is read-only and the call throws.

  • Existing profiles keep their saved joined value. A cancellable trigger saved with joined=false runs read-only; enable its Joined button if it needs to cancel or change the event.

  • A non-joined delivery must not call cancel() on a cancellable event, EventCustom.put*, or a checked setter. Doing so throws IllegalStateException explaining that joined handling is required. For a custom event, set joinable or cancelable before dispatch so the true request can take effect. Release the event lock with context.releaseLock() only after any changes are made.

  • Extension authors can build in a standalone Gradle project with compileOnly("com.jsmacrosce.jsmacros:extension-api:<version>") from the JsMacrosCE Maven repository. Keep the API JAR out of the extension package; the installed mod supplies it at runtime.

  • Player.getStatistics().getFormattedStatValue(...) and getStatText(...) can now return null for a key that is not in getStatList(). Check the result before using it.

  • Player.getStatistics() count getters throw IllegalArgumentException for unknown ids or keys instead of reading a registry default. Validate ids, or catch the exception where the id comes from user input. Use hasCustomStat(id) to check a custom id before reading it.

Quick examples ​

js
// Observe an event without joining (read-only; this is the default)
JsMacros.on("RecvMessage", JavaWrapper.methodToJava((event) => {
  const text = event.getText();
  if (text !== null) Chat.log(text.getString());
}));

// Join a cancellable event so it can change the payload
JsMacros.on("SendMessage", true, JavaWrapper.methodToJava((event) => {
  if (event.getMessage() === "/hello") {
    event.setMessage("say hello");
  }
}));

// Wait for one event without joining; release the context yourself
const next = JsMacros.waitForEvent("RecvMessage");
const nextText = next.event.getText();
if (nextText !== null) Chat.log(nextText.getString());
next.context.releaseLock();