From c8ac243589c9d929dce6bb7ca826613c13806af2 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Sun, 31 Dec 2023 02:00:29 +0100 Subject: [PATCH] Add missing mcl_util functions --- mods/CORE/mcl_util/init.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 6ec86d05c..0c6bc73b9 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -22,6 +22,13 @@ function table.update_nil(t, ...) return t end +-- Copies the table then updates +function table.merge(t, ...) + local t2 = table.copy(t) + return table.update(t2, ...) +end + + ---Works the same as `pairs`, but order returned by keys --- ---Taken from https://www.lua.org/pil/19.3.html @@ -630,6 +637,21 @@ function mcl_util.replace_mob(obj, mob) return obj end + +function mcl_util.traverse_tower(pos, dir, callback) + local node = minetest.get_node(pos) + local i = 0 + while minetest.get_node(pos).name == node.name do + if callback and callback(pos, dir, node) then + return pos,i,true + end + i = i + 1 + pos = vector.offset(pos, 0, dir, 0) + end + return vector.offset(pos, 0, -dir, 0), i +end + + function mcl_util.get_pointed_thing(player, liquid) local pos = vector.offset(player:get_pos(), 0, player:get_properties().eye_height, 0) local look_dir = vector.multiply(player:get_look_dir(), 5)