forked from paramat/snowdrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abms.lua
114 lines (104 loc) · 3.06 KB
/
abms.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
if minetest.get_modpath("fire") then
minetest.register_abm({
nodenames = {"fire:basic_flame"}, --Extinguish fire
interval = 6,
chance = 2,
action = function(pos)
pos.y=pos.y+1
if minetest.get_node_light(pos) == 15 and snowdrift.get_precip(pos) ~= "none" and pos.y < snowdrift.upperLimit then
minetest.remove_node(pos)
end
end
})
end
minetest.register_abm({
label = "Grow grass in rain",
nodenames = {"group:grass"}, --Grow grass
interval = 30,
chance = 50,
action = function(pos, node)
if minetest.get_node_light(pos) == 15 and snowdrift.get_precip(pos) == "rain" and pos.y < snowdrift.upperLimit then
local level = tonumber(string.sub(node.name, -1))
if not level then return end
if string.sub(node.name, 1, -2) == "default:grass_" and minetest.registered_nodes["default:grass_"..(level+1)] then
node.name = "default:grass_"..(level+1)
minetest.set_node(pos, node)
end
end
end
})
minetest.register_abm({
label = "Spawn grass in rain",
nodenames = {"default:dirt_with_grass"},
neighbors={"air"},
interval = 60,
chance = 50,
action = function(pos, node)
pos.y = pos.y + 1
if minetest.get_node(pos).name == "air" and minetest.get_node_light(pos) == 15 and snowdrift.get_precip(pos) == "rain" and pos.y < snowdrift.upperLimit then
minetest.set_node(pos, {name="default:grass_1"})
end
end
})
minetest.register_abm({
label = "Shorten grass in sun",
nodenames = {"default:grass_5"},
interval = 30,
chance = 60,
action = function(pos, node)
if not (minetest.get_node_light(pos, 0.5) == 15 and snowdrift.get_precip(pos) == "rain") then
local reduce = math.random(1,4)
node.name = "default:grass_"..(reduce)
minetest.set_node(pos, node)
end
end
})
minetest.register_abm({
label = "Remove grass_1 in sun",
nodenames = {"default:grass_1"},
interval = 30,
chance = 50,
action = function(pos, node)
if not (minetest.get_node_light(pos, 0.5) == 15 and snowdrift.get_precip(pos) == "rain") then
minetest.remove_node(pos)
end
end
})
local mossy = {
["default:cobble"]="default:mossycobble",
}
if minetest.get_modpath("walls") then
mossy["walls:cobble"]="walls:mossycobble"
end
if minetest.get_modpath("stairs") then
stairs.register_stair_and_slab(
"mossycobble",
"default:mossycobble",
{cracky = 3},
{"default_mossycobble.png"},
"Mossy Cobblestone Stair",
"Mossy Cobblestone Slab",
default.node_sound_stone_defaults()
)
mossy["stairs:stair_cobble"] = "stairs:stair_mossycobble"
mossy["stairs:stair_inner_cobble"] = "stairs:stair_inner_mossycobble"
mossy["stairs:stair_outer_cobble"] = "stairs:stair_outer_mossycobble"
mossy["stairs:slab_cobble"] = "stairs:slab_mossycobble"
end
local mossible = {}
for k,_ in pairs(mossy) do
mossible[#mossible + 1] = k
end
minetest.register_abm({
nodenames = mossible, --Mossify cobble
interval = 30,
chance = 30,
action = function(pos, node)
pos.y=pos.y+1
if pos.y < snowdrift.upperLimit and minetest.get_node_light(pos, 0.5) == 15 and snowdrift.get_precip(pos) == "rain" then
pos.y=pos.y-1
node.name=mossy[node.name]
minetest.set_node(pos, node)
end
end
})