From fa085f566235b0ad084dfe7b28c86eb3bd55edc8 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Tue, 10 Sep 2019 16:18:54 +0200 Subject: [PATCH] check buildable_to of nodes --- is_area_empty.lua | 39 ++++++++++++++++++++++----------------- move_nodetimers.lua | 4 ++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/is_area_empty.lua b/is_area_empty.lua index c225d84..64e713f 100644 --- a/is_area_empty.lua +++ b/is_area_empty.lua @@ -1,15 +1,20 @@ -local c_air = minetest.get_content_id("air") local c_ignore = minetest.get_content_id("ignore") -local has_vacuum_mod = minetest.get_modpath("vacuum") --- TODO: what about ignore? +local buildable_to_nodes = {} + +minetest.after(4, function() + local count = 0 + for name, node in pairs(minetest.registered_nodes) do + if node.buildable_to then + count = count + 1 + local id = minetest.get_content_id(name) + buildable_to_nodes[id] = true + end + end + minetest.log("action", "[jumpdrive] collected " .. count .. " nodes that are buildable_to") +end) + -local c_vacuum -if has_vacuum_mod then - c_vacuum = minetest.get_content_id("vacuum:vacuum") -else - c_vacuum = c_air -end jumpdrive.is_area_empty = function(pos1, pos2) local manip = minetest.get_voxel_manip() @@ -24,19 +29,19 @@ jumpdrive.is_area_empty = function(pos1, pos2) local index = area:index(x, y, z) local id = data[index] - if id ~= c_air and id ~= c_vacuum then - -- not air or vacuum - if id == c_ignore then - return false, "Uncharted" - else - return false, "Neither air or vacuum" - end + if id == c_ignore then + return false, "Uncharted" + end + + if not buildable_to_nodes[id] then + -- not buildable_to + return false, "Occupied" end end end end - -- only air and vacuum nodes found + -- only buildable_to nodes found return true, "" end diff --git a/move_nodetimers.lua b/move_nodetimers.lua index 1ef35ac..959fcd6 100644 --- a/move_nodetimers.lua +++ b/move_nodetimers.lua @@ -8,7 +8,7 @@ minetest.after(4, function() end end minetest.log("action", "[jumpdrive] collected " .. #node_names_with_timer .. " items with node timers") -end); +end) -- invoked from move.lua @@ -39,4 +39,4 @@ jumpdrive.move_nodetimers = function(source_pos1, source_pos2, delta_vector) end end -end \ No newline at end of file +end