1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-29 12:10:34 +01:00
server-nalc/minetestforfun_game/mods/flowers/init.lua

276 lines
7.6 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- Minetest 0.4 mod: default
-- See README.txt for licensing and other information.
-- Namespace for functions
flowers = {}
2014-10-28 18:01:32 +01:00
-- Map Generation
dofile(minetest.get_modpath("flowers") .. "/mapgen.lua")
--
-- Flowers
--
2014-10-28 18:01:32 +01:00
-- Aliases for original flowers mod
2014-10-28 18:01:32 +01:00
minetest.register_alias("flowers:flower_rose", "flowers:rose")
minetest.register_alias("flowers:flower_tulip", "flowers:tulip")
minetest.register_alias("flowers:flower_dandelion_yellow", "flowers:dandelion_yellow")
minetest.register_alias("flowers:flower_geranium", "flowers:geranium")
2014-10-28 18:01:32 +01:00
minetest.register_alias("flowers:flower_viola", "flowers:viola")
minetest.register_alias("flowers:flower_dandelion_white", "flowers:dandelion_white")
-- Flower registration
2014-10-28 18:01:32 +01:00
local function add_simple_flower(name, desc, box, f_groups)
-- Common flowers' groups
f_groups.snappy = 3
f_groups.flammable = 2
f_groups.flower = 1
f_groups.flora = 1
f_groups.attached_node = 1
minetest.register_node("flowers:" .. name, {
description = desc,
drawtype = "plantlike",
2015-09-15 22:24:56 +02:00
waving = 1,
tiles = {"flowers_" .. name .. ".png"},
inventory_image = "flowers_" .. name .. ".png",
wield_image = "flowers_" .. name .. ".png",
sunlight_propagates = true,
paramtype = "light",
walkable = false,
buildable_to = true,
stack_max = 99,
groups = f_groups,
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = box
}
})
end
flowers.datas = {
{"rose", "Rose", {-0.15, -0.5, -0.15, 0.15, 0.3, 0.15}, {color_red = 1}},
{"tulip", "Orange Tulip", {-0.15, -0.5, -0.15, 0.15, 0.2, 0.15}, {color_orange = 1}},
{"dandelion_yellow", "Yellow Dandelion", {-0.15, -0.5, -0.15, 0.15, 0.2, 0.15}, {color_yellow = 1}},
{"geranium", "Blue Geranium", {-0.15, -0.5, -0.15, 0.15, 0.2, 0.15}, {color_blue = 1}},
{"viola", "Viola", {-0.5, -0.5, -0.5, 0.5, -0.2, 0.5}, {color_violet = 1}},
{"dandelion_white", "White dandelion", {-0.5, -0.5, -0.5, 0.5, -0.2, 0.5}, {color_white = 1}}
}
for _,item in pairs(flowers.datas) do
add_simple_flower(unpack(item))
end
2014-10-28 18:01:32 +01:00
2015-06-09 17:59:08 +02:00
minetest.register_node("flowers:lily_pad", {
description = "Lily Pad",
drawtype = "nodebox",
tiles = { "flowers_lily_pad.png" },
inventory_image = "flowers_lily_pad.png",
wield_image = "flowers_lily_pad.png",
wield_scale = {x = 1, y = 1, z = 0.001},
is_ground_content = true,
sunlight_propagates = true,
paramtype = "light",
walkable = false,
buildable_to = true,
groups = {snappy = 3, flammable = 2, flower = 1, flora = 1},
sounds = default.node_sound_leaves_defaults(),
node_box = {
type = "fixed",
fixed = {-0.5, -0.45, -0.5, 0.5, -0.4375, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
},
})
-- Flower spread
2014-10-28 18:01:32 +01:00
minetest.register_abm({
nodenames = {"group:flora"},
neighbors = {"default:dirt_with_grass", "default:desert_sand"},
interval = 13,
chance = 96,
2014-10-28 18:01:32 +01:00
action = function(pos, node)
pos.y = pos.y - 1
local under = minetest.get_node(pos)
pos.y = pos.y + 1
if under.name == "default:desert_sand" then
minetest.set_node(pos, {name = "default:dry_shrub"})
elseif under.name ~= "default:dirt_with_grass" then
return
end
2014-10-28 18:01:32 +01:00
local light = minetest.get_node_light(pos)
if not light or light < 13 then
return
end
local pos0 = {x = pos.x - 4, y = pos.y - 4, z = pos.z - 4}
local pos1 = {x = pos.x + 4, y = pos.y + 4, z = pos.z + 4}
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora_block") > 0 then
return
end
2014-10-28 18:01:32 +01:00
local flowers = minetest.find_nodes_in_area(pos0, pos1, "group:flora")
if #flowers > 3 then
return
end
2014-10-28 18:01:32 +01:00
local seedling = minetest.find_nodes_in_area(pos0, pos1, "default:dirt_with_grass")
if #seedling > 0 then
seedling = seedling[math.random(#seedling)]
seedling.y = seedling.y + 1
light = minetest.get_node_light(seedling)
if not light or light < 13 then
return
end
if minetest.get_node(seedling).name == "air" then
minetest.set_node(seedling, {name = node.name})
2014-10-28 18:01:32 +01:00
end
end
end,
})
--
-- Mushrooms
--
minetest.register_node("flowers:mushroom_red", {
description = "Red Mushroom",
tiles = {"flowers_mushroom_red.png"},
inventory_image = "flowers_mushroom_red.png",
wield_image = "flowers_mushroom_red.png",
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
buildable_to = true,
groups = {snappy = 3, flammable = 3, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
on_use = minetest.item_eat(-5),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.3}
}
})
minetest.register_node("flowers:mushroom_brown", {
description = "Brown Mushroom",
tiles = {"flowers_mushroom_brown.png"},
inventory_image = "flowers_mushroom_brown.png",
wield_image = "flowers_mushroom_brown.png",
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
buildable_to = true,
groups = {snappy = 3, flammable = 3, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
on_use = minetest.item_eat(1),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.3}
}
})
-- mushroom spread and death
minetest.register_abm({
nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red"},
interval = 11,
chance = 50,
action = function(pos, node)
if minetest.get_node_light(pos, nil) == 15 then
minetest.remove_node(pos)
end
local random = {
x = pos.x + math.random(-2,2),
y = pos.y + math.random(-1,1),
z = pos.z + math.random(-2,2)
}
local random_node = minetest.get_node_or_nil(random)
if not random_node then
return
end
if random_node.name ~= "air" then
return
end
local node_under = minetest.get_node_or_nil({x = random.x,
y = random.y - 1, z = random.z})
if not node_under then
return
end
if minetest.get_item_group(node_under.name, "soil") ~= 0 and
minetest.get_node_light(pos, nil) <= 9 and
minetest.get_node_light(random, nil) <= 9 and
not minetest.is_protected(random, "") then
minetest.set_node(random, {name = node.name})
end
end
})
2015-09-22 18:51:17 +02:00
-- these old mushroom related nodes can be simplified now
minetest.register_alias("flowers:mushroom_spores_brown", "flowers:mushroom_brown")
minetest.register_alias("flowers:mushroom_spores_red", "flowers:mushroom_red")
minetest.register_alias("flowers:mushroom_fertile_brown", "flowers:mushroom_brown")
minetest.register_alias("flowers:mushroom_fertile_red", "flowers:mushroom_red")
2015-09-22 18:51:17 +02:00
--
-- Waterlily
--
minetest.register_node("flowers:waterlily", {
description = "Waterlily",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
tiles = {"flowers_waterlily.png"},
inventory_image = "flowers_waterlily.png",
wield_image = "flowers_waterlily.png",
liquids_pointable = true,
walkable = false,
buildable_to = true,
sunlight_propagates = true,
2015-09-22 18:51:17 +02:00
groups = {snappy = 3, flower = 1},
sounds = default.node_sound_leaves_defaults(),
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.46875, 0.5}
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}
},
2016-06-09 21:43:23 +02:00
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local node = minetest.get_node(pointed_thing.under).name
local def = minetest.registered_nodes[node]
2016-06-09 21:43:23 +02:00
local player_name = placer:get_player_name()
if def and def.liquidtype == "source" and minetest.get_item_group(node, "water") > 0 then
2016-06-09 21:43:23 +02:00
if not minetest.is_protected(pos, player_name) then
minetest.set_node(pos, {name = "flowers:waterlily", param2 = math.random(0, 3)})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
else
minetest.chat_send_player(player_name, "This area is protected")
end
2015-09-22 18:51:17 +02:00
end
2016-06-09 21:43:23 +02:00
return itemstack
2015-09-22 18:51:17 +02:00
end
})