
LuaDatapack
A simple mod that allows lua to be included in datapacks
- Загрузки
- 1K
- Подписчики
- 19
- Обновлён
- 15 июня 2023 г.
- Лицензия
- MIT
Опубликован 9 июля 2022 г.

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: https://github.com/kinderhead/LuaDatapack
Modrinth: https://modrinth.com/mod/luadatapack
Api reference: https://kinderhead.github.io/LuaDatapack
Ченджлог
0.11.0-betaБета1.20, 1.20.1 · 15 июня 2023 г.
- 1.20 + 1.20.1 support
loadandtickfields in_project.lua
0.10.2-betaБета1.19.4 · 5 июня 2023 г.
- New
inventory.clearmethod - Reworked
entity.set_posand addedentity.get_rotandentity.set_rot - Fixed an issue where
printandprint_dbwould not use the__tostringmetamethod if it exists
0.10.1-betaБета1.19.4 · 1 июня 2023 г.
- Fixed a bug where the mod would just not work
0.10.0-betaБета1.19.4 · 1 июня 2023 г.
/luacommand now returns any integer that the lua script returns- New
std:storagemodule which allows permanent storage- Use
storage.save()andstorage.load()to store data. Check the documentation for more information
- Use
- Added support for
print() - New
print_db()function which prints to the console instead of chat - Modified
entity.add_effectslightly - Added new global variable
filename - Added project system
- Bug fixes
- Fixed some issues with importing modules
0.9.0-betaБета1.19.4 · 30 мая 2023 г.
- Updated to 1.19.4
- Did some clean up
0.7.1-betaБета1.19 · 28 июля 2022 г.
- Moved command wrapper functions to their own module:
std:commandsrunis still in the global namespace, this may change
0.7.0-betaБета1.19 · 27 июля 2022 г.
- Not much, but there has not been a release in a while
- Separated a couple of standard lua libraries. They are no longer instantiated every time
/luais ran, improving performancestd:mathstd:stringstd:bit32std:utf8
- Api features
Entity.new- Alternative to
summon, it returns the entity spawned.Entityis a global variable representing the entity type as seen in entity.d.ts
- Alternative to
0.6.0-betaБета1.19 · 19 июля 2022 г.
- New standard library:
class.lua. If you prefer a different OOP library, you can add one to the datapack - Top level return with
run() - Api features
entity.add_effectentity.clear_effects
- Bug fixes
- Certain api calls displayed output in the chat. This is no longer the case
Комментарии
Загружаем…