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, andwaitForEventforms do not request joined handling; passtrueto 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()returnstruefor 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()replacesjoined()as the listener-side join preference.ScriptTrigger.joinRequestedreplacesjoinedand keeps the saved config key"joined".- New accessors:
SendMessage.getMessage()andsetMessage(String)RecvMessage.getText()andsetText(TextHelper)Title.getMessage()andsetMessage(TextHelper)NameChange.getNewName()andsetNewName(TextHelper)SendPacket/RecvPacket.getPacket()andsetPacket(Packet)SignEdit.shouldCloseScreen(),setShouldCloseScreen(...),isFront(),getSignText(), andsetSignText(...)
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, andnull, an empty string, or cancelling prevents sending.SendPacket/RecvPacket.setPacket(...)replace or drop a packet;nulldrops it. Packet-buffer edits do not affect the packet until the decoded result is assigned withsetPacket(...).RecvMessage.setText(...)marks a changed line asModified; setting it tonullskips the HUD message.SignEdit.setSignText(...)copies the list, uses the first four lines, fills missing entries with empty strings, and treatsnullas 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 asminecraft:fly_one_cm.Player.getStatistics().hasCustomStat(id)reports whether a custom statistic id is registered, with or without theminecraft: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-apitohttps://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
joinedsetting 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(...), andwaitForEvent(...)do not join unless you passtrue. A non-joined listener is not awaited and cannot cancel or change the event.- Joined handling is opt-in for every event: pass
truewhere the event permits it. Custom and non-cancellable events follow the same rule. - Packet events can join, but the simple
JsMacros.on,once, andwaitForEventforms no longer do. Passtrueto cancel or replace a packet; a non-joined packet listener observes the packet asynchronously and cannot change it. EventSendPacket.replacePacket(...)now assigns throughsetPacket(...)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, andwaitForEventis now namedrequestJoined; 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 usedoSubclassClose()orcloseRuntime(...)instead of overriding it.Player.getStatistics().getFormattedStatValue(...)andgetStatText(...)returnnullwhen the key is not ingetStatList()instead of throwing.Player.getStatistics()count getters (getRawStatValue,getCustomStat, and the typed methods such asgetBlockMined) reject unknown ids or keys withIllegalArgumentException. 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.
EventCustomkeeps 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()orJsMacros.disableAllListeners()with no event no longer fails when another thread registers an event name at the same time. SendPacket/RecvPacket.getPacketBuffer()now throwsIllegalStateExceptionwith a clear message when there is no packet, andcanGetPacketBuffer()returnsfalsein 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")andgetCustomFormattedStat(...)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:
withCustomClickEventcallbacks on text added to aHud.createScreenscreen 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. OverridedoSubclassClose()for language teardown, orcloseRuntime(...)to close a runtime that was built but never published. OverridingcloseContext()directly is no longer possible.Replace reads and writes of the fields in the table with their accessors:
Old field New 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 deprecatedtextfield are nullable in the generated typings. Check fornullbefore callinggetString().IEventListener.joined()is deprecated in favour ofIEventListener.joinRequested(). The old method still works, so existing third-party listeners continue to be honoured until 3.0.0.ScriptTrigger.joinedwas renamed tojoinRequested; the saved config key remains"joined", so existing profiles load unchanged. Scripts and extensions that read or settrigger.joinedmust switch totrigger.joinRequested.Listeners that call
event.cancel()or a checked setter must passtruetoJsMacros.on,once, orwaitForEventwhen 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
joinedvalue. A cancellable trigger saved withjoined=falseruns 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 throwsIllegalStateExceptionexplaining that joined handling is required. For a custom event, setjoinableorcancelablebefore dispatch so thetruerequest can take effect. Release the event lock withcontext.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(...)andgetStatText(...)can now returnnullfor a key that is not ingetStatList(). Check the result before using it.Player.getStatistics()count getters throwIllegalArgumentExceptionfor unknown ids or keys instead of reading a registry default. Validate ids, or catch the exception where the id comes from user input. UsehasCustomStat(id)to check a custom id before reading it.
Quick examples
// 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();