Flora spread: Re-enable dry shrub replacing flora in desert sand
[oweals/minetest_game.git] / mods / flowers / init.lua
index e572357c577f3ef16ce87f39368a0107d7af34d6..db7a4eb35178956aa0a667f71710894ff0039be7 100644 (file)
@@ -57,12 +57,42 @@ local function add_simple_flower(name, desc, box, f_groups)
 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}}
+       {
+               "rose",
+               "Rose",
+               {-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",
+               {-2 / 16, -0.5, -2 / 16, 2 / 16, 4 / 16, 2 / 16},
+               {color_yellow = 1, flammable = 1}
+       },
+       {
+               "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",
+               "White dandelion",
+               {-5 / 16, -0.5, -5 / 16, 5 / 16, -2 / 16, 5 / 16},
+               {color_white = 1, flammable = 1}
+       },
 }
 
 for _,item in pairs(flowers.datas) do
@@ -77,11 +107,16 @@ function flowers.flower_spread(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
+       -- 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
-       elseif under.name ~= "default:dirt_with_grass" and
-                       under.name ~= "default:dirt_with_dry_grass" then
+       end
+
+       if minetest.get_item_group(under.name, "soil") == 0 then
                return
        end
 
@@ -96,24 +131,26 @@ function flowers.flower_spread(pos, node)
                return
        end
 
-       local seedling = minetest.find_nodes_in_area_under_air(pos0, pos1,
-               {"default:dirt_with_grass", "default:dirt_with_dry_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
+       local soils = minetest.find_nodes_in_area_under_air(
+               pos0, pos1, "group:soil")
+       if #soils > 0 then
+               local seedling = soils[math.random(#soils)]
+               local seedling_above =
+                       {x = seedling.x, y = seedling.y + 1, z = seedling.z}
+               light = minetest.get_node_light(seedling_above)
+               if not light or light < 13 or
+                               -- Desert sand is in the soil group
+                               minetest.get_node(seedling).name == "default:desert_sand" then
                        return
                end
-               minetest.set_node(seedling, {name = node.name})
+
+               minetest.set_node(seedling_above, {name = node.name})
        end
 end
 
 minetest.register_abm({
        label = "Flower spread",
        nodenames = {"group:flora"},
-       neighbors = {"default:dirt_with_grass", "default:dirt_with_dry_grass",
-               "default:desert_sand"},
        interval = 13,
        chance = 96,
        action = function(...)
@@ -136,12 +173,12 @@ minetest.register_node("flowers:mushroom_red", {
        sunlight_propagates = true,
        walkable = false,
        buildable_to = true,
-       groups = {snappy = 3, attached_node = 1},
+       groups = {snappy = 3, attached_node = 1, flammable = 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}
+               fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, -1 / 16, 4 / 16},
        }
 })
 
@@ -155,12 +192,12 @@ minetest.register_node("flowers:mushroom_brown", {
        sunlight_propagates = true,
        walkable = false,
        buildable_to = true,
-       groups = {snappy = 3, attached_node = 1},
+       groups = {snappy = 3, attached_node = 1, flammable = 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}
+               fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
        }
 })
 
@@ -229,16 +266,16 @@ minetest.register_node("flowers:waterlily", {
        buildable_to = true,
        sunlight_propagates = true,
        floodable = true,
-       groups = {snappy = 3, flower = 1},
+       groups = {snappy = 3, flower = 1, flammable = 1},
        sounds = default.node_sound_leaves_defaults(),
        node_placement_prediction = "",
        node_box = {
                type = "fixed",
-               fixed = {-0.5, -0.5, -0.5, 0.5, -0.46875, 0.5}
+               fixed = {-0.5, -31 / 64, -0.5, 0.5, -15 / 32, 0.5}
        },
        selection_box = {
                type = "fixed",
-               fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}
+               fixed = {-7 / 16, -0.5, -7 / 16, 7 / 16, -15 / 32, 7 / 16}
        },
 
        on_place = function(itemstack, placer, pointed_thing)