Add missing mcl_util functions

This commit is contained in:
the-real-herowl 2023-12-31 02:00:29 +01:00
parent a8d451c1b0
commit c8ac243589
1 changed files with 22 additions and 0 deletions

View File

@ -22,6 +22,13 @@ function table.update_nil(t, ...)
return t return t
end 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 ---Works the same as `pairs`, but order returned by keys
--- ---
---Taken from https://www.lua.org/pil/19.3.html ---Taken from https://www.lua.org/pil/19.3.html
@ -630,6 +637,21 @@ function mcl_util.replace_mob(obj, mob)
return obj return obj
end 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) function mcl_util.get_pointed_thing(player, liquid)
local pos = vector.offset(player:get_pos(), 0, player:get_properties().eye_height, 0) local pos = vector.offset(player:get_pos(), 0, player:get_properties().eye_height, 0)
local look_dir = vector.multiply(player:get_look_dir(), 5) local look_dir = vector.multiply(player:get_look_dir(), 5)