tsm_chests: Simplify node lookups a bit by using a table of node-names

This commit is contained in:
ANAND 2019-12-18 08:21:27 +05:30
parent 54598ce947
commit a86cb11501

View file

@ -17,6 +17,13 @@
tsm_chests = {} tsm_chests = {}
local non_ground_nodes = {
"air",
"default:water_source",
"default:lava_source",
"default:lava_flowing"
}
local chest_formspec = local chest_formspec =
"size[8,9]" .. "size[8,9]" ..
default.gui_bg .. default.gui_bg ..
@ -89,7 +96,7 @@ local function findGroundLevel(pos, y_min, y_max)
for y = y_max, y_min, -1 do for y = y_max, y_min, -1 do
local p = {x=pos.x,y=y,z=pos.z} local p = {x=pos.x,y=y,z=pos.z}
local name = get_node(p).name local name = get_node(p).name
if name == "air" or name == "default:water_source" or name == "default:lava_source" then if table.indexof(non_ground_nodes, name) ~= -1 then
top = y top = y
break break
end end
@ -97,7 +104,7 @@ local function findGroundLevel(pos, y_min, y_max)
for y=top,y_min,-1 do for y=top,y_min,-1 do
local p = {x=pos.x,y=y,z=pos.z} local p = {x=pos.x,y=y,z=pos.z}
local name = get_node(p).name local name = get_node(p).name
if name ~= "air" and name ~= "default:water_source" and name ~= "default:lava_source" then if table.indexof(non_ground_nodes, name) == -1 then
ground = y ground = y
break break
end end