Skip to content

05 · 复制 NBT 地址 ​

current 最初指向 first。saved 复制这个地址,随后给 current 重新赋值只会把 current 指向 second。因此 saved.set(21) 修改的是 first。前面的 increment 对计分板地址做了相似的读写。

mcfpp
    var current = <int>("showcase:references", "first")
    const saved = current
    current = <int>("showcase:references", "second")
    saved.set(21)
    saved.tryRead { value -> (value) }

    const absent = <int>("showcase:references", "missing")
    var present = absent.tryRead { value -> (value) }
    if (!present) { ("missing is different from zero") }

动手验证 ​

addressCopiesKeepTheirTarget 检查计分板为 11、first 为 21、second 仍为 99。读取缺失的 missing 时,tryRead 跳过回调并返回 false;已有路径即使存着 0,也会进入回调。

游戏入口为 /function showcase.references:main。

完整源码 · 测试