-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabms.lua
201 lines (140 loc) · 4.45 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
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
--Places Snow on ground
if mymonths.snow_on_ground == true then
minetest.register_abm({
nodenames = {"default:leaves", "default:dirt", "default:dirt_with_grass"},
neighbors = {"air"},
interval = 8,
chance = 20,
action = function (pos, node)
local biome_jungle = minetest.find_node_near(pos, 5, "default:jungletree", "default:junglegrass")
pos.y = pos.y + 1 -- check above node
local na = minetest.get_node(pos)
if (mymonths.weather == "snow" or mymonths.weather == "snowstorm")
and biome_jungle == nil then
if minetest.get_node_light(pos, 0.5) == 15
and na.name == "air" then
minetest.set_node(pos, {name = "mymonths:snow_cover_1"})
end
end
end
})
--Replace grass and flowers with snow
minetest.register_abm({
nodenames = {"group:flora", "mymonths:puddle"},
neighbors = {"air"},
interval = 8,
chance = 20,
action = function (pos, node)
local biome_jungle = minetest.find_node_near(pos, 5, "default:jungletree","default:junglegrass")
if mymonths.weather == "snow"
and biome_jungle == nil then
if minetest.get_node_light({
x = pos.x,
y = pos.y + 1,
z = pos.z}, 0.5) == 15 then
minetest.set_node(pos, {name="mymonths:snow_cover_1"})
end
end
end
})
-- Changes snow to larger snow
minetest.register_abm({
nodenames = {"mymonths:snow_cover_1", "mymonths:snow_cover_2", "mymonths:snow_cover_3", "mymonths:snow_cover_4"},
neighbors = {"default:dirt", "default:dirt_with_grass"},
interval = 20,
chance = 40,
action = function (pos, node)
if mymonths.weather2 == "snow"
or mymonths.weather2 == "snowstorm" then
if mymonths.weather2 == "snow"
and math.random(1, 4) ~= 1 then
return
end
if node.name == "mymonths:snow_cover_1" then
minetest.set_node(pos, {name = "mymonths:snow_cover_2"})
elseif node.name == "mymonths:snow_cover_2" then
minetest.set_node(pos, {name = "mymonths:snow_cover_3"})
elseif node.name == "mymonths:snow_cover_3" then
minetest.set_node(pos, {name = "mymonths:snow_cover_4"})
elseif node.name == "mymonths:snow_cover_4" then
minetest.set_node(pos, {name = "mymonths:snow_cover_5"})
end
end
end
})
-- Snow Melting
minetest.register_abm({
nodenames = {"mymonths:snow_cover_1", "mymonths:snow_cover_2", "mymonths:snow_cover_3", "mymonths:snow_cover_4", "mymonths:snow_cover_5"},
interval = 10,
chance = 1,
action = function (pos, node)
if mymonths.month_counter == 12
or mymonths.month_counter == 1
or mymonths.month_counter == 2 then
return
end
-- remove snow if month is april
if mymonths.month_counter == 4 then
minetest.remove_node(pos)
return
end
if math.random(1, 100) == 1 then
if node.name == "mymonths:snow_cover_2" then
minetest.set_node(pos, {name = "mymonths:snow_cover_1"})
elseif node.name == "mymonths:snow_cover_3" then
minetest.set_node(pos, {name = "mymonths:snow_cover_2"})
elseif node.name == "mymonths:snow_cover_4" then
minetest.set_node(pos, {name = "mymonths:snow_cover_3"})
elseif node.name == "mymonths:snow_cover_5" then
minetest.set_node(pos, {name = "mymonths:snow_cover_4"})
elseif node.name == "mymonths:snow_cover_1" then
local nu = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
if nu.name == "default:dirt_with_grass"
or nu.name == "default:dirt" then
minetest.set_node(pos, {name = "mymonths:puddle"})
else
minetest.remove_node(pos)
end
end
end
end
})
end -- END IF
if mymonths.use_puddles == true then
-- Makes Puddles when raining
minetest.register_abm({
nodenames = {"default:dirt", "default:dirt_with_grass"},
neighbors = {"default:air"},
interval = 10,
chance = 50,
action = function (pos, node)
if mymonths.weather == "rain" then
-- return if puddle found nearby
if minetest.find_node_near(pos, 20, "mymonths:puddle") then
return
end
pos.y = pos.y + 1
-- otherwise place puddle in empty space
if minetest.get_node_light(pos, 0.5) == 15
and minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name = "mymonths:puddle"})
end
end
end
})
-- Makes puddles dry up when not raining
minetest.register_abm({
nodenames = {"mymonths:puddle"},
neighbors = {"air"},
interval = 5,
chance = 5,
action = function (pos, node)
if mymonths.weather == "clear" then
minetest.remove_node(pos)
elseif mymonths.weather == "snow"
or mymonths.weather == "snowstorm" then
minetest.set_node(pos, {name = "mymonths:snow_cover_1"})
end
end
})
end -- END IF