chore(lua): add basic functions

This commit is contained in:
Ryan 2025-02-17 01:24:57 -05:00
parent fc5ff582c6
commit 93348835ac
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
5 changed files with 80 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
*.lua
.luarc.json .luarc.json
target target

15
errornowatcher.lua Normal file
View File

@ -0,0 +1,15 @@
SERVER = "localhost"
USERNAME = "ErrorNoWatcher"
OWNERS = { "ErrorNoInternet" }
for _, module in
{
"enum",
"events",
"utils",
}
do
module = "lua/" .. module
package.loaded[module] = nil
require(module)
end

15
lua/enum.lua Normal file
View File

@ -0,0 +1,15 @@
NONE = 0
FORWARD = 1
BACKWARD = 2
LEFT = 3
RIGHT = 4
FORWARD_LEFT = 5
FORWARD_RIGHT = 6
BACKWARD_LEFT = 7
BACKWARD_RIGHT = 8
BLOCK_POS_GOAL = 0
RADIUS_GOAL = 1
REACH_BLOCK_POS_GOAL = 2
XZ_GOAL = 3
Y_GOAL = 4

20
lua/events.lua Normal file
View File

@ -0,0 +1,20 @@
local center = { x = 0, z = 0 }
local radius = 50
function on_tick()
local entities = client:find_entities(function(e)
return e.kind == "minecraft:player"
and e.position.x > center.x - radius + 1
and e.position.x < center.x + radius
and e.position.z > center.z - radius
and e.position.z < center.z + radius
end)
for _, e in entities do
client:chat(string.format("%s (%s) at %.1f %.1f %.1f", e.kind, e.id, e.position.x, e.position.y, e.position.z))
end
end
function on_init()
info("client initialized, setting client information")
client:set_client_information({ view_distance = 16 })
end

30
lua/utils.lua Normal file
View File

@ -0,0 +1,30 @@
function dump(object)
if type(object) == "table" then
local string = "{ "
local parts = {}
for key, value in pairs(object) do
table.insert(parts, key .. " = " .. dump(value))
end
string = string .. table.concat(parts, ", ")
return string .. " " .. "}"
else
return tostring(object)
end
end
function dump_pretty(object, level)
if not level then
level = 0
end
if type(object) == "table" then
local string = "{\n" .. string.rep(" ", level + 1)
local parts = {}
for key, value in pairs(object) do
table.insert(parts, key .. " = " .. dump_pretty(value, level + 1))
end
string = string .. table.concat(parts, ",\n" .. string.rep(" ", level + 1))
return string .. "\n" .. string.rep(" ", level) .. "}"
else
return tostring(object)
end
end