diff --git a/common.lua b/common.lua index d95e4c6..a3437f7 100644 --- a/common.lua +++ b/common.lua @@ -2,11 +2,17 @@ vacuum.air_bottle_image = "vessels_steel_bottle.png^[colorize:#0000FFAA" --- returns true, if in space (with safety margin for abm) +-- space pos checker vacuum.is_pos_in_space = function(pos) - return pos.y > vacuum.space_height + 40 + return pos.y > vacuum.space_height end -vacuum.is_pos_on_earth = function(pos) - return pos.y < vacuum.space_height - 40 -end \ No newline at end of file +-- (cheaper) space check, gets called more often than `is_pos_in_space` +vacuum.no_vacuum_abm = function(pos) + return pos.y > vacuum.space_height - 40 and pos.y < vacuum.space_height + 40 +end + +-- checks if this mapblock is in space when generated +vacuum.is_mapgen_block_in_space = function(minp, maxp) + return minp.y > vacuum.space_height +end diff --git a/mapgen.lua b/mapgen.lua index 0a5b83a..23cd27f 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -5,7 +5,7 @@ local c_air = minetest.get_content_id("air") minetest.register_on_generated(function(minp, maxp, seed) - if minp.y < vacuum.space_height then + if not vacuum.is_mapgen_block_in_space(minp, maxp) then return end diff --git a/physics.lua b/physics.lua index dddd967..f0c6cea 100644 --- a/physics.lua +++ b/physics.lua @@ -50,7 +50,7 @@ end -- vacuum/air propagation minetest.register_abm({ - label = "space vacuum", + label = "space vacuum", nodenames = {"air"}, neighbors = {"vacuum:vacuum"}, interval = 1, @@ -59,14 +59,18 @@ minetest.register_abm({ if metric_space_vacuum_abm ~= nil then metric_space_vacuum_abm.inc() end - if vacuum.is_pos_on_earth(pos) or near_powered_airpump(pos) then + if vacuum.no_vacuum_abm(pos) then + return + end + + if not vacuum.is_pos_in_space(pos) or near_powered_airpump(pos) then -- on earth or near a powered airpump local node = minetest.find_node_near(pos, 1, {"vacuum:vacuum"}) if node ~= nil then minetest.set_node(node, {name = "air"}) end - elseif vacuum.is_pos_in_space(pos) then + else -- in space, evacuate air minetest.set_node(pos, {name = "vacuum:vacuum"}) end @@ -183,10 +187,10 @@ minetest.register_abm({ action = throttle(250, function(pos) if metric_space_vacuum_leak_abm ~= nil then metric_space_vacuum_leak_abm.inc() end - if vacuum.is_pos_on_earth(pos) or near_powered_airpump(pos) then + if not vacuum.is_pos_in_space(pos) or near_powered_airpump(pos) then -- on earth: TODO: replace vacuum with air return - elseif vacuum.is_pos_in_space(pos) then + else local node = minetest.get_node(pos) if node.name == "pipeworks:entry_panel_empty" or node.name == "pipeworks:entry_panel_loaded" then diff --git a/vacuum.lua b/vacuum.lua index 1e1388b..9afea4c 100644 --- a/vacuum.lua +++ b/vacuum.lua @@ -13,6 +13,7 @@ minetest.register_node("vacuum:vacuum", { alpha = 0.1, groups = {not_in_creative_inventory=1, not_blocking_trains=1, cools_lava=1}, paramtype = "light", + -- light_source = minetest.LIGHT_MAX, TOOD: test drop = {}, sunlight_propagates = true })