diff --git a/API.txt b/API.txt index 55bbd89..e4da586 100644 --- a/API.txt +++ b/API.txt @@ -72,8 +72,9 @@ depthmax: If a node spawns on top of a water source, the water must be at ----- The second function, grow_plants() is defined like so: -grow_plants = function(gdelay, gchance, gplant, gresult, - dry_early_node, grow_nodes) +grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, + grow_nodes, facedir, need_wall, grow_vertically, height_limit, + ground_nodes) gdelay: Passed as the ABM "interval" parameter, as with spawning. gchance: Passed as the ABM "chance" parameter. @@ -97,6 +98,19 @@ grow_nodes: This node must be under the plant in order for it to grow at facedir: Same as with spawning a plant. If supplied, this value is passed to the param2 variable when changing the plant. If nil or left out, no new param2 value is applied. +need_wall: Set this to true if you the plant needs to grow against a + wall. Defaults to false. +grow_vertically: Set this to true if the plant needs to grow vertically, as in + climbing poison ivy. Defaults to false. +height_limit: Just how tall can a vertically-growing plant go? Set this + accordingly. The mod will search straight down from the + position being spawned at to find a ground node, below. + Defaults to 62000 (unlimited). +ground_nodes: What nodes should be treated as "the ground" below a + vertically-growing plant. Usually this will be the same as + the grow_nodes table, but might also include, for example, + water or some other surrounding material. Defaults to + "default:dirt_with_grass". ----- plant_valid_wall() expects only a single parameter, "pos", which is a table diff --git a/plants_lib/textures/cotton.png b/flowers/textures/cotton.png similarity index 100% rename from plants_lib/textures/cotton.png rename to flowers/textures/cotton.png diff --git a/plants_lib/textures/flower_cotton.png b/flowers/textures/flower_cotton.png similarity index 100% rename from plants_lib/textures/flower_cotton.png rename to flowers/textures/flower_cotton.png diff --git a/plants_lib/textures/flower_cotton_pot.png b/flowers/textures/flower_cotton_pot.png similarity index 100% rename from plants_lib/textures/flower_cotton_pot.png rename to flowers/textures/flower_cotton_pot.png diff --git a/plants_lib/textures/flower_dandelion_white.png b/flowers/textures/flower_dandelion_white.png similarity index 100% rename from plants_lib/textures/flower_dandelion_white.png rename to flowers/textures/flower_dandelion_white.png diff --git a/plants_lib/textures/flower_dandelion_white_pot.png b/flowers/textures/flower_dandelion_white_pot.png similarity index 100% rename from plants_lib/textures/flower_dandelion_white_pot.png rename to flowers/textures/flower_dandelion_white_pot.png diff --git a/plants_lib/textures/flower_dandelion_yellow.png b/flowers/textures/flower_dandelion_yellow.png similarity index 100% rename from plants_lib/textures/flower_dandelion_yellow.png rename to flowers/textures/flower_dandelion_yellow.png diff --git a/plants_lib/textures/flower_dandelion_yellow_pot.png b/flowers/textures/flower_dandelion_yellow_pot.png similarity index 100% rename from plants_lib/textures/flower_dandelion_yellow_pot.png rename to flowers/textures/flower_dandelion_yellow_pot.png diff --git a/plants_lib/textures/flower_geranium.png b/flowers/textures/flower_geranium.png similarity index 100% rename from plants_lib/textures/flower_geranium.png rename to flowers/textures/flower_geranium.png diff --git a/plants_lib/textures/flower_geranium_pot.png b/flowers/textures/flower_geranium_pot.png similarity index 100% rename from plants_lib/textures/flower_geranium_pot.png rename to flowers/textures/flower_geranium_pot.png diff --git a/plants_lib/textures/flower_pot.png b/flowers/textures/flower_pot.png similarity index 100% rename from plants_lib/textures/flower_pot.png rename to flowers/textures/flower_pot.png diff --git a/plants_lib/textures/flower_rose.png b/flowers/textures/flower_rose.png similarity index 100% rename from plants_lib/textures/flower_rose.png rename to flowers/textures/flower_rose.png diff --git a/plants_lib/textures/flower_rose_pot.png b/flowers/textures/flower_rose_pot.png similarity index 100% rename from plants_lib/textures/flower_rose_pot.png rename to flowers/textures/flower_rose_pot.png diff --git a/plants_lib/textures/flower_seaweed.png b/flowers/textures/flower_seaweed.png similarity index 100% rename from plants_lib/textures/flower_seaweed.png rename to flowers/textures/flower_seaweed.png diff --git a/plants_lib/textures/flower_tulip.png b/flowers/textures/flower_tulip.png similarity index 100% rename from plants_lib/textures/flower_tulip.png rename to flowers/textures/flower_tulip.png diff --git a/plants_lib/textures/flower_tulip_pot.png b/flowers/textures/flower_tulip_pot.png similarity index 100% rename from plants_lib/textures/flower_tulip_pot.png rename to flowers/textures/flower_tulip_pot.png diff --git a/plants_lib/textures/flower_viola.png b/flowers/textures/flower_viola.png similarity index 100% rename from plants_lib/textures/flower_viola.png rename to flowers/textures/flower_viola.png diff --git a/plants_lib/textures/flower_viola_pot.png b/flowers/textures/flower_viola_pot.png similarity index 100% rename from plants_lib/textures/flower_viola_pot.png rename to flowers/textures/flower_viola_pot.png diff --git a/plants_lib/textures/flower_waterlily.png b/flowers/textures/flower_waterlily.png similarity index 100% rename from plants_lib/textures/flower_waterlily.png rename to flowers/textures/flower_waterlily.png diff --git a/plants_lib/textures/junglegrass_medium.png b/junglegrass/textures/junglegrass_medium.png similarity index 100% rename from plants_lib/textures/junglegrass_medium.png rename to junglegrass/textures/junglegrass_medium.png diff --git a/plants_lib/textures/junglegrass_short.png b/junglegrass/textures/junglegrass_short.png similarity index 100% rename from plants_lib/textures/junglegrass_short.png rename to junglegrass/textures/junglegrass_short.png diff --git a/plants_lib/textures/junglegrass_shortest.png b/junglegrass/textures/junglegrass_shortest.png similarity index 100% rename from plants_lib/textures/junglegrass_shortest.png rename to junglegrass/textures/junglegrass_shortest.png diff --git a/plants_lib/init.lua b/plants_lib/init.lua index 8715047..c4d13a6 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -90,7 +90,11 @@ end -- The growing ABM -grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_nodes, facedir) +grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_nodes, facedir, need_wall, grow_vertically, height_limit, ground_nodes) + if need_wall ~= true then need_wall = false end + if grow_vertically ~= true then grow_vertically = false end + if height_limit == nil then height_limit = 62000 end + if ground_node == nil then ground_nodes = { "default:dirt_with_grass" } end minetest.register_abm({ nodenames = { gplant }, interval = gdelay, @@ -100,15 +104,21 @@ grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_no local p_bot = {x=pos.x, y=pos.y-1, z=pos.z} local n_top = minetest.env:get_node(p_top) local n_bot = minetest.env:get_node(p_bot) + local groundnode = minetest.env:get_node({x=pos.x, y=pos.y-height_limit, z=pos.z}) if string.find(dump(grow_nodes), n_bot.name) ~= nil and n_top.name == "air" then - - -- corner case for wall-climbing poison ivy - if gplant == "poisonivy:climbing" then - local walldir=plant_valid_wall(p_top) - if walldir ~= nil then - dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..")") - minetest.env:add_node(p_top, { name = gplant, param2 = walldir }) + if grow_vertically then + if find_first_node(pos, height_limit, ground_nodes) ~= nil then + if need_wall then + local walldir=plant_valid_wall(p_top) + if walldir ~= nil then + dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..") on wall "..walldir) + minetest.env:add_node(p_top, { name = gplant, param2 = walldir }) + end + else + dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..")") + minetest.env:add_node(p_top, { name = gplant }) + end end -- corner case for changing short junglegrass to dry shrub in desert @@ -155,6 +165,19 @@ plant_valid_wall = function(wallpos) return walldir end +-- Function to search straight down from (pos) to find first node in match list. + +find_first_node = function(pos, height_limit, nodelist) + for i = 1, height_limit do + n = minetest.env:get_node({x=pos.x, y=pos.y-i, z=pos.z}) + if string.find(dump(nodelist),n.name) ~= nil then + return n.name + end + end + return nil +end + + local enstr = "" if enabled_flowers then enstr = enstr.." flowers" end diff --git a/poinsonivy/init.lua b/poinsonivy/init.lua index 702bc2b..13e6850 100644 --- a/poinsonivy/init.lua +++ b/poinsonivy/init.lua @@ -63,7 +63,9 @@ minetest.register_node(':poisonivy:climbing', { }) spawn_on_surfaces(spawn_delay, "poisonivy:seedling", 10 , spawn_chance/10, "default:dirt_with_grass", {"group:poisonivy","group:flower"}, poisonivy_seed_diff, 7) + grow_plants(spawn_delay, grow_chance, "poisonivy:seedling", "poisonivy:sproutling", nil, {"default:dirt_with_grass"}) -grow_plants(spawn_delay, grow_chance*2, "poisonivy:climbing", nil, nil, nil) + +grow_plants(spawn_delay, grow_chance*2, "poisonivy:climbing", nil, nil, nil ,nil,true,true,nil,{"default:dirt_with_grass"}) enabled_poisonivy = true diff --git a/plants_lib/textures/poisonivy_climbing.png b/poinsonivy/textures/poisonivy_climbing.png similarity index 100% rename from plants_lib/textures/poisonivy_climbing.png rename to poinsonivy/textures/poisonivy_climbing.png diff --git a/plants_lib/textures/poisonivy_seedling.png b/poinsonivy/textures/poisonivy_seedling.png similarity index 100% rename from plants_lib/textures/poisonivy_seedling.png rename to poinsonivy/textures/poisonivy_seedling.png diff --git a/plants_lib/textures/poisonivy_sproutling.png b/poinsonivy/textures/poisonivy_sproutling.png similarity index 100% rename from plants_lib/textures/poisonivy_sproutling.png rename to poinsonivy/textures/poisonivy_sproutling.png