JsMacros Community Edition (JsMacrosCE)
JsMacrosCE 允许你编写并运行客户端脚本,以自动化任务并在 Minecraft 中构建自定义工具。 你可以触发宏、响应事件,并在游戏中构建自己的工作流。你还可以 直接与 Java 运行时交互,因此当你需要比简单命令更强大的功能时,你的脚本可以与客户端环境紧密集成。
语言支持与扩展
JsMacrosCE 支持多种脚本语言,并可通过扩展进行扩充:
- JavaScript(原生支持)
- Python(通过扩展)
- 即将推出: Lua、Ruby 等
链接
- 源码 / 问题反馈:
- 文档:
- Discord:
为什么选择 JsMacrosCE
- 社区维护的版本最高至 26.3(上游版本目前最高为 1.21.1)
- 更新了玩家脚本 API(请参阅文档)
- 持续的维护与修复
Fork 与许可协议 (MPL-2.0)
JsMacrosCE 是 wagyourtail 开发的 JsMacros 的一个分支,根据 MPL-2.0 许可证分发。
源代码公开:
致谢
JsMacrosCE 建立在 JsMacros 项目及其贡献者的工作基础之上。我向原始开发者 wagyourtail 致以敬意,感谢他所付出的努力。
JsMacros Community Edition (JsMacrosCE)
JsMacrosCE lets you write and run client-side scripts to automate tasks and build custom tools in Minecraft. You can trigger macros, react to events, and build your own workflow in-game. You can also interact directly with the Java runtime, so your scripts can integrate tightly with the client environment when you need more power than simple commands.
Language support and extensions
JsMacrosCE supports multiple scripting languages and can be expanded through extensions:
- JavaScript (native)
- Python (via extension)
- Soon: Lua, Ruby, and more
Links
- Source / Issues:
- Documentation:
- Discord:
Why JsMacrosCE
- Community-maintained builds up to 26.3 (upstream currently up to 1.21.1)
- Updated player scripting API (see documentation)
- Ongoing maintenance and fixes
Fork & license (MPL-2.0)
JsMacrosCE is a fork of JsMacros by wagyourtail, distributed under MPL-2.0.
Source code is public:
Acknowledgements
JsMacrosCE builds on the work of the JsMacros project and its contributors. I bow my head to the original developer, wagyourtail, for the effort he put in.
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 JsMacros Community Edition
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
JsMacrosCE 2.3.0,适用于 Minecraft 26.1.2 的 NeoForge。 来源:
亮点
- 脚本现在可以分别读取物品组件的默认值和按栈(per-stack)修改的值。类型化的 getter 无需查询组件 ID 即可暴露耐久度、容器内容物、药水效果等信息。
- 锻造台脚本可以通过名称读取各个输入项,
getOutput()返回锻造台显示的结果。 - 库存辅助功能现在报告实际的槽位位置,并暴露玩家合成网格的所有四个格子。
- 高炉和烟熏炉使用现有的熔炉辅助功能。 Crafter(自动合成器)和坐骑的槽位映射反映了其实际菜单。
- 在 Minecraft 26.2 和 26.3 中,岩浆怪再次与
EntityHelpers.Slime匹配。
新增
物品栈
stack.getComponents()读取物品栈的有效组件,包括从物品继承的默认值。当存在时,getMaxDamage()和getDamage()返回数值;不存在时返回null。getCustomData()读取附加在物品栈上的任意 NBT。getBundleContents()读取 bundle(聚拢袋)的物品、充盈度和选择状态。getContainerContents()在存储型容器(如潜影盒)中保留槽位位置。getPotionContents()读取药水及溅射药水的基底药水、效果和颜色。getFood()、getConsumable()和getUseRemainder()读取物品栈的营养值、消耗设置与效果,以及使用后剩余的物品。getWrittenBookContents()读取已签名书的元数据和格式化页面。getWritableBookContents()读取书与笔的纯文本页面。getStoredEnchantments()读取附魔书中存储的附魔。getFireworks()和getFireworkExplosion()读取火箭飞行持续时间以及爆炸的形状、颜色、轨迹和闪烁效果。getTool()、getAttributeModifiers()和getUseCooldown()暴露挖掘规则、属性修饰器和配置的冷却时间。getEquippable()读取装备槽位、穿戴外观和装备规则。getArmorTrim()、getDyedColor()和getCustomModelData()暴露物品栈的外观设置。getLodestoneTracker()读取指南针保存的目标位置、维度及追踪标志。getMapId()读取已填充地图的数字 ID。- 在 Minecraft 26.3 及更高版本中,
getCookingFuel()和getBrewingFuel()读取熔炉和酿造台的燃料设置,包括由数据包数字提供程序提供的值。 - 使用
getIds()、has(id)和get(id)通过 ID 进行组件查找。使用getChanges()分别读取保存的添加、覆盖和移除操作。
库存
Inventories.Smithing具有用于三个锻造输入的getTemplate()、getBase()和getAddition()。Inventory.getScreenPos()返回 GUI 缩放坐标下库存面板的左上角。
更改
SmithingInventory.getOutput()现在返回槽位 3 中的结果。此前它返回槽位 2 中的附加输入项。Inventory.getSlotPos(slot)现在返回所选槽位在 GUI 缩放坐标下的左上角。此前无论槽位如何,它都返回面板原点。PlayerInventory.getInput()现在将 2×2 合成网格作为[column][row]返回。其宽度和高度均为 2,合成槽位数量为 4。对于超出网格范围的坐标,getInput(x, y)会抛出IndexOutOfBoundsException。- 没有更具体辅助功能的生物现在匹配
EntityHelpers.Mob,因此脚本可以读取它们的攻击性和无 AI 标志。 ItemStackHelper.getNBT()已被弃用,并从生成的参考文档和类型定义中省略。现有脚本仍可在运行时调用它以获取相同的编码组件变更。
修复
Player.openInventory()和OpenContainer事件现在为高炉和烟熏炉返回Inventories.Furnace包装器,使脚本能够访问与普通熔炉相同的燃料、进度和配方书方法。- Crafter(自动合成器)的槽位映射现在保持
main和hotbar与玩家库存对齐。使用getSlots("input")获取 3×3 网格,使用getSlots("preview")获取无法取走的配方预览。 - 马匹库存检查和槽位映射现在遵循菜单中启用的鞍具和护甲槽位。在 Minecraft 1.21.11 及更高版本中,通用的鹦鹉螺壳库存也会在启用时映射这些槽位。
- 在 Minecraft 26.2 和 26.3 中,岩浆怪再次通过
EntityHelpers.Slime暴露getSize()和isSmall()。
升级
更新依赖之前返回值的脚本:
| 如果脚本使用了… | 请使用… |
|---|---|
锻造台 getOutput() 读取附加输入项 |
getAddition() |
getSlotPos(slot) 读取库存面板原点 |
getScreenPos() |
锻造台的 getLeftInput() 和 getRightInput() 仍然有效,但已被弃用,并计划于 3.0.0 版本中移除。请分别将其替换为 getTemplate() 和 getBase()。那些曾通过 workaround 解决 Crafter 玩家槽位索引偏移问题的脚本,现在可以直接使用 getSlots("main") 和 getSlots("hotbar")。
将 stack.getNBT() 替换为 stack.getComponents().getChanges() 以读取保存的变更。如果没有变更,新方法返回空复合标签(compound);如果某个变更无法编码,则返回 null。如果脚本曾使用 null 表示“未更改”,请检查返回的复合标签上 getKeys() 是否为空。
JsMacrosCE 2.2.0 for fabric on Minecraft 1.21.8. Source:
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
- 保存的
joined设置现在仅作为请求。不可取消的事件不再加入未主动请求的监听器,而未加入的监听器必须将该事件视为只读。 JsMacros.on(...)、once(...)和waitForEvent(...)除非传入true,否则不会加入。未加入的监听器不会被等待,也无法取消或更改事件。- 所有事件的加入处理均为可选:在事件允许的地方传入
true。自定义事件和不可取消的事件遵循相同的规则。 - 数据包事件可以加入,但简单的
JsMacros.on、once和waitForEvent形式不再默认加入。如需取消或替换数据包,请传入true;未加入的数据包监听器异步观察数据包,无法更改它。 EventSendPacket.replacePacket(...)现在通过setPacket(...)进行赋值,并像其他 setter 一样进行检查。- 在“Events”选项卡中添加的触发器默认处于未加入状态,与简单脚本 API 保持一致。使用 Joined 按钮选择加入。现有配置保留其已保存的设置。
JsMacros.on、once和waitForEvent的脚本 API 标志现在命名为requestJoined;位置参数调用方式保持不变。- Android:GraalVM 引擎现在使用仅解释器运行时。这避免了 Pojav 和 FCL 启动器中的启动崩溃问题(因为 Android 拒绝 GraalVM 的原生附加库),代价是在这些目标平台上脚本执行速度变慢。
BaseScriptContext.closeContext()现在是 final 方法,且仅运行一次语言清理。语言扩展应使用doSubclassClose()或closeRuntime(...),而不是重写此方法。Player.getStatistics().getFormattedStatValue(...)和getStatText(...)当键不在getStatList()中时返回null,而非抛出异常。Player.getStatistics()的计数获取方法(包括getRawStatValue、getCustomStat以及如getBlockMined等类型化方法)对于未知的 ID 或键会抛出IllegalArgumentException。之前,未知方块或物品 ID 会从该注册表的默认条目中读取。
修复
- 脚本关闭:停止脚本不再在屏幕小部件或事件回调正在运行时中断 Minecraft 的渲染或网络线程,不再因回调在停止期间结束而导致死锁,也不再留下仅在停止前创建的 Graal 运行时未关闭的情况。仅中断属于脚本拥有的线程。
EventCustom在分派之间为创建该事件的脚本保留写入权限,因此一个事件实例仍可用于多个触发器。- 当另一个线程同时注册事件名称时,调用无事件参数的
JsMacros.disableScriptListeners()或JsMacros.disableAllListeners()不再失败。 - 当没有数据包时,
SendPacket/RecvPacket.getPacketBuffer()现在抛出带有清晰消息的IllegalStateException,并且此时canGetPacketBuffer()返回false。 - 锁看门狗现在在加入分发未能及时释放锁时,对脚本监听器和配置文件触发器都调用
IEventListener.off()。 - 统计数据:
Player.getStatistics().getCustomStat("minecraft:fly_one_cm")和getCustomFormattedStat(...)不再因空指针错误而失败。自定义统计解析为注册的统计项,因此距离和时间值使用其真实格式化器。 - 渲染:
Draw2D.addLine(...)按请求的粗细绘制分数宽度,而不是将其向上舍入到下一个整像素。极细的线条至少保持一个物理像素宽。 - 屏幕文本:添加到
Hud.createScreen屏幕的文本上的withCustomClickEvent回调现在无需加载世界即可运行。之前点击仅在游戏中的有效,因为处理器需要玩家。
升级
-
扩展作者:
BaseScriptContext.closeContext()是 final 方法。如需进行语言清理,请重写doSubclassClose();如需关闭已构建但未发布的运行时,请使用closeRuntime(...)。直接重写closeContext()已不再可行。 -
将表中字段的读写替换为其访问器:
旧字段 新访问器 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(...)已弃用的字段仍然有效,但写入它们会绕过加入/只读检查,因此在游戏已经读取事件后可能发生非加入写入。
-
生成的类型定义中,
RecvMessage.getText()和已弃用的text字段可能为null。在调用getString()之前请检查是否为null。 -
IEventListener.joined()已被弃用,推荐使用IEventListener.joinRequested()。旧方法仍然有效,因此现有的第三方监听器将继续被保留,直到版本 3.0.0。 -
ScriptTrigger.joined已重命名为joinRequested;保存的配置键仍为"joined",因此现有配置文件加载时不会改变。读取或设置trigger.joined的脚本和扩展程序必须切换为使用trigger.joinRequested。 -
如果监听器调用了
event.cancel()或经过检查的设置器(checked setter),当事件允许加入时,必须在JsMacros.on、once或waitForEvent中传入true,或者在其触发器上启用 Joined。否则,事件交付将是只读的,调用将抛出异常。 -
现有配置文件会保留其保存的
joined值。以joined=false保存的可取消触发器将以只读方式运行;如果该触发器需要取消或更改事件,请启用其 Joined 按钮。 -
非加入状态的交付不得对可取消事件调用
cancel(),不得调用EventCustom.put*,也不得调用经过检查的设置器。这样做会抛出IllegalStateException,说明需要进行加入处理。对于自定义事件,请在分发前设置joinable或cancelable,以便使true请求生效。仅在完成任何更改后,才通过context.releaseLock()释放事件锁。 -
扩展作者可以使用 JsMacrosCE Maven 仓库中的
compileOnly("com.jsmacrosce.jsmacros:extension-api:<version>")在独立的 Gradle 项目中构建扩展。请勿将 API JAR 包含在扩展包中;安装的模组会在运行时提供它。 -
Player.getStatistics().getFormattedStatValue(...)和getStatText(...)现在对于不在getStatList()中的键可能返回null。在使用结果之前请进行检查。 -
Player.getStatistics()的数量获取器对于未知的 ID 或键将抛出IllegalArgumentException,而不再读取注册表默认值。请验证 ID,或在 ID 来自用户输入的地方捕获异常。在读取之前,请使用hasCustomStat(id)检查自定义 ID。
快速示例
// 观察一个事件而不加入(只读模式;这是默认行为)
JsMacros.on("RecvMessage", JavaWrapper.methodToJava((event) => {
const text = event.getText();
if (text !== null) Chat.log(text.getString());
}));
// 加入一个可取消的事件,以便修改其载荷
JsMacros.on("SendMessage", true, JavaWrapper.methodToJava((event) => {
if (event.getMessage() === "/hello") {
event.setMessage("say hello");
}
}));
// 等待一个事件而不加入;自行释放上下文
const next = JsMacros.waitForEvent("RecvMessage");
const nextText = next.event.getText();
if (nextText !== null) Chat.log(nextText.getString());
next.context.releaseLock();
JsMacrosCE 2.0.0-beta.6,适用于 Minecraft 1.21.8 的 NeoForge。 来源:
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
AE2:一款流行的自动化与存储模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