-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
259 lines (231 loc) · 6.41 KB
/
init.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
-- firefly/init.lua
-- Load support for MT game translation.
local S = minetest.get_translator("fireflies")
-- Legacy compatibility, when pointabilities don't exist, pointable is set to true.
local pointable_compat = not minetest.features.item_specific_pointabilities
minetest.register_node("fireflies:firefly", {
description = S("Firefly"),
drawtype = "plantlike",
tiles = {{
name = "fireflies_firefly_animated.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}},
inventory_image = "fireflies_firefly.png",
wield_image = "fireflies_firefly.png",
waving = 1,
paramtype = "light",
sunlight_propagates = true,
buildable_to = true,
walkable = false,
pointable = pointable_compat,
groups = {catchable = 1},
selection_box = {
type = "fixed",
fixed = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
},
light_source = 6,
floodable = true,
on_construct = function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_timer = function(pos, elapsed)
if minetest.get_node_light(pos) > 11 then
minetest.set_node(pos, {name = "fireflies:hidden_firefly"})
end
minetest.get_node_timer(pos):start(30)
end
})
minetest.register_node("fireflies:hidden_firefly", {
description = S("Hidden Firefly"),
drawtype = "airlike",
inventory_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
wield_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
floodable = true,
on_construct = function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_timer = function(pos, elapsed)
if minetest.get_node_light(pos) <= 11 then
minetest.set_node(pos, {name = "fireflies:firefly"})
end
minetest.get_node_timer(pos):start(30)
end
})
-- bug net
minetest.register_tool("fireflies:bug_net", {
description = S("Bug Net"),
inventory_image = "fireflies_bugnet.png",
pointabilities = {nodes = {["group:catchable"] = true}},
tool_capabilities = {
groupcaps = {
catchable = { maxlevel = 1, uses = 256, times = { [1] = 0, [2] = 0, [3] = 0 } }
},
},
})
minetest.register_craft( {
output = "fireflies:bug_net",
recipe = {
{"farming:string", "farming:string"},
{"farming:string", "farming:string"},
{"group:stick", ""}
}
})
-- firefly in a bottle
minetest.register_node("fireflies:firefly_bottle", {
description = S("Firefly in a Bottle"),
inventory_image = "fireflies_bottle.png",
wield_image = "fireflies_bottle.png",
tiles = {{
name = "fireflies_bottle_animated.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}},
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
light_source = 9,
walkable = false,
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
},
sounds = default.node_sound_glass_defaults(),
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local lower_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
if minetest.is_protected(pos, player:get_player_name()) or
minetest.get_node(lower_pos).name ~= "air" then
return
end
local upper_pos = {x = pos.x, y = pos.y + 2, z = pos.z}
local firefly_pos
if not minetest.is_protected(upper_pos, player:get_player_name()) and
minetest.get_node(upper_pos).name == "air" then
firefly_pos = upper_pos
elseif not minetest.is_protected(lower_pos, player:get_player_name()) then
firefly_pos = lower_pos
end
if firefly_pos then
minetest.set_node(pos, {name = "vessels:glass_bottle"})
minetest.set_node(firefly_pos, {name = "fireflies:firefly"})
minetest.get_node_timer(firefly_pos):start(1)
end
end
})
minetest.register_craft( {
output = "fireflies:firefly_bottle",
recipe = {
{"fireflies:firefly"},
{"vessels:glass_bottle"}
}
})
-- register fireflies as decorations
if minetest.get_mapgen_setting("mg_name") == "v6" then
minetest.register_decoration({
name = "fireflies:firefly_low",
deco_type = "simple",
place_on = "default:dirt_with_grass",
place_offset_y = 2,
sidelen = 80,
fill_ratio = 0.0002,
y_max = 31000,
y_min = 1,
decoration = "fireflies:hidden_firefly",
})
minetest.register_decoration({
name = "fireflies:firefly_high",
deco_type = "simple",
place_on = "default:dirt_with_grass",
place_offset_y = 3,
sidelen = 80,
fill_ratio = 0.0002,
y_max = 31000,
y_min = 1,
decoration = "fireflies:hidden_firefly",
})
else
minetest.register_decoration({
name = "fireflies:firefly_low",
deco_type = "simple",
place_on = {
"default:dirt_with_grass",
"default:dirt_with_coniferous_litter",
"default:dirt_with_rainforest_litter",
"default:dirt"
},
place_offset_y = 2,
sidelen = 80,
fill_ratio = 0.0005,
biomes = {
"deciduous_forest",
"coniferous_forest",
"rainforest",
"rainforest_swamp"
},
y_max = 31000,
y_min = -1,
decoration = "fireflies:hidden_firefly",
})
minetest.register_decoration({
name = "fireflies:firefly_high",
deco_type = "simple",
place_on = {
"default:dirt_with_grass",
"default:dirt_with_coniferous_litter",
"default:dirt_with_rainforest_litter",
"default:dirt"
},
place_offset_y = 3,
sidelen = 80,
fill_ratio = 0.0005,
biomes = {
"deciduous_forest",
"coniferous_forest",
"rainforest",
"rainforest_swamp"
},
y_max = 31000,
y_min = -1,
decoration = "fireflies:hidden_firefly",
})
end
-- get decoration IDs
local firefly_low = minetest.get_decoration_id("fireflies:firefly_low")
local firefly_high = minetest.get_decoration_id("fireflies:firefly_high")
minetest.set_gen_notify({decoration = true}, {firefly_low, firefly_high})
-- start nodetimers
minetest.register_on_generated(function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local poslist = {}
for _, pos in ipairs(gennotify["decoration#"..firefly_low] or {}) do
local firefly_low_pos = {x = pos.x, y = pos.y + 3, z = pos.z}
table.insert(poslist, firefly_low_pos)
end
for _, pos in ipairs(gennotify["decoration#"..firefly_high] or {}) do
local firefly_high_pos = {x = pos.x, y = pos.y + 4, z = pos.z}
table.insert(poslist, firefly_high_pos)
end
if #poslist ~= 0 then
for i = 1, #poslist do
local pos = poslist[i]
minetest.get_node_timer(pos):start(1)
end
end
end)