dirt.lua 10.6 KB
Newer Older
1

TenPlus1's avatar
TenPlus1 committed
2
3
local S = ethereal.intllib

tenplus1's avatar
tenplus1 committed
4
-- override default dirt (to stop caves cutting away dirt)
5
minetest.override_item("default:dirt", {is_ground_content = ethereal.cavedirt})
Milan's avatar
Milan committed
6
minetest.override_item("default:dirt_with_grass", {groups = {crumbly = 3, soil = 1, grass = 1}})
7
--[[ green dirt
tenplus1's avatar
tenplus1 committed
8
minetest.register_node("ethereal:green_dirt", {
TenPlus1's avatar
TenPlus1 committed
9
	description = S("Green Dirt"),
10
11
12
13
14
	tiles = {
		"default_grass.png",
		"default_dirt.png",
		"default_dirt.png^default_grass_side.png"
	},
15
	is_ground_content = ethereal.cavedirt,
16
	groups = {crumbly = 3, soil = 1, ethereal_grass = 1},
17
18
19
20
21
	soil = {
		base = "ethereal:green_dirt",
		dry = "farming:soil",
		wet = "farming:soil_wet"
	},
tenplus1's avatar
tenplus1 committed
22
	drop = "default:dirt",
23
24
25
	sounds = default.node_sound_dirt_defaults({
		footstep = {name = "default_grass_footstep", gain = 0.25},
	}),
26
})]]
Milan's avatar
Milan committed
27
--minetest.register_alias("ethereal:green_dirt", "default:dirt_with_grass")
tenplus1's avatar
tenplus1 committed
28

tenplus1's avatar
tenplus1 committed
29
-- dry dirt
tenplus1's avatar
tenplus1 committed
30
minetest.register_node("ethereal:dry_dirt", {
TenPlus1's avatar
TenPlus1 committed
31
	description = S("Dried Dirt"),
tenplus1's avatar
tenplus1 committed
32
	tiles = {"ethereal_dry_dirt.png"},
33
	is_ground_content = ethereal.cavedirt,
34
	groups = {crumbly = 3},
35
36
37
	sounds = default.node_sound_dirt_defaults({
		footstep = {name = "default_grass_footstep", gain = 0.25},
	}),
tenplus1's avatar
tenplus1 committed
38
39
40
41
42
43
44
45
46
})

minetest.register_craft({
	type = "cooking",
	output = "ethereal:dry_dirt",
	recipe = "default:dirt",
	cooktime = 3,
})

47
local dirts = {
Milan's avatar
Milan committed
48
	"Bamboo", "Jungle", "Mesa", "Grove", "Prairie", "Cold",
Milan's avatar
Milan committed
49
	"Crystal", "Mushroom", "Fiery", "Gray", "Swamp"
tenplus1's avatar
tenplus1 committed
50
51
}

52
for n = 1, #dirts do
tenplus1's avatar
tenplus1 committed
53

54
	local desc = dirts[n]
tenplus1's avatar
tenplus1 committed
55
56
57
	local name = desc:lower()

	minetest.register_node("ethereal:"..name.."_dirt", {
TenPlus1's avatar
TenPlus1 committed
58
		description = S(desc.." Dirt"),
59
60
61
62
63
		tiles = {
			"ethereal_grass_"..name.."_top.png",
			"default_dirt.png",
			"default_dirt.png^ethereal_grass_"..name.."_side.png"
		},
64
		is_ground_content = ethereal.cavedirt,
65
		groups = {crumbly = 3, soil = 1, ethereal_grass = 1},
66
67
68
69
70
		soil = {
			base = "ethereal:"..name.."_dirt",
			dry = "farming:soil",
			wet = "farming:soil_wet"
		},
tenplus1's avatar
tenplus1 committed
71
		drop = "default:dirt",
72
73
74
		sounds = default.node_sound_dirt_defaults({
			footstep = {name = "default_grass_footstep", gain = 0.25},
		}),
tenplus1's avatar
tenplus1 committed
75
76
77
78
	})

end

79
80
81
82
83
-- re-register dirt types for abm
dirts = {
	"ethereal:bamboo_dirt", "ethereal:jungle_dirt", "ethereal:grove_dirt",
	"ethereal:prairie_dirt", "ethereal:cold_dirt", "ethereal:crystal_dirt",
	"ethereal:mushroom_dirt", "ethereal:fiery_dirt", "ethereal:gray_dirt",
TenPlus1's avatar
TenPlus1 committed
84
	"default:dirt_with_grass", "default:dirt_with_dry_grass", "ethereal:green_dirt",
Milan's avatar
Milan committed
85
	"default:dirt_with_snow", "default:dirt_with_dry_grass", "ethereal:mesa_dirt",
Milan's avatar
Milan committed
86
	"ethereal:swamp_dirt"
87
}
tenplus1's avatar
tenplus1 committed
88

