-
Notifications
You must be signed in to change notification settings - Fork 2
/
decoration.lua
396 lines (358 loc) · 10 KB
/
decoration.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
-- Modify the parameters in parameter.lua!
-- Decoration engine
sflat = sflat or {}
sflat.biome = sflat.biome or {}
sflat.biome.list = {}
function sflat.biome.register(param)
sflat.biome.list[param.name] = {
decoration = param.decoration or false
}
end
sflat.decoration = sflat.decoration or {}
sflat.decoration.list = {}
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
function sflat.decoration.generate(minp, maxp, LAYERS, data, area, seed, pr)
local biome = sflat.biome.list[sflat.options.biome]
local dcr = biome.decoration
for i = 1, #dcr do
local dcri = sflat.decoration.list[dcr[i][1]] or sflat.decoration.list["nil"]
if LAYERS[#LAYERS][1] == dcri.grows_on then
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
local vi = area:index(x, LAYERS[#LAYERS][3], z)
local chance = dcr[i][2] or 1024
if pr:next(1, chance) == 1 and data[vi] == c_air then
sflat.decoration.list[dcr[i][1]].grow(
{x = x, y = LAYERS[#LAYERS][3], z = z},
data, area, seed,
minp, maxp, pr
)
end
end
end
end
end
end
function sflat.decoration.register(param)
sflat.decoration.list[param.name] = {
chance = param.chance or 1024,
grows_on = param.grows_on or "air",
grow = param.grow or function() return nil end
}
end
---------------------
-- Decoration Data --
---------------------
-- Biome definition (from cold to hot)
sflat.biome.register({
name = ""
})
sflat.biome.register({
name = "Frozen River"
})
sflat.biome.register({
name = "River"
})
-- cold
sflat.biome.register({
name = "Ice Plains"
})
sflat.biome.register({
name = "Ice Plains Spikes",
decoration = {{"ice_spike", 40}}
})
-- medium/lush
sflat.biome.register({
name = "Flower Plains",
decoration = {{"flowers", 20}, {"grass14", 80}}
})
sflat.biome.register({
name = "Plains",
decoration = {{"grass14", 40}, {"grass35", 15}, {"papyrus", 40}, {"flowers", 25}}
})
sflat.biome.register({
name = "Forest",
decoration = {{"normal", 29}, {"grass14", 70}, {"grass35", 15}, {"papyrus", 26}, {"flowers", 28}}
})
sflat.biome.register({
name = "Jungle",
decoration = {{"jungle", 21}, {"jungle_grass", 10}, {"papyrus", 25}, {"flowers", 25}}
})
-- hot
sflat.biome.register({
name = "Desert",
decoration = {{"cactus", 60}, {"dry_shrub", 60}}
})
-- Decoration definition
local c_dirt_grass = sflat.get_content_id("default:dirt_with_grass")
local c_tree = sflat.get_content_id("default:tree")
local c_leaves = sflat.get_content_id("default:leaves")
local c_apple = sflat.get_content_id("default:apple")
local c_jungletree = sflat.get_content_id("default:jungletree")
local c_jungleleaves = sflat.get_content_id("default:jungleleaves")
local c_snow = sflat.get_content_id("default:snow")
-- leaves
local function add_leaves(data, vi, c_leaf, other)
local other = other or c_leaf
if data[vi] == c_air or data[vi] == c_ignore or data[vi] == other then
data[vi] = c_leaf
end
end
-- normal tree
function sflat.decoration.normal_tree(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local is_apple_tree = false
if pr:next(1, 100) < 25 then
is_apple_tree = true
end
local th = pr:next(4, 5)
for yy = y, y + th do
local vi = area:index(x, yy, z)
data[vi] = c_tree
end
local y = y + th - 1
for xx = x - 1, x + 1 do
for yy = y - 1, y + 1 do
for zz = z - 1, z + 1 do
if area:contains(xx, yy, zz) then
local vi = area:index(xx, yy, zz)
if pr:next(1, 100) > 25 then
add_leaves(data, vi, c_leaves)
else
if is_apple_tree == true then
add_leaves(data, vi, c_apple)
else
add_leaves(data, vi, c_leaves)
end
end
end
end
end
end
for ii = 1, 8 do
local xx = x + pr:next(-2, 2)
local yy = y + pr:next(-1, 2)
local zz = z + pr:next(-2, 2)
for xxx = 0, 1 do
for yyy = 0, 1 do
for zzz = 0, 1 do
if area:contains(xx + xxx, yy + yyy, zz + zzz) then
local vi = area:index(xx + xxx, yy + yyy, zz + zzz)
add_leaves(data, vi, c_leaves, c_leaves)
end
end
end
end
end
end
sflat.decoration.register({
name = "normal",
chance = 15,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
sflat.decoration.normal_tree(pos, data, area, seed, minp, maxp, pr)
end
})
-- jungle tree
function sflat.decoration.jungle_tree(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local th = pr:next(8, 12)
for zz = z - 1, z + 1, maxp.z do
for xx = x - 1, x + 1, maxp.x do
if pr:next(1, 3) >= 2 and area:contains(xx, y, zz) then
local vi = area:index(xx, y, zz)
add_leaves(data, vi, c_jungletree)
end
end
end
for yy = y, y + th do
local vi = area:index(x, yy, z)
data[vi] = c_jungletree
end
local y = y + th - 1
for xx = x - 1, x + 1 do
for yy = y - 1, y + 1 do
for zz = z - 1, z + 1 do
if area:contains(xx, yy, zz) then
local vi = area:index(xx, yy, zz)
add_leaves(data, vi, c_jungleleaves)
end
end
end
end
for ii = 1, 30 do
local xx = x + pr:next(-3, 3)
local yy = y + pr:next(-2, 2)
local zz = z + pr:next(-3, 3)
for xxx = 0, 1 do
for yyy = 0, 1 do
for zzz = 0, 1 do
if area:contains(xx + xxx, yy + yyy, zz + zzz) then
local vi = area:index(xx + xxx, yy + yyy, zz + zzz)
add_leaves(data, vi, c_jungleleaves, c_jungleleaves)
end
end
end
end
end
end
sflat.decoration.register({
name = "jungle",
chance = 10,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
sflat.decoration.jungle_tree(pos, data, area, seed, minp, maxp, pr)
end
})
-- small plants
local c_cactus = sflat.get_content_id("default:cactus")
local c_dry_shrub = sflat.get_content_id("default:dry_shrub")
local c_papyrus = sflat.get_content_id("default:papyrus")
local c_junglegrass = sflat.get_content_id("default:junglegrass")
local c_grass_1 = sflat.get_content_id("default:grass_1")
local c_grass_2 = sflat.get_content_id("default:grass_2")
local c_grass_3 = sflat.get_content_id("default:grass_3")
local c_grass_4 = sflat.get_content_id("default:grass_4")
local c_grass_5 = sflat.get_content_id("default:grass_5")
local c_grasses = {c_grass_1, c_grass_2, c_grass_3, c_grass_4, c_grass_5}
-- dry shrub
sflat.decoration.register({
name = "dry_shrub",
chance = 50,
grows_on = "default:sand",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
data[vi] = c_dry_shrub
end
end
})
-- cactus
sflat.decoration.register({
name = "cactus",
chance = 50,
grows_on = "default:desert_sand",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
for yy = math.max(y, minp.y), math.min(y + pr:next(1, 4), maxp.y) do
data[area:index(x, yy, z)] = c_cactus
end
end
})
-- papyrus
sflat.decoration.register({
name = "papyrus",
chance = 10,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
for yy = math.max(y, minp.y), math.min(y + pr:next(2, 4), maxp.y) do
data[area:index(x, yy, z)] = c_papyrus
end
end
})
-- jungle grass
sflat.decoration.register({
name = "jungle_grass",
chance = 25,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
data[vi] = c_junglegrass
end
end
})
-- grass 1-4
sflat.decoration.register({
name = "grass14",
chance = 60,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
data[vi] = c_grasses[pr:next(1, 4)]
end
end
})
-- grass 3-5
sflat.decoration.register({
name = "grass35",
chance = 5,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
data[vi] = c_grasses[pr:next(3, 5)]
end
end
})
local c_chrysanthemum_green = sflat.get_content_id("flowers:chrysanthemum_green")
local c_dandelion_white = sflat.get_content_id("flowers:dandelion_white")
local c_dandelion_yellow = sflat.get_content_id("flowers:dandelion_yellow")
local c_geranium = sflat.get_content_id("flowers:geranium")
local c_rose = sflat.get_content_id("flowers:rose")
local c_tulip = sflat.get_content_id("flowers:tulip")
local c_tulip_black = sflat.get_content_id("flowers:tulip_black")
local c_viola = sflat.get_content_id("flowers:viola")
local c_flowers = {
c_chrysanthemum_green, c_dandelion_white, c_dandelion_yellow, c_geranium,
c_rose, c_tulip, c_tulip_black, c_viola, c_flowers
}
-- flowers
sflat.decoration.register({
name = "flowers",
chance = 3,
grows_on = "default:dirt_with_grass",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
data[vi] = c_flowers[pr:next(1, 6)]
end
end
})
local c_ice = sflat.get_content_id("default:ice")
-- ice spikes
sflat.decoration.register({
name = "ice_spike",
chance = 25,
grows_on = "default:dirt_with_snow",
grow = function(pos, data, area, seed, minp, maxp, pr)
local x, y, z = pos.x, pos.y, pos.z
local vi = area:index(x, y, z)
if data[vi] == c_air or data[vi] == c_ignore then
local h = pr:next(4,7)
for u = -1, 1 do
for i = -1, 1 do
local vi = area:index(x + u, y - 1, z + i)
if data[vi] ~= c_air or data[vi] ~= c_ignore then
for o = 0, h do
local vi = area:index(x + u, y + o, z + i)
data[vi] = c_ice
end
end
end
end
j = h + pr:next(2, 3)
for u = 0, 1 do
for i = -1, 0 do
local vi = area:index(x + u, y - 1, z + i)
if data[vi] ~= c_air or data[vi] ~= c_ignore then
for o = h, j do
local vi = area:index(x + u, y + o, z + i)
data[vi] = c_ice
end
end
end
end
local vi = area:index(x, y + j, z)
data[vi] = c_ice
end
end
})