摘要
- 优化了获取物品时触发进度(advancements)的逻辑;
- 可能会与原版行为产生差异,但不会影响原版进度,也不应影响绝大多数模组/数据包;
- 即使确实影响了某些内容,玩家仍然可以通过丢弃并重新拾取所需物品之一来获得该进度;
- 目前已知没有不兼容或问题;
- 所有对原版代码的注入均可在配置文件中禁用。
- 所有更改均为服务端逻辑。
测试结果
在专用服务器上进行了实时测试,在线活跃玩家 3 人,运行包含超过 200 个模组的自定义 Forge 整合包以及 BlazeandCave's Advancements Pack(添加了超过 950 个进度)。使用 Spark 收集了一小时的统计数据。
使用 Icterine 后,InventoryChangeTrigger 的执行速度提高了约 2.5 倍(截至 1.1.0 版本),占用每个刻时间的比例从 20% 降至约 7.5%。
Icterine 1.0.0 版本的统计对比(速度提升约 2 倍):

原版 InventoryChangeTrigger 的工作原理
- 当游戏检测到玩家背包中的物品堆发生变化时,会调用 InventoryChangeTrigger。这包括拾取物品、丢弃物品、丢弃整组物品以及在背包内移动物品。
- 此外,当你打开容器(箱子、熔炉等)时,游戏会认为你背包中的所有槽位都发生了变化,并为所有槽位(包括空槽位)调用触发器。
- InventoryChangeTrigger 会统计你背包中空槽、非空槽和完全填满的槽的数量。这些信息 可用于进度触发条件,但在原版中并未使用。
- InventoryChangeTrigger 遍历已注册的进度标准(criteria)。
- 如果标准具有槽位数量要求且不匹配第 2 步的值,或者如果标准没有物品要求,则跳过该标准。
- 如果标准只有一个物品要求,则将变化的物品堆与该要求进行比对。
- 如果标准有多个物品要求(例如,“Cover me with debris”需要拥有全套下界合金护甲),则检查背包中的每一个物品堆是否符合每一项要求(但已满足的要求会被移除,不再进行检查)。
- 物品匹配,尤其是针对标签(tag)的匹配,非常耗时。但游戏首先检查玩家的物品类型是否与要求中的类型匹配,然后再检查其他参数如数量、附魔和其他 NBT 数据。
Icterine 的优化原理
- 在第 1 步中,当丢弃整组物品或将它们移出背包(例如放入箱子)时,不调用 InventoryChangeTrigger。由配置文件中的
ignore_triggers_for_emptied_stacks参数控制。 - 类似地,如果物品堆的变化是由减少堆叠数量但未清空它引起的(例如,玩家从满组物品中丢弃了一个物品),则不调用 InventoryChangeTrigger。由
ignore_triggers_for_decreased_stacks控制。 - 同样,如果物品堆数量增加但未达到任何进度的阈值,则不调用 InventoryChangeTrigger。例如,泥土堆的数量从 52 增加到 53,但你的整合包中没有获得 53 个泥土的进度。由
optimize_triggers_for_increased_stacks控制。 - 修改玩家打开容器屏幕时游戏检查物品变化的方式,以便在你打开任何界面时不会立即将所有物品堆视为已变化。由
initialize_inventory_last_slots控制。 - 在第 6 步中,首先检查变化的槽位是否符合任何要求,然后再检查背包中的其他物品堆。由
optimize_multiple_predicate_trigger控制。 - 在第 7 步中,首先比较物品堆数量以避免不必要的标签匹配。同时使用之前的物品堆数量以避免更多的不必要匹配。由
check_count_before_item_predicate_match控制。
未来计划进行更多优化。
支持版本
Icterine v1.2.0 适用于 Minecraft Fabric/Quilt 1.18.2 至 1.19.4,以及 Forge 1.18.2 至 1.19.2 (forge moment)。
Icterine v1.3.0 具有与 v1.2.0 相同的功能,适用于 Fabric/Quilt 1.20 - 1.20.4,Forge 1.19.3 - 1.20.4,以及 NeoForge 1.20.1 - 1.20.4。
请使用 版本页面 上的过滤器选择合适的文件。
如果你需要移植到其他版本,请提交 Issue,或在 Discord 服务器询问。
Summary
- Optimizes triggering advancements for obtaining items;
- Might break parity with vanilla, but doesn't affect vanilla advancements and shouldn't affect the vast majority of mods/datapacks;
- Even if it does affect something, advancement still should be obtainable by just dropping and picking up one of required items;
- Currently, there are no known incompatibilities or issues;
- Every injection into vanilla code can be disabled in config file.
- All changes are server-side.
Results
Live test performed on dedicated server with 3 active players online, running custom Forge modpack with over 200 mods and BlazeandCave's Advancements Pack, which adds over 950 advancements. Stats collected using Spark for one hour.
With Icterine, InventoryChangeTrigger executes almost 2.5 times faster (as of version 1.1.0), spending about 7.5% of the tick time instead of 20%.
Stats comparison for Icterine 1.0.0 (~2 times faster):

