xdecor-libre/handlers/helpers.lua

69 lines
1.4 KiB
Lua
Raw Normal View History

2016-02-04 18:02:28 +03:00
-- Returns the greatest numeric key in a table.
function xdecor.maxn(T)
local n = 0
for k in pairs(T) do
2019-07-23 15:03:20 +03:00
if k > n then
n = k
end
2016-02-04 18:02:28 +03:00
end
2019-07-23 15:03:20 +03:00
2016-02-04 18:02:28 +03:00
return n
end
-- Returns the length of an hash table.
function xdecor.tablelen(T)
local n = 0
2019-07-23 15:03:20 +03:00
for _ in pairs(T) do
n = n + 1
end
2016-02-04 18:02:28 +03:00
return n
end
-- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
function xdecor.tablecopy(T)
2019-07-23 15:03:20 +03:00
if type(T) ~= "table" then
return T -- No need to copy.
end
2016-02-04 18:02:28 +03:00
local new = {}
for k, v in pairs(T) do
if type(v) == "table" then
new[k] = xdecor.tablecopy(v)
else
new[k] = v
2016-02-04 18:02:28 +03:00
end
end
2019-07-23 15:03:20 +03:00
2016-02-04 18:02:28 +03:00
return new
end
function xdecor.stairs_valid_def(def)
return (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
2018-03-08 23:12:21 +03:00
(def.groups.cracky or def.groups.choppy) and
not def.on_construct and
not def.after_place_node and
not def.on_rightclick and
not def.on_blast and
not def.allow_metadata_inventory_take and
not (def.groups.not_in_creative_inventory == 1) and
not (def.groups.not_cuttable == 1) and
not def.groups.wool and
(def.tiles and type(def.tiles[1]) == "string" and not
2021-03-01 00:12:18 +03:00
def.tiles[1]:find("default_mineral")) and
not def.mesecons and
def.description and
def.description ~= "" and
2018-03-08 23:12:21 +03:00
def.light_source == 0
end
2023-07-01 10:34:49 +03:00
function xdecor.get_inventory_drops(pos, listnames)
local drops = {}
for l=1, #listnames do
default.get_inventory_drops(pos, listnames[l], drops)
end
return drops
end