forked from mt-mods/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
physics.lua
221 lines (185 loc) · 5.42 KB
/
physics.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
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
local has_monitoring = minetest.get_modpath("monitoring")
local has_technic = minetest.get_modpath("technic")
local has_mesecons_random = minetest.get_modpath("mesecons_random")
local MP = minetest.get_modpath("vacuum")
local throttle = dofile(MP .. "/util/throttle.lua")
local metric_space_vacuum_abm
local metric_space_vacuum_leak_abm
if has_monitoring then
metric_space_vacuum_abm = monitoring.counter("vacuum_abm_count", "number of space vacuum abm calls")
metric_space_vacuum_leak_abm = monitoring.counter("vacuum_abm_leak_count", "number of space vacuum leak abm calls")
end
-- air leaking nodes
local leaky_nodes = {
"group:door",
"group:soil",
"group:pipe", "group:tube"
}
if has_mesecons_random then
table.insert(leaky_nodes, "mesecons_random:ghoststone_active")
end
if has_technic then
table.insert(leaky_nodes, "technic:lv_cable")
table.insert(leaky_nodes, "technic:mv_cable")
table.insert(leaky_nodes, "technic:hv_cable")
end
local near_powered_airpump = function(pos)
local pos1 = vector.subtract(pos, {x=vacuum.air_pump_range, y=vacuum.air_pump_range, z=vacuum.air_pump_range})
local pos2 = vector.add(pos, {x=vacuum.air_pump_range, y=vacuum.air_pump_range, z=vacuum.air_pump_range})
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"vacuum:airpump"})
for _,node in ipairs(nodes) do
local meta = minetest.get_meta(node)
if vacuum.airpump_active(meta) then
return true
end
end
return false
end
-- vacuum/air propagation
minetest.register_abm({
label = "space vacuum",
nodenames = {"air"},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = throttle(1000, function(pos)
if metric_space_vacuum_abm ~= nil then metric_space_vacuum_abm.inc() end
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
else
-- in space, evacuate air
minetest.set_node(pos, {name = "vacuum:vacuum"})
end
end)
})
-- weird behaving nodes in vacuum
local drop_nodes = {
"default:torch",
"default:torch_wall",
"default:torch_ceiling",
"default:ladder_wood",
"default:ladder_steel",
"default:dry_shrub",
"default:papyrus",
"default:cactus",
"group:wool",
"group:wood",
"group:tree",
-- "group:mesecon", TODO: add hardcore setting for that one
-- TODO: maybe: group:dig_immediate
}
-- weird nodes in vacuum
minetest.register_abm({
label = "space drop nodes",
nodenames = drop_nodes,
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = throttle(100, function(pos)
if not vacuum.is_pos_in_space(pos) or near_powered_airpump(pos) then
return
end
local node = minetest.get_node(pos)
minetest.set_node(pos, {name = "vacuum:vacuum"})
for _, drop in pairs(minetest.get_node_drops(node.name)) do
minetest.add_item(pos, ItemStack(drop))
end
end)
})
-- various dirts in vacuum
minetest.register_abm({
label = "space vacuum soil dry",
nodenames = {
"default:dirt",
"default:dirt_with_grass",
"default:dirt_with_snow",
"default:dirt_with_dry_grass",
"default:dirt_with_grass_footsteps",
"default:dirt_with_rainforest_litter",
"default:dirt_with_coniferous_litter"
},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = throttle(100, function(pos)
minetest.set_node(pos, {name = "default:gravel"})
end)
})
-- plants in vacuum
minetest.register_abm({
label = "space vacuum plants",
nodenames = {
"group:sapling",
"group:plant",
"group:flora",
"group:flower",
"group:leafdecay",
"ethereal:banana", -- ethereal compat
"ethereal:orange",
"ethereal:strawberry"
},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = throttle(100, function(pos)
minetest.set_node(pos, {name = "default:dry_shrub"})
end)
})
-- sublimate nodes in vacuum
minetest.register_abm({
label = "space vacuum sublimate",
nodenames = {"group:snowy", "group:leaves", "group:water"},
neighbors = {"vacuum:vacuum"},
interval = 1,
chance = 1,
action = throttle(100, function(pos)
if not vacuum.is_pos_in_space(pos) or near_powered_airpump(pos) then
return
end
minetest.set_node(pos, {name = "vacuum:vacuum"})
end)
})
-- depressurize through leaky nodes
minetest.register_abm({
label = "space vacuum depressurize",
nodenames = leaky_nodes,
neighbors = {"vacuum:vacuum"},
interval = 2,
chance = 2,
action = throttle(250, function(pos)
if metric_space_vacuum_leak_abm ~= nil then metric_space_vacuum_leak_abm.inc() end
if not vacuum.is_pos_in_space(pos) or near_powered_airpump(pos) then
-- on earth: TODO: replace vacuum with air
return
else
local node = minetest.get_node(pos)
if node.name == "pipeworks:entry_panel_empty" or node.name == "pipeworks:entry_panel_loaded" then
-- air thight pipes
return
end
if node.name == "vacuum:airpump" then
-- pump is airthight
return
end
-- TODO check n nodes down (multiple simple door airlock hack)
-- in space: replace air with vacuum
local surrounding_node = minetest.find_node_near(pos, 1, {"air"})
if surrounding_node ~= nil then
if vacuum.debug then
-- debug mode, set
minetest.set_node(surrounding_node, {name = "default:cobble"})
else
-- normal case
minetest.set_node(surrounding_node, {name = "vacuum:vacuum"})
end
end
end
end)
})