-
Notifications
You must be signed in to change notification settings - Fork 0
/
lbm.lua
260 lines (247 loc) · 8.44 KB
/
lbm.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
local get_node = minetest.get_node
-- a list of nodes that should not be considered land/shore
local water_or_air = {
["air"] = true,
["default:water_source"] = true,
["default:water_flowing"] = true,
-- ["default:river_water_source"] = true,
["default:river_water_flowing"] = true,
["tides:water"] = true,
["tides:air"] = true,
["tides:wave"] = true,
["tides:surface"] = true,
["tides:offshore_water"] = true,
["tides:seawater"] = true,
["tides:shorewater"] = true,
["ignore"] = true --/!\--
}
-- To DO : target every airlike node?
--[[
local air_and_friends = {
["air"] = true,
["default:water_flowing"] = true,
["default:river_water_flowing"] = true,
-- ["tides:wave"] = true,
["ignore"] = true --/!\--
}]]
local water_and_friends = {
["default:water_source"] = true,
["default:water_flowing"] = true,
-- ["default:river_water_source"] = true,
["default:river_water_flowing"] = true,
["tides:water"] = true,
["tides:air"] = true,
["tides:wave"] = true,
["tides:offshore_water"] = true,
["tides:seawater"] = true,
["tides:shorewater"] = true,
["ignore"] = true --/!\--
}
-- REPLACE SEA WATER AT GENERATION with tides:seawater; tides:offshore_water (surface only); tides:waves (surface only)
if minetest.settings:get_bool("fixwater_generated_mapblocks") then
minetest.register_lbm({
name="tidesandfloods:water_source_lbm",
nodenames = {"default:water_source"},
run_at_every_load=true,
action = function(pos)
local check_node = {
["east"] = get_node({x=pos.x+1, y=pos.y, z=pos.z}).name,
["west"] = get_node({x=pos.x-1, y=pos.y, z=pos.z}).name,
["up"] = get_node({x=pos.x, y=pos.y+1, z=pos.z}).name,
["down"] = get_node({x=pos.x, y=pos.y-1, z=pos.z}).name,
["north"] = get_node({x=pos.x, y=pos.y, z=pos.z+1}).name,
["south"] = get_node({x=pos.x, y=pos.y, z=pos.z-1}).name
}
local cardinal = {"north", "south", "east", "west"}
if check_node["up"] == "air" then
for i = 1,4 do
if water_or_air[check_node[cardinal[i] ] ] == nil then --if cardinal node name not in list, then
minetest.set_node(pos,{name="tides:shorewater"})
do return end
break
end
end
local edge_x = pos.x % 16
local edge_z = pos.z % 16
if (edge_x == 0 or edge_x == 15) and (edge_z == 0 or edge_z == 15) then -- if node border mapblock
minetest.set_node(pos,{name="tides:offshore_water"})
do return end
end
end
minetest.set_node(pos,{name="tides:seawater"})-- turn every other node into seawater
end
})
end
-- SEAWATER LBM
minetest.register_lbm({
name="tidesandfloods:seawater_lbm",
nodenames = {"tides:seawater"},
run_at_every_load=true,
action = function(pos)
local cardinal_down_pos = {
{x=pos.x+1, y=pos.y-1, z=pos.z},
{x=pos.x-1, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y-1, z=pos.z+1},
{x=pos.x, y=pos.y-1, z=pos.z-1}
}
local cardinal_down_node = {
get_node(cardinal_down_pos[1]).name,
get_node(cardinal_down_pos[2]).name,
get_node(cardinal_down_pos[3]).name,
get_node(cardinal_down_pos[4]).name
}
-- local edge_x = pos.x % 16
-- local edge_z = pos.z % 16
if pos.y > tidesandfloods.sealevel then
-- minetest.after(1, function()
minetest.remove_node(pos)
minetest.set_node(pos,{name="air"})
-- end)
-- CHANGE NODES BELOW
if pos.y == tidesandfloods.sealevel + 1 then
if get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "tides:seawater" then -- make node below wave or mapblock edge
if (pos.x % 16 == 0 or pos.x % 16 == 15) and (pos.z % 16 == 0 or pos.z % 16 == 15) then -- if node border mapblock
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:offshore_water"})
do return end
end
for i = 1,4 do
if water_or_air[cardinal_down_node[i]] == nil then
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:shorewater"})
do return end
break
end
end
end
do return end
end
end
if get_node(pos:offset(0, 1, 0)).name ~= "ignore" then
local node_above = get_node(pos:offset(0, 1, 0)).name
local drawtype = minetest.registered_nodes[node_above].drawtype
if drawtype == "airlike" or drawtype == "flowingliquid" then
if pos.y > tidesandfloods.sealevel then
minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z},{name="air"})
elseif pos.y < tidesandfloods.sealevel then
local tide_diff = tidesandfloods.sealevel-pos.y
for i = 1,tide_diff do
local node_above_i = get_node({x=pos.x, y=pos.y+i, z=pos.z}).name
local drawtype = minetest.registered_nodes[node_above_i].drawtype
if drawtype == "airlike" or drawtype == "flowing_liquid" then
minetest.set_node({x=pos.x, y=pos.y+i, z=pos.z},{name="tides:seawater"})
end
end
end
end
end
end
})
-- SHOREWATER LBM
minetest.register_lbm({
name="tidesandfloods:shorewater_lbm",
nodenames = {"tides:shorewater"},
run_at_every_load=true,
action = function(pos,node)
local cardinal_down_pos = {
{x=pos.x+1, y=pos.y-1, z=pos.z},
{x=pos.x-1, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y-1, z=pos.z+1},
{x=pos.x, y=pos.y-1, z=pos.z-1}
}
local cardinal_down_node = {
get_node(cardinal_down_pos[1]).name,
get_node(cardinal_down_pos[2]).name,
get_node(cardinal_down_pos[3]).name,
get_node(cardinal_down_pos[4]).name
}
if pos.y > tidesandfloods.sealevel then
minetest.remove_node(pos)
if pos.y == tidesandfloods.sealevel + 1 and water_and_friends[get_node({x=pos.x, y=pos.y-1, z=pos.z}).name] then
for i = 1,4 do
if water_or_air[cardinal_down_node[i]] == nil then
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:wave"})
break
else
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:seawater"})
end
-- do return end
end
end
end
local node_above = get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local drawtype = minetest.registered_nodes[node_above].drawtype
if drawtype == "airlike" or drawtype == "flowing_liquid" then
-- if pos.y > tidesandfloods.sealevel then
-- minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z},{name="air"})
if pos.y < tidesandfloods.sealevel then
local tide_diff = tidesandfloods.sealevel-pos.y
for i = 1,tide_diff do
local node_above_i = get_node({x=pos.x, y=pos.y+i, z=pos.z}).name
local drawtype = minetest.registered_nodes[node_above_i].drawtype
if drawtype == "airlike" or drawtype == "flowing_liquid" then
minetest.set_node({x=pos.x, y=pos.y+i, z=pos.z},{name="tides:shorewater"})
end
end
end
end
end
})
-- OFFSHORE_WATER LBM
minetest.register_lbm({
name="tidesandfloods:offshore_water_lbm",
nodenames = {"tides:offshore_water"},
run_at_every_load=true,
action = function(pos)
if pos.y > tidesandfloods.sealevel then
minetest.remove_node(pos)
if pos.y == tidesandfloods.sealevel + 1 and water_and_friends[get_node({x=pos.x, y=pos.y-1, z=pos.z}).name] then
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:offshore_water"})
do return end
end
end
local node_above = get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local drawtype = minetest.registered_nodes[node_above].drawtype
--if air_and_friends[node_above] then
if drawtype == "airlike" or drawtype == "flowing_liquid" then
-- if pos.y > tidesandfloods.sealevel then
-- minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z},{name="air"})
if pos.y < tidesandfloods.sealevel then
local tide_diff = tidesandfloods.sealevel-pos.y
for i = 1,tide_diff do
local node_above_i = get_node({x=pos.x, y=pos.y+i, z=pos.z}).name
if can_it_flood(node_above_i) then
minetest.set_node({x=pos.x, y=pos.y+i, z=pos.z},{name="tides:offshore_water"})
end
end
end
end
end
})
-- WAVE LBM
minetest.register_lbm({
name="tidesandfloods:wave_lbm",
nodenames = {"tides:wave"},
run_at_every_load=true,
action = function(pos)
if pos.y > tidesandfloods.sealevel then
minetest.remove_node(pos)
if pos.y == tidesandfloods.sealevel + 1 and water_and_friends[get_node({x=pos.x, y=pos.y-1, z=pos.z}).name] then
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z},{name="tides:seawater"})
do return end
end
end
local node_above = get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local drawtype = minetest.registered_nodes[node_above].drawtype
if drawtype == "airlike" or drawtype == "flowing_liquid" then
if pos.y < tidesandfloods.sealevel then
minetest.set_node(pos,{name="tides:seawater"})
local tide_diff = tidesandfloods.sealevel-pos.y
for i = 1,tide_diff do
local node_above_i = get_node({x=pos.x, y=pos.y+i, z=pos.z}).name
if can_it_flood(node_above_i) then
minetest.set_node({x=pos.x, y=pos.y+i, z=pos.z},{name="tides:seawater"})
end
end
end
end
end
})