forked from mt-mods/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathairpump_abm.lua
More file actions
234 lines (213 loc) · 7.84 KB
/
airpump_abm.lua
File metadata and controls
234 lines (213 loc) · 7.84 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
minetest.register_abm({
label = "airpump",
nodenames = {"vacuum:airpump", "vacuum:airpump_wait", "vacuum:airpump_active"},
interval = 10,
chance = 1,
action = function(pos)
local meta = minetest.get_meta(pos)
if vacuum.airpump_enabled(meta) then
local eu_input = meta:get_int("LV" .. "_EU_input")
local powered = eu_input >= 100
if not powered then
return
end
-- 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
local used_type = 0;
if vacuum.is_pos_in_space(pos) then
used = vacuum.do_empty_bottle(meta:get_inventory())
used_type = 1
if math.random(0, 3) == 0 then
used_type = 4
end
if used and has_spacesuit then
vacuum.do_repair_spacesuit(meta:get_inventory())
used_type = 3
end
else
if has_spacesuit then
used = vacuum.do_repair_spacesuit(meta:get_inventory())
used_type = 3
end
if not used then
used = vacuum.do_fill_bottle(meta:get_inventory())
used_type = 2
end
end
if used then
technic.swap_node(pos, "vacuum:airpump")
if used_type == 1 then
minetest.sound_play("vacuum_hiss", {
pos = pos,
gain = 0.3
})
elseif used_type == 2 then
minetest.sound_play("vacuum_hiss_2", {
pos = pos,
gain = 0.3
})
elseif used_type == 3 then
minetest.sound_play("vacuum_hiss_3", {
pos = pos,
gain = 0.3
})
elseif used_type == 4 then
minetest.sound_play("vacuum_hiss_4", {
pos = pos,
gain = 0.3
})
end
minetest.add_particlespawner({
amount = 16,
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
})
local function flush_area(pos)
local range = {
x = 2,
y = 1,
z = 2
}
local pos1 = vector.subtract(pos, range)
local pos2 = vector.add(pos, range)
local manip = minetest.get_voxel_manip()
local e1, e2 = manip:read_from_map(pos1, pos2)
local area = VoxelArea:new({
MinEdge = e1,
MaxEdge = e2
})
local data = manip:get_data()
for y = pos1.y, pos2.y do
for z = pos1.z, pos2.z do
for x = pos1.x, pos2.x do
local index = area:index(x, y, z)
-- if data[index] == c_vacuum or data[index] == c_atmos or data[index] == c_air or data[index] == c_aer then
if data[index] == c_vacuum then
data[index] = c_aer
-- elseif data[index] == c_atmos
-- data[index] = c_aeri
elseif data[index] == c_aer then
data[index] = c_air
elseif data[index] == c_aeri then
data[index] = c_air
end
end
end
end
manip:set_data(data)
manip:write_to_map()
end
-- initial airpump step
minetest.register_abm({
label = "airpump seed",
nodenames = {"vacuum:airpump", "vacuum:airpump_wait", "vacuum:airpump_active"},
neighbors = {"vacuum:vacuum", "asteroid:atmos", "group:atmosphere"},
-- interval = 0.7,
interval = 1,
chance = 1,
action = function(pos)
local meta = minetest.get_meta(pos)
if vacuum.airpump_active(meta) then
local eu_input = meta:get_int("LV" .. "_EU_input")
local powered = eu_input >= 100
if not powered then
return
end
-- seed initial air
-- local count = 0;
for j = 1, 7 do
local count = 0;
local sz = j
local pos1 = vector.subtract(pos, {
x = sz,
y = sz,
z = sz
})
local pos2 = vector.add(pos, {
x = sz,
y = sz,
z = sz
})
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"vacuum:vacuum"})
local nodes_thin = minetest.find_nodes_in_area(pos1, pos2, {"vacuum:atmos_thin"})
for i, node in ipairs(nodes_thin) do
if node ~= nil then
if (vacuum.has_in_area(pos, "vacuum:atmos_thin", 1, 7)) then
minetest.set_node(node, {
name = "air"
})
end
end
end
for i, node in ipairs(nodes) do
if node ~= nil then
count = count + 1
if (vacuum.has_in_area(pos, "vacuum:atmos_thin", 1, 8)) then
minetest.set_node(node, {
name = "vacuum:atmos_thin"
})
-- vacuum.replace_nodes_at(pos, j, node.name, "air")
end
-- flush_area(node)
-- flush_area({x=node.x, y=node.y, z=node.z}) -- doesn't work..
if (math.random(0, 500) == 0) then
minetest.sound_play("vacuum_hiss_4", {
pos = pos,
gain = 0.3
})
end
-- if (vacuum.has_in_area(pos, "vacuum:atmos_thin", 2, 3)) then
-- if (node.name == "vacuum:atmos_thin") then
-- minetest.set_node(node, {name = "air"})
-- vacuum.replace_nodes_at(pos, 2, node.name, "air")
-- else
-- minetest.set_node(node, {name = "vacuum:atmos_thin"})
-- vacuum.replace_nodes_at(pos, 2, node.name, "vacuum:atmos_thin")
-- end
-- end
end
end
if (count > 0 and #nodes > 0) then
if count / #nodes > 0.9 then
-- return
end
if count / #nodes > 0.8 and j > 3 then
return
end
end
end
end
end
})