How vanilla InventoryChangeTrigger works
- When the game detects that stack in player inventory has changed, it calls InventoryChangeTrigger for it. This includes picking up items, dropping items, dropping whole stacks, moving items in your inventory.
- Also, when you open a container (chest, furnace, etc.), game thinks that all the slots in your inventory changed, and calls trigger for all of them, including empty slots.
- InventoryChangeTrigger counts empty, non-empty and completely filled slots in your inventory. This information could be used in advancement triggers, but is not used in vanilla.
- InventoryChangeTrigger goes over registered advancement criteria.
- If criterion has slot count requirements and they don't match values from step 2, or if criterion doesn't have item requirements, criterion is skipped.
- If criterion has only one item requirement, changed stack is checked against this requirement.
- If criterion has multiple items requirements (e.g., "Cover me with debris" requires having full netherite armor set), every item stack in the inventory is checked against every requirement (but fulfilled requirements get removed and are no longer checked).
- Item matching, especially against tag, is very heavy. But the game first checks if the player's item type matches the one from the requirement, and only then checks other parameters like count, enchants and other NBT data.
How Icterine's optimizations work
- In step 1, do not call InventoryChangeTrigger when you drop stacks or move them out of your inventory (e.g. to chest). This is controlled by the
ignore_triggers_for_emptied_stacksparameter in config file. - Similarly, do not call InventoryChangeTrigger if stack change was caused by decreasing stack but not emptying it (e.g. player dropped single item from the full stack). Controlled by
ignore_triggers_for_decreased_stacks. - And also do not call InventoryChangeTrigger if stack size increased, but hasn't passed threshold for any advancement. For example, dirt stack size increased from 52 to 53, but there's no advancement for getting 53 dirt in your modpack. Controlled by
optimize_triggers_for_increased_stacks. - Modify how game checks for changed items when player opens container screen, so it doesn't treat all the stack as changed the second you open anything. Controlled by
initialize_inventory_last_slots. - In step 6, firstly check if changed slot matches any requirement, and only then check other stack in the inventory. Controlled by
optimize_multiple_predicate_trigger. - In step 7, compare the stack count first to avoid unneeded tag matching. Also use previous stack count to avoid even more unneeded matching. Controlled by
check_count_before_item_predicate_match.
Further optimizations are planned.
Supported versions
Icterine v1.2.0 works with Minecraft Fabric/Quilt from 1.18.2 to 1.19.4, and Forge from 1.18.2 to 1.19.2 (forge moment).
Icterine v1.3.0 has the same features as v1.2.0 and works with Fabric/Quilt 1.20 - 1.20.4, Forge 1.19.3 - 1.20.4, and NeoForge 1.20.1 - 1.20.4.
Use filter on the versions page to choose the right file.
If you need port to any other version, please open an issue, or ask on Discord server.
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
下载 Icterine
已移植至 1.19.3、1.19.4、1.20、1.20.1、1.20.2、1.20.3、1.20.4!支持 Fabric、Quilt、Forge、NeoForge!
Icterine 现已兼容 1.18.2 至 1.20.4 之间的所有版本。
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
缓冲的原始输入和线程化的事件轮询
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
原版世界生成优化模组
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
查看物品与配方
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
评论 0
登录后参与评分
还没有评论,来抢沙发吧