/
airpump_abm.lua
73 lines (64 loc) · 1.69 KB
/
airpump_abm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
minetest.register_abm({
label = "airpump",
nodenames = {"vacuum:airpump"},
interval = 5,
chance = 1,
action = function(pos)
local meta = minetest.get_meta(pos)
if vacuum.airpump_enabled(meta) then
-- The spacesuit mod must be loaded after this mod, so we can't check at the start.
local has_spacesuit = minetest.get_modpath("spacesuit")
local used
if vacuum.is_pos_in_space(pos) then
used = vacuum.do_empty_bottle(meta:get_inventory())
if used and has_spacesuit then
vacuum.do_repair_spacesuit(meta:get_inventory())
end
else
if has_spacesuit then
used = vacuum.do_repair_spacesuit(meta:get_inventory())
end
if not used then
used = vacuum.do_fill_bottle(meta:get_inventory())
end
end
if used then
minetest.sound_play("vacuum_hiss", {pos = pos, gain = 0.5})
minetest.add_particlespawner({
amount = 12,
time = 4,
minpos = vector.subtract(pos, 0.95),
maxpos = vector.add(pos, 0.95),
minvel = {x=-1.2, y=-1.2, z=-1.2},
maxvel = {x=1.2, y=1.2, z=1.2},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 0.5,
maxexptime = 1,
minsize = 1,
maxsize = 2,
vertical = false,
texture = "bubble.png"
})
end
end
end
})
-- initial airpump step
minetest.register_abm({
label = "airpump seed",
nodenames = {"vacuum:airpump"},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = function(pos)
local meta = minetest.get_meta(pos)
if vacuum.airpump_active(meta) then
-- seed initial air
local node = minetest.find_node_near(pos, 1, {"vacuum:vacuum"})
if node ~= nil then
minetest.set_node(node, {name = "air"})
end
end
end
})