diff --git a/.gitignore b/.gitignore index 45560fd..7bbd4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -*.lua .luarc.json target diff --git a/errornowatcher.lua b/errornowatcher.lua new file mode 100644 index 0000000..95ef5c5 --- /dev/null +++ b/errornowatcher.lua @@ -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 diff --git a/lua/enum.lua b/lua/enum.lua new file mode 100644 index 0000000..96aadee --- /dev/null +++ b/lua/enum.lua @@ -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 diff --git a/lua/events.lua b/lua/events.lua new file mode 100644 index 0000000..a7f4c1f --- /dev/null +++ b/lua/events.lua @@ -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 diff --git a/lua/utils.lua b/lua/utils.lua new file mode 100644 index 0000000..4ef5ba8 --- /dev/null +++ b/lua/utils.lua @@ -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