2019-09-10 19:09:51 +02:00
|
|
|
-- firefly/init.lua
|
|
|
|
|
|
|
|
-- Load support for MT game translation.
|
|
|
|
local S = minetest.get_translator("fireflies")
|
|
|
|
|
2024-03-10 17:57:22 +01:00
|
|
|
-- Legacy compatibility, when pointabilities don't exist, pointable is set to true.
|
|
|
|
local pointable_compat = not minetest.features.item_specific_pointabilities
|
2019-09-10 19:09:51 +02:00
|
|
|
|
2018-01-29 02:40:09 +01:00
|
|
|
minetest.register_node("fireflies:firefly", {
|
2019-09-10 19:09:51 +02:00
|
|
|
description = S("Firefly"),
|
2018-01-29 02:40:09 +01:00
|
|
|
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,
|
2024-03-10 17:57:22 +01:00
|
|
|
pointable = pointable_compat,
|
2018-01-29 02:40:09 +01:00
|
|
|
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,
|
2024-08-31 11:43:07 +02:00
|
|
|
on_construct = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
2018-03-22 21:33:54 +01:00
|
|
|
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", {
|
2019-09-10 19:09:51 +02:00
|
|
|
description = S("Hidden Firefly"),
|
2018-03-22 21:33:54 +01:00
|
|
|
drawtype = "airlike",
|
2020-09-30 17:41:04 +02:00
|
|
|
inventory_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
|
|
|
|
wield_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
|
2018-03-22 21:33:54 +01:00
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
pointable = false,
|
|
|
|
diggable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
drop = "",
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
2018-06-25 22:29:24 +02:00
|
|
|
floodable = true,
|
2024-08-31 11:43:07 +02:00
|
|
|
on_construct = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
2018-03-22 21:33:54 +01:00
|
|
|
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)
|
2018-01-29 02:40:09 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- bug net
|
|
|
|
minetest.register_tool("fireflies:bug_net", {
|
2019-09-10 19:09:51 +02:00
|
|
|
description = S("Bug Net"),
|
2018-01-29 02:40:09 +01:00
|
|
|
inventory_image = "fireflies_bugnet.png",
|
2024-03-10 17:57:22 +01:00
|
|
|
pointabilities = {nodes = {["group:catchable"] = true}},
|
2024-08-31 11:43:07 +02:00
|
|
|
tool_capabilities = {
|
|
|
|
groupcaps = {
|
|
|
|
catchable = { maxlevel = 1, uses = 256, times = { [1] = 0, [2] = 0, [3] = 0 } }
|
|
|
|
},
|
|
|
|
},
|
2018-01-29 02:40:09 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft( {
|
|
|
|
output = "fireflies:bug_net",
|
|
|
|
recipe = {
|
2019-01-02 12:40:32 +01:00
|
|
|
{"farming:string", "farming:string"},
|
|
|
|
{"farming:string", "farming:string"},
|
2019-03-24 10:59:34 +01:00
|
|
|
{"group:stick", ""}
|
2018-01-29 02:40:09 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- firefly in a bottle
|
|
|
|
minetest.register_node("fireflies:firefly_bottle", {
|
2019-09-10 19:09:51 +02:00
|
|
|
description = S("Firefly in a Bottle"),
|
2018-01-29 02:40:09 +01:00
|
|
|
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,
|
2019-09-13 20:47:09 +02:00
|
|
|
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
|
2018-01-29 02:40:09 +01:00
|
|
|
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"})
|
2018-03-22 21:33:54 +01:00
|
|
|
minetest.get_node_timer(firefly_pos):start(1)
|
2018-01-29 02:40:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft( {
|
|
|
|
output = "fireflies:firefly_bottle",
|
|
|
|
recipe = {
|
2019-01-02 12:40:32 +01:00
|
|
|
{"fireflies:firefly"},
|
|
|
|
{"vessels:glass_bottle"}
|
2018-01-29 02:40:09 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- register fireflies as decorations
|
|
|
|
|
2018-02-26 00:29:16 +01:00
|
|
|
if minetest.get_mapgen_setting("mg_name") == "v6" then
|
|
|
|
|
|
|
|
minetest.register_decoration({
|
2018-03-18 01:25:16 +01:00
|
|
|
name = "fireflies:firefly_low",
|
2018-02-26 00:29:16 +01:00
|
|
|
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,
|
2018-05-25 23:33:03 +02:00
|
|
|
decoration = "fireflies:hidden_firefly",
|
2018-02-26 00:29:16 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_decoration({
|
2018-03-18 01:25:16 +01:00
|
|
|
name = "fireflies:firefly_high",
|
2018-02-26 00:29:16 +01:00
|
|
|
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,
|
2018-05-25 23:33:03 +02:00
|
|
|
decoration = "fireflies:hidden_firefly",
|
2018-02-26 00:29:16 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
minetest.register_decoration({
|
2018-03-18 01:25:16 +01:00
|
|
|
name = "fireflies:firefly_low",
|
2018-02-26 00:29:16 +01:00
|
|
|
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,
|
2018-03-05 22:45:45 +01:00
|
|
|
fill_ratio = 0.0005,
|
2018-02-26 00:29:16 +01:00
|
|
|
biomes = {
|
|
|
|
"deciduous_forest",
|
|
|
|
"coniferous_forest",
|
|
|
|
"rainforest",
|
|
|
|
"rainforest_swamp"
|
|
|
|
},
|
|
|
|
y_max = 31000,
|
|
|
|
y_min = -1,
|
2018-05-25 23:33:03 +02:00
|
|
|
decoration = "fireflies:hidden_firefly",
|
2018-02-26 00:29:16 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_decoration({
|
2018-03-18 01:25:16 +01:00
|
|
|
name = "fireflies:firefly_high",
|
2018-02-26 00:29:16 +01:00
|
|
|
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,
|
2018-03-05 22:45:45 +01:00
|
|
|
fill_ratio = 0.0005,
|
2018-02-26 00:29:16 +01:00
|
|
|
biomes = {
|
|
|
|
"deciduous_forest",
|
|
|
|
"coniferous_forest",
|
|
|
|
"rainforest",
|
|
|
|
"rainforest_swamp"
|
|
|
|
},
|
|
|
|
y_max = 31000,
|
|
|
|
y_min = -1,
|
2018-05-25 23:33:03 +02:00
|
|
|
decoration = "fireflies:hidden_firefly",
|
2018-02-26 00:29:16 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
end
|
2018-03-22 21:33:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- 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)
|