Skip to content
On this page

命令

Katton 在游戏中添加了 /katton 命令,允许你在游戏内就管理脚本、查看状态、编辑配置等。

NOTE

Paper 上的 /katton 命令更为精简:没有 registrydebug 子命令,因为 Paper 不支持注册表操作。

速览

命令作用权限级别
/katton/katton help列出所有命令所有人
/katton statusKatton 运行状态所有人
/katton registry注册表状况概览所有人
/katton registry stale显示残留旧注册条目所有人
/katton reload重载所有脚本包仅 OP
/katton debug registryLogging查看调试日志开关仅 OP
/katton debug registryLogging on/off开/关调试日志仅 OP

帮助

输入 /katton/katton help,Katton 会列出所有可用子命令。

/katton

or

/katton help

Output:

[Katton] /katton help | status | registry | registry stale | reload | itemrender spawn <item> [still|spin|float|pulse|showcase] [scale] [lifetimeTicks] | itemrender clear <radius> | debug registryLogging [on|off] | config ...

状态

想快速看看 Katton 现在的状态?/katton status 会打印当前加载状态、是否绑定了服务器、以及客户端重载是否进行中。

/katton status

Output:

[Katton] state=SERVER_STARTED, serverBound=true, clientReloadRunning=false

注册诊断

/katton registry

命令会按注册表分类展示摘要:Katton 记录了多少条目、有多少正被脚本管理、有多少是残留的(重载之前注册的,但是重载之后没有被注册或者被修改的,为了保证稳定仍留在 Minecraft 内置注册表中的对象)。

/katton registry

Output:

[Katton] items: entries=2, managed=2, stale=0 | effects: entries=1, managed=1, stale=0 | blocks: entries=1, managed=1, stale=0 | ...
/katton registry stale

When no stale entries exist:

[Katton] No stale retained registry entries.

When stale entries exist (e.g. after removing a script that registered items):

[Katton] Stale retained entries: items=1 | entity_types=1

/katton registry stale

显示有残留条目的注册表。

NOTE

"残留" 不意味着出错。Katton 在重载时故意把对象保留在 Minecraft 的内置注册表中,以避免 holder 崩溃。残留只表示 "上次脚本注册了,这次没重新注册"。

重载

/katton reload 可能会是你最常用的命令。它会:

  1. 重新扫描所有启用的脚本包

  2. 重新编译并执行服务端脚本

  3. 在内置服务端(单人游戏)上同时异步触发客户端脚本重载

    kotlin
    // In a server script:
    // The /katton reload command is built-in — just type it in chat or server console.
    // No code needed! It reloads all script packs and syncs the command tree.
    
    // If an event or custom command needs to request the same reload:
    import net.minecraft.server.MinecraftServer
    import top.katton.engine.ScriptReloadManager
    
    fun requestKattonReload(server: MinecraftServer) {
        ScriptReloadManager.reloadScriptsAsync(server) { success ->
            println("Katton reload finished: $success")
        }
    }

TIP

  • F3 + T 只重载 Minecraft 资源,不会调用 Katton 脚本。
  • /reload(原版命令)重载数据包,Katton 会借此重载服务端脚本。
  • /katton reload 客户端和服务端都会尝试重载。