2013-05-18 16:05:16 +02:00
|
|
|
-- Minetest 0.4 mod: default
|
|
|
|
-- See README.txt for licensing and other information.
|
|
|
|
|
2015-08-07 18:41:44 +02:00
|
|
|
|
2015-06-04 20:08:54 +02:00
|
|
|
-- Namespace for functions
|
2015-08-07 18:41:44 +02:00
|
|
|
|
2015-06-04 20:08:54 +02:00
|
|
|
flowers = {}
|
|
|
|
|
2015-08-01 03:13:14 +02:00
|
|
|
|
2013-05-18 16:05:16 +02:00
|
|
|
-- Map Generation
|
2015-08-07 18:41:44 +02:00
|
|
|
|
2015-08-01 03:13:14 +02:00
|
|
|
dofile(minetest.get_modpath("flowers") .. "/mapgen.lua")
|
|
|
|
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2015-08-07 18:41:44 +02:00
|
|
|
--
|
|
|
|
-- Flowers
|
|
|
|
--
|
|
|
|
|
2013-05-18 16:05:16 +02:00
|
|
|
-- Aliases for original flowers mod
|
2015-08-07 18:41:44 +02:00
|
|
|
|
2013-05-18 16:05:16 +02:00
|
|
|
minetest.register_alias("flowers:flower_rose", "flowers:rose")
|
|
|
|
minetest.register_alias("flowers:flower_tulip", "flowers:tulip")
|
2015-08-07 18:41:44 +02:00
|
|
|
minetest.register_alias("flowers:flower_dandelion_yellow", "flowers:dandelion_yellow")
|
|
|
|
minetest.register_alias("flowers:flower_geranium", "flowers:geranium")
|
2013-05-18 16:05:16 +02:00
|
|
|
minetest.register_alias("flowers:flower_viola", "flowers:viola")
|
2015-08-07 18:41:44 +02:00
|
|
|
minetest.register_alias("flowers:flower_dandelion_white", "flowers:dandelion_white")
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2015-08-01 03:13:14 +02:00
|
|
|
|
|
|
|
-- Flower registration
|
|
|
|
|
2015-06-04 20:08:54 +02:00
|
|
|
local function add_simple_flower(name, desc, box, f_groups)
|
|
|
|
-- Common flowers' groups
|
|
|
|
f_groups.snappy = 3
|
|
|
|
f_groups.flower = 1
|
|
|
|
f_groups.flora = 1
|
|
|
|
f_groups.attached_node = 1
|
|
|
|
|
2015-08-01 03:13:14 +02:00
|
|
|
minetest.register_node("flowers:" .. name, {
|
2015-04-18 16:48:43 +02:00
|
|
|
description = desc,
|
|
|
|
drawtype = "plantlike",
|
2015-09-06 07:03:08 +02:00
|
|
|
waving = 1,
|
2015-08-01 03:13:14 +02:00
|
|
|
tiles = {"flowers_" .. name .. ".png"},
|
2015-06-04 20:08:54 +02:00
|
|
|
inventory_image = "flowers_" .. name .. ".png",
|
|
|
|
wield_image = "flowers_" .. name .. ".png",
|
2015-04-18 16:48:43 +02:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
walkable = false,
|
2015-10-05 01:06:07 +02:00
|
|
|
buildable_to = true,
|
2015-04-18 16:48:43 +02:00
|
|
|
groups = f_groups,
|
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2015-06-04 20:08:54 +02:00
|
|
|
fixed = box
|
|
|
|
}
|
2015-04-18 16:48:43 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2015-06-04 20:08:54 +02:00
|
|
|
flowers.datas = {
|
2016-11-05 06:58:12 +01:00
|
|
|
{
|
|
|
|
"rose",
|
2017-07-23 10:26:10 +02:00
|
|
|
"Red Rose",
|
2016-11-05 06:58:12 +01:00
|
|
|
{-2 / 16, -0.5, -2 / 16, 2 / 16, 5 / 16, 2 / 16},
|
|
|
|
{color_red = 1, flammable = 1}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tulip",
|
|
|
|
"Orange Tulip",
|
|
|
|
{-2 / 16, -0.5, -2 / 16, 2 / 16, 3 / 16, 2 / 16},
|
|
|
|
{color_orange = 1, flammable = 1}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"dandelion_yellow",
|
|
|
|
"Yellow Dandelion",
|
2017-05-25 16:44:21 +02:00
|
|
|
{-4 / 16, -0.5, -4 / 16, 4 / 16, -2 / 16, 4 / 16},
|
2016-11-05 06:58:12 +01:00
|
|
|
{color_yellow = 1, flammable = 1}
|
|
|
|
},
|
2017-11-20 05:13:41 +01:00
|
|
|
{
|
|
|
|
"chrysanthemum_green",
|
|
|
|
"Green Chrysanthemum",
|
|
|
|
{-4 / 16, -0.5, -4 / 16, 4 / 16, -1 / 16, 4 / 16},
|
|
|
|
{color_green = 1, flammable = 1}
|
|
|
|
},
|
2016-11-05 06:58:12 +01:00
|
|
|
{
|
|
|
|
"geranium",
|
|
|
|
"Blue Geranium",
|
|
|
|
{-2 / 16, -0.5, -2 / 16, 2 / 16, 2 / 16, 2 / 16},
|
|
|
|
{color_blue = 1, flammable = 1}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"viola",
|
|
|
|
"Viola",
|
|
|
|
{-5 / 16, -0.5, -5 / 16, 5 / 16, -1 / 16, 5 / 16},
|
|
|
|
{color_violet = 1, flammable = 1}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"dandelion_white",
|
2017-06-25 11:19:12 +02:00
|
|
|
"White Dandelion",
|
2016-11-05 06:58:12 +01:00
|
|
|
{-5 / 16, -0.5, -5 / 16, 5 / 16, -2 / 16, 5 / 16},
|
|
|
|
{color_white = 1, flammable = 1}
|
|
|
|
},
|
2017-11-20 05:13:41 +01:00
|
|
|
{
|
|
|
|
"tulip_black",
|
|
|
|
"Black Tulip",
|
|
|
|
{-2 / 16, -0.5, -2 / 16, 2 / 16, 3 / 16, 2 / 16},
|
|
|
|
{color_black = 1, flammable = 1}
|
|
|
|
},
|
2015-06-04 20:08:54 +02:00
|
|
|
}
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2015-06-04 20:08:54 +02:00
|
|
|
for _,item in pairs(flowers.datas) do
|
|
|
|
add_simple_flower(unpack(item))
|
|
|
|
end
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2015-08-01 03:13:14 +02:00
|
|
|
|
2015-08-07 18:41:44 +02:00
|
|
|
-- Flower spread
|
2016-04-16 23:33:08 +02:00
|
|
|
-- Public function to enable override by mods
|
|
|
|
|
|
|
|
function flowers.flower_spread(pos, node)
|
|
|
|
pos.y = pos.y - 1
|
|
|
|
local under = minetest.get_node(pos)
|
|
|
|
pos.y = pos.y + 1
|
2017-03-23 02:19:33 +01:00
|
|
|
-- Replace flora with dry shrub in desert sand and silver sand,
|
|
|
|
-- as this is the only way to generate them.
|
|
|
|
-- However, preserve grasses in sand dune biomes.
|
|
|
|
if minetest.get_item_group(under.name, "sand") == 1 and
|
|
|
|
under.name ~= "default:sand" then
|
|
|
|
minetest.set_node(pos, {name = "default:dry_shrub"})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-03-22 18:51:29 +01:00
|
|
|
if minetest.get_item_group(under.name, "soil") == 0 then
|
2016-04-16 23:33:08 +02:00
|
|
|
return
|
|
|
|
end
|
2015-08-07 18:41:44 +02:00
|
|
|
|
2016-04-16 23:33:08 +02:00
|
|
|
local light = minetest.get_node_light(pos)
|
|
|
|
if not light or light < 13 then
|
|
|
|
return
|
|
|
|
end
|
2015-08-10 01:03:15 +02:00
|
|
|
|
2016-04-16 23:33:08 +02:00
|
|
|
local pos0 = vector.subtract(pos, 4)
|
|
|
|
local pos1 = vector.add(pos, 4)
|
2018-07-17 06:04:46 +02:00
|
|
|
-- Testing shows that a threshold of 3 results in an appropriate maximum
|
|
|
|
-- density of approximately 7 flora per 9x9 area.
|
|
|
|
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then
|
2016-04-16 23:33:08 +02:00
|
|
|
return
|
|
|
|
end
|
2015-08-10 01:03:15 +02:00
|
|
|
|
2017-03-18 18:54:03 +01:00
|
|
|
local soils = minetest.find_nodes_in_area_under_air(
|
|
|
|
pos0, pos1, "group:soil")
|
2018-01-15 06:33:27 +01:00
|
|
|
local num_soils = #soils
|
|
|
|
if num_soils >= 1 then
|
|
|
|
for si = 1, math.min(3, num_soils) do
|
|
|
|
local soil = soils[math.random(num_soils)]
|
2018-02-11 09:47:15 +01:00
|
|
|
local soil_name = minetest.get_node(soil).name
|
2018-01-15 06:33:27 +01:00
|
|
|
local soil_above = {x = soil.x, y = soil.y + 1, z = soil.z}
|
|
|
|
light = minetest.get_node_light(soil_above)
|
|
|
|
if light and light >= 13 and
|
2018-02-11 09:47:15 +01:00
|
|
|
-- Only spread to same surface node
|
|
|
|
soil_name == under.name and
|
2018-01-15 06:33:27 +01:00
|
|
|
-- Desert sand is in the soil group
|
2018-02-11 09:47:15 +01:00
|
|
|
soil_name ~= "default:desert_sand" then
|
2018-01-15 06:33:27 +01:00
|
|
|
minetest.set_node(soil_above, {name = node.name})
|
|
|
|
end
|
2015-08-07 18:41:44 +02:00
|
|
|
end
|
2016-04-16 23:33:08 +02:00
|
|
|
end
|
|
|
|
end
|
2015-08-10 01:03:15 +02:00
|
|
|
|
2016-04-16 23:33:08 +02:00
|
|
|
minetest.register_abm({
|
2016-08-08 11:56:13 +02:00
|
|
|
label = "Flower spread",
|
2016-04-16 23:33:08 +02:00
|
|
|
nodenames = {"group:flora"},
|
|
|
|
interval = 13,
|
2018-01-15 06:33:27 +01:00
|
|
|
chance = 300,
|
2016-04-16 23:33:08 +02:00
|
|
|
action = function(...)
|
|
|
|
flowers.flower_spread(...)
|
2015-08-07 18:41:44 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
--
|
2015-08-01 03:13:14 +02:00
|
|
|
-- Mushrooms
|
2015-08-07 18:41:44 +02:00
|
|
|
--
|
2015-08-01 03:13:14 +02:00
|
|
|
|
2015-12-15 08:53:27 +01:00
|
|
|
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,
|
2019-06-01 21:10:30 +02:00
|
|
|
groups = {mushroom = 1, snappy = 3, attached_node = 1, flammable = 1},
|
2015-12-15 08:53:27 +01:00
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
on_use = minetest.item_eat(-5),
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2016-11-05 06:58:12 +01:00
|
|
|
fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, -1 / 16, 4 / 16},
|
2015-12-15 08:53:27 +01:00
|
|
|
}
|
|
|
|
})
|
2015-08-01 03:13:14 +02:00
|
|
|
|
2015-12-15 08:53:27 +01:00
|
|
|
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,
|
2019-06-01 21:10:30 +02:00
|
|
|
groups = {mushroom = 1, food_mushroom = 1, snappy = 3, attached_node = 1, flammable = 1},
|
2015-12-15 08:53:27 +01:00
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
on_use = minetest.item_eat(1),
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2016-11-05 06:58:12 +01:00
|
|
|
fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
|
2015-12-15 08:53:27 +01:00
|
|
|
}
|
|
|
|
})
|
2015-08-01 03:13:14 +02:00
|
|
|
|
2016-04-16 23:33:08 +02:00
|
|
|
|
|
|
|
-- Mushroom spread and death
|
|
|
|
|
2017-07-30 15:02:10 +02:00
|
|
|
function flowers.mushroom_spread(pos, node)
|
2019-03-31 23:20:28 +02:00
|
|
|
if minetest.get_node_light(pos, 0.5) > 3 then
|
|
|
|
if minetest.get_node_light(pos, nil) == 15 then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
2017-07-30 15:02:10 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local positions = minetest.find_nodes_in_area_under_air(
|
|
|
|
{x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
|
|
|
|
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
|
|
|
|
{"group:soil", "group:tree"})
|
|
|
|
if #positions == 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pos2 = positions[math.random(#positions)]
|
|
|
|
pos2.y = pos2.y + 1
|
2019-03-31 23:20:28 +02:00
|
|
|
if minetest.get_node_light(pos2, 0.5) <= 3 then
|
2017-07-30 15:02:10 +02:00
|
|
|
minetest.set_node(pos2, {name = node.name})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-18 16:05:16 +02:00
|
|
|
minetest.register_abm({
|
2016-08-08 11:56:13 +02:00
|
|
|
label = "Mushroom spread",
|
2015-12-15 08:53:27 +01:00
|
|
|
nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red"},
|
2015-08-07 18:41:44 +02:00
|
|
|
interval = 11,
|
2017-07-30 15:02:10 +02:00
|
|
|
chance = 150,
|
|
|
|
action = function(...)
|
|
|
|
flowers.mushroom_spread(...)
|
|
|
|
end,
|
2013-05-18 16:05:16 +02:00
|
|
|
})
|
2015-09-16 03:38:58 +02:00
|
|
|
|
2016-04-16 23:33:08 +02:00
|
|
|
|
|
|
|
-- These old mushroom related nodes can be simplified now
|
|
|
|
|
2015-12-15 08:53:27 +01:00
|
|
|
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")
|
2016-08-21 22:18:32 +02:00
|
|
|
minetest.register_alias("mushroom:brown_natural", "flowers:mushroom_brown")
|
|
|
|
minetest.register_alias("mushroom:red_natural", "flowers:mushroom_red")
|
2015-12-15 08:53:27 +01:00
|
|
|
|
2015-09-16 03:38:58 +02:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Waterlily
|
|
|
|
--
|
|
|
|
|
2019-06-16 23:09:36 +02:00
|
|
|
local waterlily_def = {
|
2015-09-16 03:38:58 +02:00
|
|
|
description = "Waterlily",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2016-06-17 16:47:43 +02:00
|
|
|
tiles = {"flowers_waterlily.png", "flowers_waterlily_bottom.png"},
|
2015-09-16 03:38:58 +02:00
|
|
|
inventory_image = "flowers_waterlily.png",
|
|
|
|
wield_image = "flowers_waterlily.png",
|
|
|
|
liquids_pointable = true,
|
2015-09-17 16:43:29 +02:00
|
|
|
walkable = false,
|
2015-10-05 01:06:07 +02:00
|
|
|
buildable_to = true,
|
2016-06-30 23:16:46 +02:00
|
|
|
floodable = true,
|
2016-10-24 20:34:00 +02:00
|
|
|
groups = {snappy = 3, flower = 1, flammable = 1},
|
2015-09-16 03:38:58 +02:00
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
2016-04-21 12:38:44 +02:00
|
|
|
node_placement_prediction = "",
|
2015-09-16 03:38:58 +02:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2017-02-11 02:13:13 +01:00
|
|
|
fixed = {-0.5, -31 / 64, -0.5, 0.5, -15 / 32, 0.5}
|
2015-09-16 03:38:58 +02:00
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2016-11-05 06:58:12 +01:00
|
|
|
fixed = {-7 / 16, -0.5, -7 / 16, 7 / 16, -15 / 32, 7 / 16}
|
2015-09-16 03:38:58 +02:00
|
|
|
},
|
|
|
|
|
2016-04-21 12:38:44 +02:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
2016-04-07 13:10:18 +02:00
|
|
|
local pos = pointed_thing.above
|
2017-09-21 16:18:08 +02:00
|
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
2016-04-21 12:38:44 +02:00
|
|
|
|
2017-09-21 16:18:08 +02:00
|
|
|
if def and def.on_rightclick then
|
|
|
|
return def.on_rightclick(pointed_thing.under, node, placer, itemstack,
|
|
|
|
pointed_thing)
|
|
|
|
end
|
|
|
|
|
2016-07-19 23:26:02 +02:00
|
|
|
if def and def.liquidtype == "source" and
|
2017-09-21 16:18:08 +02:00
|
|
|
minetest.get_item_group(node.name, "water") > 0 then
|
2019-06-16 23:09:36 +02:00
|
|
|
local player_name = placer and placer:get_player_name() or ""
|
2016-04-21 12:38:44 +02:00
|
|
|
if not minetest.is_protected(pos, player_name) then
|
2019-06-16 23:09:36 +02:00
|
|
|
minetest.set_node(pos, {name = "flowers:waterlily" ..
|
|
|
|
(def.waving == 3 and "_waving" or ""),
|
2016-07-19 23:26:02 +02:00
|
|
|
param2 = math.random(0, 3)})
|
2017-03-29 21:02:26 +02:00
|
|
|
if not (creative and creative.is_enabled_for
|
|
|
|
and creative.is_enabled_for(player_name)) then
|
2016-07-19 23:26:02 +02:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
2016-04-21 12:38:44 +02:00
|
|
|
else
|
2016-07-19 23:26:02 +02:00
|
|
|
minetest.chat_send_player(player_name, "Node is protected")
|
|
|
|
minetest.record_protection_violation(pos, player_name)
|
2016-04-08 14:29:48 +02:00
|
|
|
end
|
2015-09-16 03:38:58 +02:00
|
|
|
end
|
2016-07-19 23:26:02 +02:00
|
|
|
|
2016-07-01 22:43:02 +02:00
|
|
|
return itemstack
|
2015-09-16 03:38:58 +02:00
|
|
|
end
|
2019-06-16 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local waterlily_waving_def = table.copy(waterlily_def)
|
|
|
|
waterlily_waving_def.waving = 3
|
|
|
|
waterlily_waving_def.drop = "flowers:waterlily"
|
|
|
|
waterlily_waving_def.groups.not_in_creative_inventory = 1
|
|
|
|
|
|
|
|
minetest.register_node("flowers:waterlily", waterlily_def)
|
|
|
|
minetest.register_node("flowers:waterlily_waving", waterlily_waving_def)
|
|
|
|
|