PxIgnis

PxIgnis

一个用于Minecraft Fabric服务器的Lua框架,支持即时热重载。使用专为人类设计的API,在Lua中定义聊天命令、事件和服务器逻辑,无需Java/Kotlin。

社交

这是一个为 Fabric 服务器设计的 Lua 运行时,支持热重载。编辑 config/ignis/ 中的脚本,运行 /ignis reload,更改会立即生效。

完整文档在 ignis.pyxiion.ru。


关于

PxIgnis 是与一个完全原版的 Roguelike 自定义服务器同步开发的。其 API 反映了项目自身的需求。


主要特性

  • 热重载 Lua 运行时 — /ignis reload 可在毫秒内重新运行脚本。命令会重新注册到运行的 Brigadier 调度器中,无需重启服务器。
  • 命令注册 — register("cmd <name:type> [<name:type>]", handler, permission?)。内置参数类型:int、double、float、bool、text、word、player、block_pos、choice=...。Tab 补全和权限(admin.cmd)都是 API 的一部分。
  • 事件,支持取消 — 15 个以上的钩子:player_block_break、player_chat、player_attack_entity、entity_hurt、entity_death 等。返回 false 可取消事件。
  • 区域和可脚本化的怪物 AI — 具有进入/离开/移动/死亡事件的空间区域,以及用于自定义怪物 AI 的 API。
  • 协程、持久化、UI — mc.fetch / mc.sleep 用于顺序异步代码,player.data / mc.data / 存储后端用于持久化状态,还包含全息影像、侧边栏和用于自定义容器的 chestgui 库。

等等,还有更多。


示例

1. 区域 + 异步

local arena = world:createRegion(vec(-50, 64, -50), vec(50, 80, 50))

arena:on("entity_enter", function(entity)
    if entity:isPlayer() then
        mc.broadcast(entity.name .. " entered the arena")
        
        coroutine.wrap(function()
            local res = mc.fetch("https://api.example.com/arena/log")
            if not res.ok then
                mc.broadcast("log failed: " .. res.error, true)
            end
        end)()
    end
end)

2. 怪物 AI

--# nova syntax
-- 启用自定义语法的酷炫特性,用于尾随 lambda(就像 Kotlin 一样)
mc.registerBehaviour("zombie_chase") \{ self, mob ->
    local p = mc.players[1]
    if p then
        local pos = p.pos
        mob:navigateTo(pos.x, pos.y, pos.z, 1.0)
    end
}

mc.on("entity_spawn", function(entity)
    if entity:isMob() and entity.type == "minecraft:zombie" then
        entity:setAI("zombie_chase")
    end
end)

3. 带权限的命令

register("pay <amount:int> <target:player>", function(ctx, amount, target)
    ctx.player.data.balance = (ctx.player.data.balance or 0) - amount
    target.data.balance     = (target.data.balance or 0) + amount
    
    target:sendMessage("收到来自 " .. ctx.player.name .. " 的 " .. amount)
end, "pxrp.economy")

安装与要求

  1. 安装 Fabric Loader ≥0.19.2、Fabric API ≥0.141.4+1.21.11 和 Fabric Language Kotlin ≥1.10.8。
  2. 将 pxignis-*.jar 放入服务器的 mods/ 文件夹中。
  3. 启动服务器。首次启动时会创建 config/ignis/demo.lua。
  4. 编辑 config/ignis/ 下的脚本,然后运行 /ignis reload。

许可协议

GNU 宽通用公共许可证 v3.0