89
-- check surrounding grass and change dirt to same colour
TenPlus1's avatar
TenPlus1 committed
90
local grass_spread = function(pos, node)
91

TenPlus1's avatar
TenPlus1 committed
92
	local above = {x = pos.x, y = pos.y + 1, z = pos.z}
93

Milan's avatar
Milan committed
94
	-- not enough light
TenPlus1's avatar
TenPlus1 committed
95
96
97
	if (minetest.get_node_light(above) or 0) < 13 then
		return
	end
98

TenPlus1's avatar
TenPlus1 committed
99
100
101
	local name = minetest.get_node(above).name
	local def = minetest.registered_nodes[name]

Milan's avatar
Milan committed
102
	-- water above grass
TenPlus1's avatar
TenPlus1 committed
103
104
105
106
107
108
109
110
111
	if name == "ignore" or not def or def.liquidtype ~= "none" then
		return
	end

	local curr_max, curr_type, num  = 0, ""

	-- find all default and ethereal grasses in area around dirt
	local positions, grasses = minetest.find_nodes_in_area(
		{x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
Milan's avatar
Milan committed
112
		{x = pos.x + 1, y = pos.y + 2, z = pos.z + 1}, dirts)
TenPlus1's avatar
TenPlus1 committed
113
114
115
116
117
118
119
120
121

	-- count new grass nodes
	for n = 1, #dirts do

		num = grasses[ dirts[n] ] or 0

		if num > curr_max then
			curr_max = num
			curr_type = dirts[n]
122
		end
TenPlus1's avatar
TenPlus1 committed
123
	end
124

TenPlus1's avatar
TenPlus1 committed
125
126
127
128
	-- no grass nearby, keep as dirt
	if curr_type == "" then
		return
	end
129

TenPlus1's avatar
TenPlus1 committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	minetest.swap_node(pos, {name = curr_type})
end

-- any grass with a block above will turn into dirt
local grass_devoid = function(pos, node)

	local above = {x = pos.x, y = pos.y + 1, z = pos.z}
	local name = minetest.get_node(above).name
	local nodedef = minetest.registered_nodes[name]

	if name ~= "ignore" and nodedef and not ((nodedef.sunlight_propagates or
			nodedef.paramtype == "light") and
			nodedef.liquidtype == "none") then

		minetest.swap_node(pos, {name = "default:dirt"})
	end
end

-- flower spread, also crystal and fire flower regeneration
local flower_spread = function(pos, node)

TenPlus1's avatar
TenPlus1 committed
151
	if (minetest.get_node_light(pos) or 0) < 13 then
TenPlus1's avatar
TenPlus1 committed
152
153
154
155
156
		return
	end

	local pos0 = {x = pos.x - 4, y = pos.y - 2, z = pos.z - 4}
	local pos1 = {x = pos.x + 4, y = pos.y + 2, z = pos.z + 4}
TenPlus1's avatar
TenPlus1 committed
157

158
	local num = #minetest.find_nodes_in_area(pos0, pos1, "group:flora")
TenPlus1's avatar
TenPlus1 committed
159

160
161
162
163
	-- stop flowers spreading too much just below top of map block
	if minetest.find_node_near(pos, 2, "ignore") then
		return
	end
TenPlus1's avatar
TenPlus1 committed
164
165
166
167
168
169
170
171
172
173

	if num > 3
	and node.name == "ethereal:crystalgrass" then

		local grass = minetest.find_nodes_in_area_under_air(
			pos0, pos1, {"ethereal:crystalgrass"})

		if #grass > 4
		and not minetest.find_node_near(pos, 4, {"ethereal:crystal_spike"}) then

TenPlus1's avatar
TenPlus1 committed
174
			pos = grass[math.random(#grass)]
TenPlus1's avatar
TenPlus1 committed
175

TenPlus1's avatar
TenPlus1 committed
176
			pos.y = pos.y - 1
TenPlus1's avatar
TenPlus1 committed
177

TenPlus1's avatar
TenPlus1 committed
178
			if minetest.get_node(pos).name == "ethereal:crystal_dirt" then
TenPlus1's avatar
TenPlus1 committed
179

TenPlus1's avatar
TenPlus1 committed
180
				pos.y = pos.y + 1
TenPlus1's avatar
TenPlus1 committed
181

TenPlus1's avatar
TenPlus1 committed
182
				minetest.swap_node(pos, {name = "ethereal:crystal_spike"})
TenPlus1's avatar
TenPlus1 committed
183
			end
184
185
		end

TenPlus1's avatar
TenPlus1 committed
186
187
188
189
190
191
192
193
194
195
196
		return

	elseif num > 3
	and node.name == "ethereal:dry_shrub" then

		local grass = minetest.find_nodes_in_area_under_air(
			pos0, pos1, {"ethereal:dry_shrub"})

		if #grass > 8
		and not minetest.find_node_near(pos, 4, {"ethereal:fire_flower"}) then

TenPlus1's avatar
TenPlus1 committed
197
			pos = grass[math.random(#grass)]
TenPlus1's avatar
TenPlus1 committed
198

TenPlus1's avatar
TenPlus1 committed
199
			pos.y = pos.y - 1
200

TenPlus1's avatar
TenPlus1 committed
201
			if minetest.get_node(pos).name == "ethereal:fiery_dirt" then
202

TenPlus1's avatar
TenPlus1 committed
203
				pos.y = pos.y + 1
204

TenPlus1's avatar
TenPlus1 committed
205
				minetest.swap_node(pos, {name = "ethereal:fire_flower"})
tenplus1's avatar
tenplus1 committed
206
207
			end
		end
208

TenPlus1's avatar
TenPlus1 committed
209
210
211
212
		return

	elseif num > 3 then
		return
213
	end
tenplus1's avatar
tenplus1 committed
214

TenPlus1's avatar
TenPlus1 committed
215
216
217
218
219
	local seedling = minetest.find_nodes_in_area_under_air(
		pos0, pos1, {"group:soil"})

	if #seedling > 0 then

TenPlus1's avatar
TenPlus1 committed
220
		pos = seedling[math.random(#seedling)]
TenPlus1's avatar
TenPlus1 committed
221

TenPlus1's avatar
TenPlus1 committed
222
223
224
225
		-- default farming has desert sand as soil, so dont spread on this
		if minetest.get_node(pos).name == "default:desert_sand" then
			return
		end
TenPlus1's avatar
TenPlus1 committed
226

TenPlus1's avatar
TenPlus1 committed
227
228
229
		pos.y = pos.y + 1

		if (minetest.get_node_light(pos) or 0) < 13 then
TenPlus1's avatar
TenPlus1 committed
230
231
			return
		end
232

TenPlus1's avatar
TenPlus1 committed
233
		minetest.swap_node(pos, {name = node.name})
TenPlus1's avatar
TenPlus1 committed
234
235
236
237
238
239
240
241
242
243
	end
end

-- grow papyrus up to 4 high and bamboo up to 8 high
local grow_papyrus = function(pos, node)

	local oripos = pos.y
	local high = 4

	pos.y = pos.y - 1
244

TenPlus1's avatar
TenPlus1 committed
245
	local nod = minetest.get_node_or_nil(pos)
246

TenPlus1's avatar
TenPlus1 committed
247
248
249
250
251
252
253
254
255
	if not nod
	or minetest.get_item_group(nod.name, "soil") < 1
	or minetest.find_node_near(pos, 3, {"group:water"}) == nil then
		return
	end

	if node.name == "ethereal:bamboo" then
		high = 8
	end
256

TenPlus1's avatar
TenPlus1 committed
257
	pos.y = pos.y + 1
258

TenPlus1's avatar
TenPlus1 committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
	local height = 0

	while height < high
	and minetest.get_node(pos).name == node.name do
		height = height + 1
		pos.y = pos.y + 1
	end

	nod = minetest.get_node_or_nil(pos)

	if nod
	and nod.name == "air"
	and height < high then

		if node.name == "ethereal:bamboo"
		and height == (high - 1) then

			ethereal.grow_bamboo_tree({x = pos.x, y = oripos, z = pos.z})
		else
			minetest.swap_node(pos, {name = node.name})
tenplus1's avatar
tenplus1 committed
279
280
		end
	end
TenPlus1's avatar
TenPlus1 committed
281
282
283
284
285
286
287
288
289
290
291
292
293
294

end

-- loop through active abm's
for _, ab in pairs(minetest.registered_abms) do

	local label = ab.label or ""
	local node1 = ab.nodenames and ab.nodenames[1] or ""
	local node2 = ab.nodenames and ab.nodenames[2] or ""
	local neigh = ab.neighbors and ab.neighbors[1] or ""

	-- find dirt to grass abm and replace with spread function
	if label == "Grass spread"
	or (node1 == "default:dirt"
Milan's avatar
Milan committed
295
	and neigh == "group:grass") then
TenPlus1's avatar
TenPlus1 committed
296
297
298

		--ab.interval = 2
		--ab.chance = 1
Milan's avatar
Milan committed
299
		ab.nodenames = {"default:dirt"}
TenPlus1's avatar
TenPlus1 committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
		ab.neighbors = {"air"}
		ab.action = grass_spread

	-- find grass devoid of light to dirt abm and change to devoid function
	elseif label == "Grass covered"
	or (node1 == "default:dirt_with_grass"
	and node2 == "default:dirt_with_dry_grass") then

		--ab.interval = 2
		--ab.chance = 1
		ab.nodenames = {
			"default:dirt_with_grass", "default:dirt_with_dry_grass",
			"default:dirt_with_snow", "group:ethereal_grass"
		}
		ab.action = grass_devoid

	-- find flower spread abm and change to spread function
	elseif label == "Flower spread"
	or node1 == "group:flora" then

TenPlus1's avatar
TenPlus1 committed
320
		--ab.interval = 1
TenPlus1's avatar
TenPlus1 committed
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
		--ab.chance = 1
		ab.nodenames = {"group:flora"}
		ab.neighbors = {"group:soil"}
		ab.action = flower_spread

	-- find grow papyrus abm and change to grow_papyrus function
	elseif label == "Grow papyrus"
	or node1 == "default:papyrus" then

		--ab.interval = 2
		--ab.chance = 1
		ab.nodenames = {"default:papyrus", "ethereal:bamboo"}
		ab.neighbors = {"group:soil"}
		ab.action = grow_papyrus
	end
end
tenplus1's avatar
tenplus1 committed
337

338
-- If Baked Clay mod not active, make Red, Orange and Grey nodes
339
if not minetest.get_modpath("illuna_extra") then
tenplus1's avatar
tenplus1 committed
340
341

	minetest.register_node(":bakedclay:red", {
TenPlus1's avatar
TenPlus1 committed
342
		description = S("Red Baked Clay"),
tenplus1's avatar
tenplus1 committed
343
		tiles = {"baked_clay_red.png"},
344
		groups = {cracky = 3},
345
		is_ground_content = ethereal.cavedirt,
tenplus1's avatar
tenplus1 committed
346
347
		sounds = default.node_sound_stone_defaults(),
	})
348

tenplus1's avatar
tenplus1 committed
349
	minetest.register_node(":bakedclay:orange", {
TenPlus1's avatar
TenPlus1 committed
350
		description = S("Orange Baked Clay"),
tenplus1's avatar
tenplus1 committed
351
		tiles = {"baked_clay_orange.png"},
352
		groups = {cracky = 3},
353
		is_ground_content = ethereal.cavedirt,
tenplus1's avatar
tenplus1 committed
354
355
		sounds = default.node_sound_stone_defaults(),
	})
356
357

	minetest.register_node(":bakedclay:grey", {
TenPlus1's avatar
TenPlus1 committed
358
		description = S("Grey Baked Clay"),
359
360
		tiles = {"baked_clay_grey.png"},
		groups = {cracky = 3},
361
		is_ground_content = ethereal.cavedirt,
362
363
364
		sounds = default.node_sound_stone_defaults(),
	})

365
end
366
367
368
369

-- Quicksand (old style, sinking inside shows black instead of yellow effect,
-- works ok with noclip enabled though)
minetest.register_node("ethereal:quicksand", {
TenPlus1's avatar
TenPlus1 committed
370
	description = S("Quicksand"),
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
	tiles = {"default_sand.png"},
	drop = "default:sand",
	liquid_viscosity = 15,
	liquidtype = "source",
	liquid_alternative_flowing = "ethereal:quicksand",
	liquid_alternative_source = "ethereal:quicksand",
	liquid_renewable = false,
	liquid_range = 0,
	drowning = 1,
	walkable = false,
	climbable = false,
	post_effect_color = {r = 230, g = 210, b = 160, a = 245},
	groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
	sounds = default.node_sound_sand_defaults(),
})

-- Quicksand (new style, sinking inside shows yellow effect with or without noclip,
-- but old quicksand is shown as black until block placed nearby to update light)
minetest.register_node("ethereal:quicksand2", {
TenPlus1's avatar
TenPlus1 committed
390
	description = S("Quicksand"),
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
	tiles = {"default_sand.png"},
	drawtype = "glasslike",
	paramtype = "light",
	drop = "default:sand",
	liquid_viscosity = 15,
	liquidtype = "source",
	liquid_alternative_flowing = "ethereal:quicksand2",
	liquid_alternative_source = "ethereal:quicksand2",
	liquid_renewable = false,
	liquid_range = 0,
	drowning = 1,
	walkable = false,
	climbable = false,
	post_effect_color = {r = 230, g = 210, b = 160, a = 245},
	groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
	sounds = default.node_sound_sand_defaults(),
})
408
409
410
411
412
413
414
415
416
417
418
419
420

-- craft quicksand
minetest.register_craft({
	output = "ethereal:quicksand2",
	recipe = {
		{"group:sand", "group:sand", "group:sand"},
		{"group:sand", "group:water_bucket", "group:sand"},
		{"group:sand", "group:sand", "group:sand"},
	},
	replacements = {
		{"group:water_bucket", "bucket:bucket_empty"}
	}
})