summaryrefslogtreecommitdiff
path: root/mods/vzxv/abms.lua
blob: d389398392254280a009c307907a5bae153d9459 (plain)
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
-- moist dirt dries in air
minetest.register_abm {
	nodenames = {"vzxv:moistdirt"},
	neighbors = {"air"},
	interval = 45,
	chance = 5,
	catch_up = true,
	action = function (pos, node)
		if not vzxv.check_adjacent(pos, "vzxv:water")
				and not vzxv.check_adjacent(pos, "vzxv:flowingwater")
				and vzxv.check_adjacent(pos, "air") then
			minetest.set_node(pos, {name="vzxv:dirt"})
		end
	end,
}

-- dry dirt moists in water
minetest.register_abm {
	nodenames = {"vzxv:dirt"},
	neighbors = {"vzxv:water","vzxv:flowingwater"},
	interval = 15,
	chance = 3,
	catch_up = true,
	action = function (pos, node)
		minetest.set_node(pos, {name="vzxv:moistdirt"})
	end,
}

-- grass grows on soil
minetest.register_abm {
	nodenames = {"vzxv:dirt","vzxv:moistdirt"},
	neighbors = {"group:grassy"},
	interval = 60,
	chance = 2.5,
	catch_up = true,
	action = function (pos, node)
		local above = minetest.get_node{x=pos.x,y=pos.y+1,z=pos.z}
		if above.name ~= "air" then return end

		if node.name == "vzxv:moistdirt" then
			minetest.set_node(pos, {name="vzxv:moistgrass"})
		elseif math.random(2) == 1 then
			minetest.set_node(pos, {name="vzxv:grass"})
		end
	end,
}

-- grass dies when covered
minetest.register_abm {
	nodenames = {"group:grassy"},
	interval = 30,
	chance = 1,
	action = function(pos, node)
		local above = minetest.get_node{x=pos.x,y=pos.y+1,z=pos.z}
		if above.name == "air" or above.name == "ignore" then
			return
		end
		if minetest.get_item_group(above.name, "small") then
			return
		end
		if node.name == "vzxv:moistgrass" then
			minetest.set_node(pos, {name="vzxv:moistdirt"})
		elseif node.name == "vzxv:grass" then
			minetest.set_node(pos, {name="vzxv:dirt"})
		end
	end,
}