Skip to content

Commit

Permalink
rewrite vacuum propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 21, 2020
1 parent 78b4709 commit 0328ec8
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions physics_propagation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,40 @@ if has_monitoring then
metric_space_vacuum_abm = monitoring.counter("vacuum_abm_count", "number of space vacuum abm calls")
end

-- vacuum/air propagation
-- vacuum propagation
minetest.register_abm({
label = "space vacuum",
label = "air -> vacuum replacement",
nodenames = {"air"},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = vacuum.throttle(1000, function(pos)

-- update metrics
if metric_space_vacuum_abm ~= nil then metric_space_vacuum_abm.inc() end

if vacuum.no_vacuum_abm(pos) then
return
if vacuum.is_pos_in_space(pos) and not vacuum.near_powered_airpump(pos) then
-- in space, evacuate air
minetest.set_node(pos, {name = "vacuum:vacuum"})
end
end)
})

-- air propagation
-- works slower than vacuum abm
minetest.register_abm({
label = "vacuum -> air replacement",
nodenames = {"vacuum:vacuum"},
neighbors = {"air"},
interval = 1,
chance = 2,
action = vacuum.throttle(1000, function(pos)

-- update metrics
if metric_space_vacuum_abm ~= nil then metric_space_vacuum_abm.inc() end

if not vacuum.is_pos_in_space(pos) or vacuum.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
else
-- in space, evacuate air
minetest.set_node(pos, {name = "vacuum:vacuum"})
minetest.set_node(pos, {name = "air"})
end
end)
})

0 comments on commit 0328ec8

Please sign in to comment.