
LuaDatapack
允许在 Minecraft 中运行 Lua 脚本。
注意:LuaDatapack 处于测试阶段,因此 API 可能会发生变化。
我目前不太打算在这个项目上投入更多精力。相反,我一直在开发一种专用的编程语言,它可编译为 Minecraft 命令,名为 Amethyst。它比这个更有用,因为它不需要专用的模组。
使用方法
创建一个带有 lua 子文件夹的新数据包。例如:data/foo/lua/bar.lua。
功能特性
- 底层使用 Cobalt,提供快速的执行时间
- 可以使用
require从数据包中包含脚本,并使用 Minecraft 的命名空间 ID 系统 - 支持 TypeScriptToLua
- 支持一些常见的实用库
命令
/lua
用法:/lua <name> [<args>]
示例,要运行 data/foo/lua/bar.lua:/lua foo:bar
可以通过 Lua 脚本中的名为 args 的数组访问参数。
API
API 参考文档可在 此处 找到。
标准库
默认包含了一些实用库。
| 库 | 路径 |
|---|---|
| json.lua | std:json |
| class.lua | std:class |
| 标准 Lua 库 | std:math |
| 标准 Lua 库 | std:string |
| 标准 Lua 库 | std:bit32 |
| 标准 Lua 库 | std:utf8 |
| 命令库 | std:commands |
| 存储库 | std:storage |
| 配置工具库 | std:config |
注意:如果你更喜欢不同的 OOP 库,只需将其添加到你的数据包中即可。
项目系统
有一个简单的项目系统,允许自定义哪些脚本可以被执行以及被外部项目(不同命名空间下的脚本)导入。
要自定义你的项目,请在你的命名空间中添加一个 _project.lua 文件。例如,如果命名空间是 foo,那么你可以创建 foo:_project.lua:
return {
scripts = {"foo:bar"},
exports = {"foo:baz"},
depends = {"hello"},
load = {"foo:load"},
tick = {"foo:tick"}
}
在上述示例中,foo:bar 是一个通过 /lua 运行的脚本,foo:baz 是一个任何文件都可以 require 的脚本,并且它需要 hello 项目才能正常运行。脚本可以导入同一命名空间中的任何脚本,即使它未包含在 exports 数组中。如果项目不包含 _project.lua,则默认使用 std:_default_datapack:
local config = require("std:config")
return {
scripts = config.without_underscore(),
exports = {}
}
注意:并非所有字段都需要显式定义。
如果项目加载失败,其中的所有脚本都无法加载。
贡献
构建此仓库与任何其他 Fabric 模组相同。在游戏启动时,可能会出现库(Cobalt、Apache commons-io 等)无法加载的问题,但通过 VSCode 调试器运行游戏却可以正常工作(原因不明)。
待办事项
- 优化 Lua API
- 添加更多 API 功能
- 减少内部对命令的使用
计划中的功能
- 更多命令
- 带有 TypeScriptToLua 的开发工具
链接
源码:
Modrinth:
API 参考:

LuaDatapack
Allows lua scripts to be ran in Minecraft.
Note: LuaDatapack is in beta, so the api is subject to change.
I currently don't plan on working on this project much more. Instead I've been making a dedicated programming language that compiles to Minecraft commands called Amethyst. It's more useful than this because it doesn't require a dedicated mod.
Usage
Create a new datapack with the lua subfolder. For example: data/foo/lua/bar.lua.
Features
- Uses Cobalt under the hood, which gives fast execution times
- Scripts can be included from datapacks using
requireand use Minecraft's namespaced id system - TypeScriptToLua support
- Supports a few common utility libraries
Commands
/lua
Usage: /lua <name> [<args>]
Example, to run data/foo/lua/bar.lua: /lua foo:bar
Arguments can be accessed via an array called args in the lua script.
Api
The api reference can be found here.
Standard library
A few utility libraries are included by default.
| Library | Path |
|---|---|
| json.lua | std:json |
| class.lua | std:class |
| Standard lua library | std:math |
| Standard lua library | std:string |
| Standard lua library | std:bit32 |
| Standard lua library | std:utf8 |
| Commands library | std:commands |
| Storage library | std:storage |
| Configuration utilities library | std:config |
Note: If you prefer a different OOP library, you can simply add one to your datapack.
Project system
There is a simple project system which allows for customization of which scripts can be executed and imported by external projects (scripts not in the same namespace).
To customize your project, add a _project.lua file to your namespace. For example if the namespace was foo then you would make a foo:_project.lua:
return {
scripts = {"foo:bar"},
exports = {"foo:baz"},
depends = {"hello"},
load = {"foo:load"},
tick = {"foo:tick"}
}
In the above example foo:bar is a script to be ran via /lua, foo:baz is a script that any file can require, and it requires the hello project to function. Scripts can import any script in the same namespace, even if it is not included in the exports array. If a project does not include a _project.lua, then the default std:_default_datapack is used instead:
local config = require("std:config")
return {
scripts = config.without_underscore(),
exports = {}
}
Note: not all fields need to be explicitly defined.
If a project fails to load, all scripts in it are unable to load.
Contributing
Building this repo is the same as any other Fabric mod. There may be issues with libraries (Cobalt, Apache commons-io, etc) not loading when starting the game, but running the game though the VSCode debugger works for some reason.
Things to do
- Optimize lua api
- Add more api features
- Use commands less internally
Planned features
- More commands
- Development tools with TypeScriptToLua
Links
Source:
Modrinth:
Api reference:
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
下载 LuaDatapack
- 支持 1.20 + 1.20.1
_project.lua中的load和tick字段
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
查看物品与配方
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
AE2:一款流行的自动化与存储模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