Skip to content

Port math lib and registrum alias api to 1.21.4 移植数学库和注册库别名API到1.21.4 - #130

Merged
WhereisFff merged 5 commits into
Anvil-Dev:dev/1.21.4from
QiuShui1012:port/1.21.4
Sep 28, 2026
Merged

WhereisFff merged 5 commits into
Anvil-Dev:dev/1.21.4from
QiuShui1012:port/1.21.4

Conversation

@QiuShui1012

Copy link
Copy Markdown
Contributor

No description provided.

QiuShui1012 and others added 2 commits September 25, 2026 12:20
Cherry-pick of 7285ae1 (Add math lib 添加数学库 (Anvil-Dev#122)) adapted to 1.21.4:
- javax.annotation nullness instead of jspecify @NullMarked
- ResourceLocation instead of Identifier
- 1.21.4-style module build script
Cherry-pick of 892ef23 (Add alias api for Registrum 向Registrum加入别名API (Anvil-Dev#128)) adapted to this version.
@Gugle2308

Copy link
Copy Markdown

⚠️ Dangerous command requires approval:

cd /tmp && cat > /tmp/ex.sh <<'EOF'
#!/bin/bash
# usage: ex.sh <path> [maxlines]
awk -v t="$1" 'BEGIN{p=0} /^diff --git /{p=($0 ~ " b/"t"$")} p' /tmp/pr130.diff | head -${2:-200}
EOF
chmod +x /tmp/ex....

Reason: shell execution via heredoc

Reply /approve to execute, /approve session to approve this pattern for the session, /approve always to approve permanently, or /deny to cancel.

@Gugle2308

Copy link
Copy Markdown

⚠️ Dangerous command requires approval:

cd /tmp && rm -rf x26 x1211 && mkdir x26 x1211 && tar xzf anvillib-26.1.tgz -C x26 && tar xzf anvillib-1211.tgz -C x1211 && ls x26 x1211 && echo "--- 26.1 math files ---" && find x26 -path "*module.ma...

Reason: recursive delete

Reply /approve to execute, /approve session to approve this pattern for the session, /approve always to approve permanently, or /deny to cancel.

@Gugle2308

Copy link
Copy Markdown

🌿 Roseau API Breaking Change Report

Module Status Breaking Changes
codec ✅ Compatible 0
collision ✅ Compatible 0
cube ✅ Compatible 0
config ✅ Compatible 0
integration ✅ Compatible 0
moveable-entity-block ✅ Compatible 0
network ✅ Compatible 0
rendering ⚪ Skipped —
space-select ⚪ Skipped —
font ✅ Compatible 0
util ⚪ Skipped —
explosion ⚪ Skipped —
rpc ⚪ Skipped —
math ⚪ Skipped —
multiblock ⚪ Skipped —
recipe ⚪ Skipped —
registrum ⚪ Skipped —
sync ⚪ Skipped —
wheel ⚪ Skipped —
main ⚪ Skipped —

Full CSVs: see the Artifacts section of this workflow run.

@Gugle2308

Copy link
Copy Markdown

⚠️ Dangerous command requires approval:

mkdir -p /tmp/x26 /tmp/x1211 && tar xzf /tmp/anvillib-26.1.tgz -C /tmp/x26 && tar xzf /tmp/anvillib-1211.tgz -C /tmp/x1211 && ls /tmp/x26 /tmp/x1211

Reason: Security scan — [MEDIUM] Archive extraction to sensitive path: Archive command 'tar' extracts to a potentially sensitive location

Reply /approve to execute, /approve session to approve this pattern for the session, /approve always to approve permanently, or /deny to cancel.

@Gugle2308

Copy link
Copy Markdown

代码审查摘要 — PR #130

操作: opened(非 closed/labeled,正常审查)
范围: 48 个文件(38 Java / 37 新增 / 0 删除)/ 7,065 行 diff(+6557 / −4),70 个 hunk,无 ghost/EOF 缺失,API changed_files=48 与 diff 头部一致(无截断)
提交: 2 个 — 2c7140d4 port(math)、b8363c38 port(registrum);base f8abc424 = dev/1.21.4 tips

📋 移植来源核对(与来源分支逐字节比对)

内容 来源 结果
module.math 37 个文件 dev/1.21.1(PR #122 / 7285ae13) 29 个完全一致;8 个差异均为 1.21.4 适配(见下);文件集合与来源 module.math 完全相同,无漏移植
其中 8 个差异 — build.gradle(版本号、data()→clientData())、IFunction(getHolderOrThrow→getOrThrow)、MathTestBootstrap/CustomFunctionTest/FlatExpressionTest/MathFlatAssertions/ParseCacheTest(asLookup()→注册表本身、registry()→lookup()、补 freeze()、重复键反射改绑)
registrum 别名 API(6 文件) dev/1.21.1(PR #128 / 892ef231) addAlias/applyAliases + 4 个 addAliases 覆盖方法与来源逐字节相同
dev/26.1 — 26.1 没有别名 API,module.math 在 26.1 是 jspecify/Identifier 那一套 → 本次来源确为 1.21.1 线,方向正确

🔴 关键(阻塞合并)

module.math/build.gradle:287-303 — 从 module.util 复制来的测试任务残留,会打断 build/CI

sourceSets { test { compileClasspath += sourceSets.main.compileClasspath; runtimeClasspath += sourceSets.main.compileClasspath } }
tasks.register('runShapeUtilJoinTimingTest', JavaExec) { mainClass = 'dev.anvilcraft.lib.v2.util.ShapeUtilJoinTimingTest' }
tasks.named('check') { dependsOn tasks.named('runShapeUtilJoinTimingTest') }
  • 这三段与 dev/1.21.4 的 module.util/build.gradle:274-291 逐字相同;ShapeUtilJoinTimingTest 位于 module.util/src/test/java/...(src/main 里 404),而 math 只依赖 util 的 main 产物(jarJar(implementation project(":anvillib-util-neoforge-1.21.4"))),util 的测试类不在 math 的 test runtimeClasspath 上 → mainClass 找不到,JavaExec 非零退出。
  • CI 步骤就是 ./gradlew :anvillib-math-neoforge-1.21.4:build(.github/workflows/build_and_test.yml),build 依赖 check → 该模块必挂;本地 gradlew build 同理。
  • 来源分支 dev/1.21.1 的 math build.gradle 没有这三段(本次移植引入,与 commit 里"1.21.4-style module build script"的说法对应:脚本是以 1.21.4 现有模块为模板抄的)。
  • 修法:删除这三段即可(sourceSets 块对 math 也不需要,MC 依赖已由已有的 addModdingDependenciesTo(sourceSets.test) 提供,JUnit 由 useJUnitPlatform() + junit-bom 提供)。

⚠️ 警告

  • README.en.md 未同步 — 中文 README 增加了 Features 表里的 Math 行、### Math 模块 章节、Groovy/Kotlin 两处 anvillib-math-neoforge-1.21.4 依赖、模块 id 列表里的 math;英文 README 的 Features 表、Module Introduction、依赖片段(第 11/30/327 行附近)都还没有 Math,双语文档目前不对称。

💡 建议

  • PORTING_1_21_1_TO_1_21_4.md 未更新 — 功能对照表缺 Math 一行;正文"聚合全部 17 个功能模块"、"聚合 JAR 包含 17 个功能模块"现在是 18 个;registrum 别名 API 属于新增公开能力,也值得在该文档"平台差异/新增"里记一笔(连同上文提到的派生条目别名规则)。
  • 移植残留的错误版本注释 — MathTestBootstrap.java("26.1 的 MappedRegistry 对重复键直接抛异常")、ParseCacheTest.java("26.1 里注册表自己就是 HolderLookup.RegistryLookup…")在 1.21.4 上同样成立(vanilla MappedRegistry.register 对重复 key 抛 IllegalStateException;Registry 本身即 HolderGetter),但写成 26.1 会误导后来者,建议改成"1.21.4"或"1.21.2 起"。
  • .github/modules.json 新增行的 "needs" 列比邻居少两个空格(纯格式)。
  • PR 标题已准确且符合 <英文> <中文> 格式,未作修改。

🟢 看起来不错 / 已核实

  • 别名 API 在 1.21.4 上确实可用(这是本次移植最大的风险点,已逐条核实):NeoForge 21.4.157 的 MappedRegistry extends BaseMappedRegistry(见 NeoForge 1.21.4 分支 MappedRegistry.java.patch),addAlias/resolve 由 BaseMappedRegistry 实现并以 @Override 注入 Registry 接口 → applyAliases(Registry<?>…) 里的 registry.addAlias/resolve 可编译;resolve(ResourceLocation) 返回非 null(无别名时返回原名)→ if (registry.resolve(old).equals(new)) continue; 语义正确,且正是防 NeoForge 里"二次 addAlias 相同映射会抛 Infinite alias loop detected"的必要守卫;addAlias 内同名不同目标的去重与代码注释一致。
  • 派生条目别名覆盖完整:BlockBuilder.item()→item(factory)、simpleItem()→item()、blockEntity()/simpleBlockEntity() 都经过置位方法;EntityBuilder.defaultSpawnEgg()→spawnEgg();FluidBuilder.defaultBlock()/defaultBucket() 走 block()/bucket()。别名目标名与实际注册名一一对上:super(..., "flowing_"+name) ↔ oldName.withPrefix("flowing_")、bucketName = name+"_bucket" ↔ withSuffix("_bucket")、block/type 用 sourceName ↔ newName;FluidBuilder.register() 里 block().register() 递归导致的二次 addAliases 由上述 resolve 守卫正确跳过。
  • 数学模块 API 与 1.21.4 对齐(用 1.21.4 官方 client_mappings + 目标分支既有编译通过的代码交叉验证):Registry#getOrThrow(同分支 module.multiblock/MultiblockState 已在用)、RegistryAccess#lookup/freeze、Registry 即 HolderGetter(asLookup() 已移除)、RegistrationInfo.BUILT_IN、RegistryFileCodec.create、RegistryOps.create(DynamicOps, HolderLookup.Provider)、ExtraCodecs.NON_NEGATIVE_INT、ByteBufCodecs.STRING_UTF8/DOUBLE/VAR_INT、javax.annotation.Nullable/ParametersAreNonnullByDefault(与 1.21.4 其它模块的主流写法一致)、@Mod 构造器注入 (IEventBus, ModContainer)(1.21.4 正确形态)。
  • 清单齐套:settings.gradle(include + 重命名)、module.main/build.gradle(NOT_DEV 与本地两种依赖写法)、.github/modules.json(math needs util,与 build.gradle 依赖一致)、gradle.properties、mods.toml([[mixins]] config 与文件名一致)、icon.png(与其它模块同一张,md5 相同)、空 mixins 列表 + refmap: anvillib.refmap.json 与 1.21.4 其它模块约定一致。.gitignore 的 *.log→*.log*(并删掉被其覆盖的 *.log.gz)合理。
  • README Math 章节示例 API 逐条存在:IExpression.of(HolderGetter,String)、evaluate(double...)、IExpression.CODEC、CustomFunction.of(List<String>,IExpression)、LibBuiltInFunctions.MIN.call(IExpression...)、IExpression.ref(String);内建函数清单(四则/pow/abs/floor/ceil/round/sqrt/min/max/foreach)与 LibBuiltInFunctions 枚举完全一致;无 TODO/FIXME/debug 打印。
  • 测试基础设施合理:math.fuzz.rounds 可调、往返自校验("再解析再写一遍文本相同")有专门防递归设计、缓存按注册表实例分组并配了 reload/disconnect 清理。

🧪 测试建议

被测目标 建议场景 优先级
修掉 ShapeUtil 任务后的 :anvillib-math-neoforge-1.21.4:check 确认 math 的 JUnit 测试仍被执行(useJUnitPlatform() + fuzz 轮数) 🔴
AbstractRegistrum.applyAliases 真实档案路径 改名后的方块/物品/BE id 从旧存档(chunk palette、物品栈、BE id)载入成功;并确认注释中"数据包文件名、字符串比较不走别名"的边界 🟡
MathTestBootstrap.bindValue 反射改绑 补一条断言:1.21.4 上同名重复注册确实抛异常(否则该 hack 的存在理由会随版本失效) 🟢

结论: REQUEST_CHANGES — 移植本身质量很高(源分支对齐、注册库别名 API 在 1.21.4 的可用性与语义已核实);唯一阻塞项是 module.math/build.gradle 里 module.util 的测试任务残留会让 build/CI 失败,删除即可;其余为文档同步(README.en.md、PORTING 文档)与注释准确性。

@Gugle2308

Copy link
Copy Markdown

💾 Self-improvement review: Patched SKILL.md in skill 'reverse-port-pr-review' (1 replacement).

The 1.21.4-style module build script was based on module.util/build.gradle and brought
three blocks that belong to util: a test sourceSets tweak, the runShapeUtilJoinTimingTest
JavaExec task, and a check dependency on it. ShapeUtilJoinTimingTest lives in
module.util/src/test, which is not on this module's test runtime classpath, so the task
failed with ClassNotFoundException and broke :anvillib-math-neoforge-1.21.4:build.
The Math entries added in the port were missing from README.en.md. Both are packaged into
the jar, so English readers had no math coordinates.
The test comments describing MappedRegistry and RegistryLookup named 26.1 even though the
behaviour is the same here; they now name this version.
@Gugle2308

Copy link
Copy Markdown

⚠️ Dangerous command requires approval:

cd /tmp && curl -s "https://api.github.com/repos/Anvil-Dev/AnvilLib/pulls/130/commits?per_page=20" | python3 -c "
import json,sys
d=json.load(sys.stdin)
for c in d:
    print(c['sha'][:8], c['commit']...

Reason: Security scan — [HIGH] Pipe to interpreter: curl | python3: Command pipes output from 'curl' directly to interpreter 'python3'. Downloaded content will be executed without inspection.
Safer: tirith run https://api.github.com/repos/Anvil-Dev/AnvilLib/pulls/130/commits?per_page=20 — or: vet https://api.github.com/repos/Anvil-Dev/AnvilLib/pulls/130/commits?per_page=20 (https://getvet.sh); [HIGH] Pipe to interpreter: curl | python3: Command pipes output from 'curl' directly to interpreter 'python3'. Downloaded content will be executed without inspection.
Safer: tirith run https://api.github.com/repos/Anvil-Dev/AnvilLib/commits/92152394ed14796e4d16a427d7d46c48afc6e02b/check-runs?per_page=100 — or: vet https://api.github.com/repos/Anvil-Dev/AnvilLib/commits/92152394ed14796e4d16a427d7d46c48afc6e02b/check-runs?per_page=100 (https://getvet.sh); script execution via -e/-c flag

Reply /approve to execute, /approve session to approve this pattern for the session, /approve always to approve permanently, or /deny to cancel.

@Gugle2308

Copy link
Copy Markdown

⚠️ Dangerous command requires approval:

cd /opt/data/workspace/AnvilLib && echo "=== 别名 API 区域:来源(1.21.1) vs 移植(1.21.4) 逐行比对 ==="; for f in AbstractRegistrum.java builders/AbstractBuilder.java builders/Builder.java builders/BlockBuilder.jav...

Reason: Security scan — [MEDIUM] Variation selector characters detected: Content contains Unicode variation selectors (VS1-256). These are commonly used in emoji sequences but may indicate steganographic encoding or obfuscation

Reply /approve to execute, /approve session to approve this pattern for the session, /approve always to approve permanently, or /deny to cancel.

@Gugle2308

Copy link
Copy Markdown

代码审查摘要 — PR #130(重新审查 · synchronize)

操作: synchronize(此前 opened 时已审查过前 2 个提交,本次针对新增的 3 个提交复核全量最终状态)
范围: 49 个文件(38 Java / 37 新增 / 0 删除 / 0 重命名)/ 7,125 行 diff(+6578 / −4),无 ghost 文件、无 EOF 缺失;patch diff 的 49 / +6578 / −4 与 API changed_files=49、additions=6578 完全一致 → diff 无静默截断
提交: 5 个 — 2c7140d4 port(math)、b8363c38 port(registrum)、f95dca5c、5e033f2d、92152394

✅ 本次增量(3 个新提交)已解决上次审查的全部结论

上次结论 提交 复核结果
🔴 module.math/build.gradle 残留 module.util 的 ShapeUtilJoinTimingTest 任务 / sourceSets 块 / check.dependsOn,会让 build 必挂 f95dca5c ✅ 已删除(git grep ShapeUtil 在 module.math 下无命中);check 无额外依赖,单测仍由 useJUnitPlatform() + addModdingDependenciesTo(sourceSets.test) + junit-bom 提供
⚠️ README.en.md 未同步 Math 5e033f2d ✅ Features 表新增 Math 行、新增 Math Module 章节(含 Groovy/Kotlin 依赖片段)、模块 id 列表与「Main 聚合子模块」清单都补了 math——中英已对称
💡 测试注释误指 26.1 92152394 ✅ MathTestBootstrap、ParseCacheTest 两处改为「1.21.4」

🟢 CI 证据(head 92152394)

  • build-l2 (math, anvillib-math, anvillib_math) / build → success(Gradle build 含 check→test,即 math 的表达式解析/回写往返、编解码等 JUnit 测试已在 CI 上真实跑过)
  • roseau-l2 (math …) / check → success;全仓 39 项检查中 37 项已完成且全绿,仅 main / build、multiblock (roseau) 仍在进行

🟢 移植保真度复核(本次重新独立核对)

  • module.math:与来源 dev/1.21.1(PR Add math lib 添加数学库 #122 / 7285ea13)逐文件比对,仅 7 个文件有差异,且全部是 1.21.1→1.21.4 的必要适配——build.gradle(util 坐标、data()→clientData())、IFunction.typeOf(getHolderOrThrow→getOrThrow)、MathTestBootstrap(asLookup()→注册表自身、RegistryAccess.registry()→lookup()、补 Frozen.freeze() 覆写、重复键反射改绑)、4 个测试调用点同步替换。文件集合与来源一一对应,无漏移植、无多余文件。
  • registrum 别名 API:AbstractBuilder.register()/aliasFrom()/addAliases()/getEntryId() 与来源 dev/1.21.1(PR Add alias api for Registrum 向Registrum加入别名API #128 / 892ef231)逐行一致(仅上下文行号漂移),addAlias/applyAliases 与 Block/Entity/Fluid 三处 addAliases 覆写同样一致。
  • 别名生效时序正确:onRegister(普通优先级)注册条目 → onRegisterLate(EventPriority.LOWEST)才 applyAliases,因此方块物品、刷怪蛋、桶、flowing_ 流体等派生条目以及其它模组的条目此刻都已就位;registry.resolve(old).equals(new) 守卫正好对应 NeoForge 对重复别名的抛错行为,addAlias 内的「同名不同目标」去重也有对应的 error 日志。
  • 集成清单齐套:settings.gradle(include + 项目重命名,与 CI 推导的 anvillib-math-neoforge-1.21.4 完全对上)、module.main/build.gradle(NOT_DEV 与本地两处 jarJar)、.github/modules.json(math needs util,与 IFunction 实际引用的 dev.anvilcraft.lib.v2.util.ISerializer 一致)、gradle.properties、mods.toml(字段形态与 registrum 相同,[[mixins]] config 与文件名对应)、空 mixins + anvillib.refmap.json(与 network/registrum/util 既有约定一致)、icon.png(与其它模块同一张,md5 相同)。CI 矩阵由 modules.json 自动生成,新增模块无需改 workflow。

💡 建议(非阻塞)

  1. PORTING_1_21_1_TO_1_21_4.md 未同步 — 功能对照表缺 Math 一行,正文两处「聚合全部 17 个功能模块」「17 个模块依赖」现在应为 18。README 已补,这份移植记录文档漏了。
  2. .github/modules.json 格式 — 新增行的 "needs" 列比同组邻居少 2 个空格(纯格式)。
  3. AbstractRegistrum.addAlias(...) 的迟到调用会被静默吞掉 — 别名只写入 aliases 映射,而 applyAliases 仅在 onRegisterLate 执行一次(该监听在 FMLCommonSetupEvent 还会被注销);若下游在注册期之后调用,既不会应用、也没有任何日志,条目还会长期留在 map 里。加一行 if (completedRegistrations.contains(registryType)) log.warn(...),并在 javadoc 明确「必须在注册期调用」,可把「静默失效」变成可诊断(NeoForge 原生 registry.addAlias 在冻结注册表上会抛错,语义上正好相反)。

🧪 测试建议

被测目标 建议场景 优先级
AbstractRegistrum.applyAliases 旧名从旧存档真实载入(chunk palette / 物品栈 / BE id)确实解析到新条目;并覆盖「旧名仍注册 → warn 跳过」「新名未注册 → debug 跳过」两条路径 🟡
AnvilLibMath / LibRegistries 空 anvillib_math.mixins.json(required=true、无 mixin、声明的 refmap 不存在)在专用服务器启动时无警告/无缺失 refmap 报错 🟢

结论: APPROVE — 上次唯一的阻塞项(从 module.util 抄来的测试任务残留)已删除,anvillib-math 的 build(含单元测试)与 roseau 检查在 CI 上均已通过;与来源分支的差异全部是必要的版本适配,派生条目别名覆盖与时序均正确。剩余仅为移植记录文档同步与两处格式/健壮性小建议,可随后续提交处理。

PR 标题「Port math lib and registrum alias api to 1.21.4 移植数学库和注册库别名API到1.21.4」准确且符合 <英文> <中文> 格式,未作修改。


由 Hermes Agent 审查

@Gugle2308

Copy link
Copy Markdown

💾 Self-improvement review: Patched SKILL.md in skill 'reverse-port-pr-review' (1 replacement).

@Gugle2308

Copy link
Copy Markdown

🌿 Roseau API Breaking Change Report

Module Status Breaking Changes
codec ✅ Compatible 0
collision ✅ Compatible 0
cube ✅ Compatible 0
config ✅ Compatible 0
integration ✅ Compatible 0
moveable-entity-block ✅ Compatible 0
network ✅ Compatible 0
rendering ⚪ Skipped —
space-select ✅ Compatible 0
font ✅ Compatible 0
util ✅ Compatible 0
explosion ✅ Compatible 0
rpc ✅ Compatible 0
math ⚪ Skipped —
multiblock ✅ Compatible 0
recipe ✅ Compatible 0
registrum ✅ Compatible 0
sync ✅ Compatible 0
wheel ✅ Compatible 0
main ✅ Compatible 0

Full CSVs: see the Artifacts section of this workflow run.

@WhereisFff
WhereisFff merged commit 89c568f into Anvil-Dev:dev/1.21.4 Sep 28, 2026
40 checks passed
@Gugle2308

Copy link
Copy Markdown

PR #130 状态为 closed,按 webhook 审查规则(closed/labeled → 停止),本次不进行代码审查,也不发布审查评论。

(由 Hermes Agent 自动判定:非活跃 PR,无需审查)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants