mirror of
https://github.com/mt-mods/plantlife_modpack.git
synced 2024-12-26 02:20:20 +01:00
Expanded the API to allow for additional biome controls.
See API.txt for details.
This commit is contained in:
parent
9cb6f594ee
commit
b0de25407d
156
API.txt
156
API.txt
@ -15,7 +15,7 @@ dbg()
|
|||||||
-----
|
-----
|
||||||
The first of these, spawn_on_surfaces() is defined with quite a large number
|
The first of these, spawn_on_surfaces() is defined with quite a large number
|
||||||
of variables. All of the variables below, if specified at all, must be
|
of variables. All of the variables below, if specified at all, must be
|
||||||
specified exactly in the order given here.
|
specified exactly in the order given here. This function has no return value.
|
||||||
|
|
||||||
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface,
|
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface,
|
||||||
savoid, seed_diff, lightmin, lightmax, nneighbors,
|
savoid, seed_diff, lightmin, lightmax, nneighbors,
|
||||||
@ -24,61 +24,82 @@ spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface,
|
|||||||
The first several of these are all required, and are from the last version of
|
The first several of these are all required, and are from the last version of
|
||||||
the flowers mod, so this part of the API should be the same as before.
|
the flowers mod, so this part of the API should be the same as before.
|
||||||
|
|
||||||
sdelay: The value passed to the ABM's interval parameter, usually in the
|
sdelay: The value passed to the ABM's interval parameter, usually
|
||||||
1000-3000 range.
|
in the 1000-3000 range.
|
||||||
splant: The node name of the item to spawn (e.g. "flowers:flower_rose").
|
splant: The node name of the item to spawn (e.g.
|
||||||
Note that if the plant is "poisonivy:seedling", and it's next to
|
"flowers:flower_rose"). Note that if the plant is
|
||||||
a wall at spawn time, it automatically becomes the wall-climbing
|
"poisonivy:seedling", and it's next to a wall at spawn
|
||||||
variety. A plant will of course only be spawned if the node about
|
time, it automatically becomes the wall-climbing variety.
|
||||||
|
A plant will of course only be spawned if the node about
|
||||||
to be replaced is air.
|
to be replaced is air.
|
||||||
sradius: Don't spawn within this many nodes of the avoid items mentioned
|
sradius: Don't spawn within this many nodes of the avoid items
|
||||||
below.
|
mentioned below.
|
||||||
schance: The value passed to the ABM's chance parameter, normally in the
|
schance: The value passed to the ABM's chance parameter, normally
|
||||||
10-100 range.
|
in the 10-100 range.
|
||||||
ssurface: Table with the names of the nodes on which to spawn the plant in
|
ssurface: Table with the names of the nodes on which to spawn the
|
||||||
question, such as {"default:sand","default:dirt_with_grass"}. It
|
plant in question, such as {"default:sand",
|
||||||
is not recommended to put "default:dirt" or "default:stone" into
|
"default:dirt_with_grass"}. It is not recommended to put
|
||||||
this table if you can do without it, as this will cause the engine
|
"default:dirt" or "default:stone" into this table if you
|
||||||
to process potentially large numbers of such nodes when deciding
|
can do without it, as this will cause the engine to
|
||||||
when to execute the ABM.
|
process potentially large numbers of such nodes when
|
||||||
savoid: Table with a list of groups and/or node names to avoid when
|
deciding when to execute the ABM and where it should
|
||||||
spawning the plant, such as {"group:flowers","default:tree"}.
|
operate.
|
||||||
|
savoid: Table with a list of groups and/or node names to avoid
|
||||||
|
when spawning the plant, such as {"group:flowers",
|
||||||
|
"default:tree"}.
|
||||||
|
|
||||||
From here down are several optional parameters. You can use as many as you
|
From here down are several optional parameters. You can use as many as you
|
||||||
need, but you must specify them in order (so if you want lightmax, you need
|
need, but you must specify them in order (so if you want lightmax, you need
|
||||||
lightmin and seed_diff also, but not the rest).
|
lightmin and seed_diff also, but not the rest).
|
||||||
|
|
||||||
seed_diff: The perlin seed difference value passed to the
|
seed_diff: The perlin seed difference value passed to the
|
||||||
minetest.env:get_perlin() function. Used along with the global
|
minetest.env:get_perlin() function. Used along with the
|
||||||
perlin controls below to create the "biome" in which the plants
|
global perlin controls below to create the "biome" in
|
||||||
will spawn. Usually a value of somewhere in the 10 to 100 range
|
which the plants will spawn. Usually a value of somewhere
|
||||||
is good. Defaults to 0 if not provided
|
in the 10 to 100 range is good. Defaults to 0 if not
|
||||||
lightmin: Minimum amount of light necessary to make a plant spawn. Defaults
|
provided.
|
||||||
to 0.
|
lightmin: Minimum amount of light necessary to make a plant spawn.
|
||||||
|
Defaults to 0.
|
||||||
lightmax: Maximum amount of light present to allow a plant to spawn.
|
lightmax: Maximum amount of light present to allow a plant to spawn.
|
||||||
Defaults to the engine's MAX_LIGHT value of 14.
|
Defaults to the engine's MAX_LIGHT value of 14.
|
||||||
nneighbors: Table with a list of neighboring nodes, passed to the ABM as the
|
nneighbors: Table with a list of neighboring nodes, passed to the ABM
|
||||||
"neighbors" parameter, indicating what needs to be next to the
|
as the "neighbors" parameter, indicating what needs to be
|
||||||
node the plant is about to spawn on, such as
|
next to the node the plant is about to spawn on, such as
|
||||||
{"default:stone","default:water_source"}. Defaults to the value
|
{"default:stone","default:water_source"}. Defaults to the
|
||||||
of ssurface if not provided.
|
value of ssurface if not provided.
|
||||||
ocount: There must be at least this many of the above neighbors around the
|
ocount: There must be at least this many of the above neighbors in
|
||||||
node the plant is about to spawn on for it to happen. Defaults to
|
the eight spaces immediately surrounding the node the
|
||||||
|
plant is about to spawn on for it to happen. Defaults to
|
||||||
0.
|
0.
|
||||||
facedir: The value passed to the param2 variable when adding the plant node
|
facedir: The value passed to the param2 variable when adding the
|
||||||
to the map. Defaults to 0.
|
plant node to the map. Defaults to 0.
|
||||||
depthmax: If a node spawns on top of a water source, the water must be at
|
depthmax: If a node spawns on top of a water source, the water must
|
||||||
most this deep. Defaults to 1 node.
|
be at most this deep. Defaults to 1 node.
|
||||||
altitudemin: Items must be at this altitude or higher to spawn at all.
|
altitudemin: Items must be at this altitude or higher to spawn at all.
|
||||||
Defaults to -31000.
|
Defaults to -31000.
|
||||||
altitudemax: But no higher than this altitude. Defaults to +31000.
|
altitudemax: But no higher than this altitude. Defaults to +31000.
|
||||||
|
sbiome: List of nodes that must be somewhere in the vicinity in
|
||||||
|
order for the plant to spawn. Typically this would be
|
||||||
|
something like "default:water_source" or "default:sand".
|
||||||
|
Defaults to the value of ssurface if not provided.
|
||||||
|
sbiomesize: How large of an area to check for the above node.
|
||||||
|
Specifically, this checks a cuboid area centered on the
|
||||||
|
node to be spawned on, 3 tall and this wide/long.
|
||||||
|
Defaults to 0.
|
||||||
|
sbiomecount: How many of the above nodes must be within that radius.
|
||||||
|
Defaults to 1.
|
||||||
|
|
||||||
|
By default, if a biome node, size, and count are not defined, the biome
|
||||||
|
checking is disabled. Same holds true for the nneighbors bit above that.
|
||||||
|
|
||||||
-----
|
-----
|
||||||
The second function, grow_plants() is defined like so:
|
The second function, grow_plants() is used to turn the spawned nodes above
|
||||||
|
into something else over time. This function has no return value, and is
|
||||||
|
defined like so:
|
||||||
|
|
||||||
grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node,
|
grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node,
|
||||||
grow_nodes, facedir, need_wall, grow_vertically, height_limit,
|
grow_nodes, facedir, need_wall, grow_vertically, height_limit,
|
||||||
ground_nodes)
|
ground_nodes, grow_function)
|
||||||
|
|
||||||
gdelay: Passed as the ABM "interval" parameter, as with spawning.
|
gdelay: Passed as the ABM "interval" parameter, as with spawning.
|
||||||
gchance: Passed as the ABM "chance" parameter.
|
gchance: Passed as the ABM "chance" parameter.
|
||||||
@ -87,40 +108,55 @@ gplant: Name of the node being grown. This value is passed as the
|
|||||||
parameter, so it is the plants themselves that are the ABM
|
parameter, so it is the plants themselves that are the ABM
|
||||||
trigger, rather than the ground they spawned on. A plant
|
trigger, rather than the ground they spawned on. A plant
|
||||||
will only grow if the node above it is air.
|
will only grow if the node above it is air.
|
||||||
gresult: Name of the node into which the above should transform when
|
gresult: Name of the node into which the above should transform
|
||||||
the ABM executes.
|
when the ABM executes.
|
||||||
dry_early_node: This value is ignored except for jungle grass, where it
|
dry_early_node: This value is ignored except for jungle grass, where it
|
||||||
indicates which node the grass must be on in order for it to
|
indicates which node the grass must be on in order for it
|
||||||
turn from "short" to default:dry_shrub.
|
to turn from "short" to default:dry_shrub.
|
||||||
grow_nodes: This node must be under the plant in order for it to grow at
|
grow_nodes: This node must be under the plant in order for it to grow
|
||||||
all. Normally this should be the same as the list of
|
at all. Normally this should be the same as the list of
|
||||||
surfaces passed to the spawning ABM as the "nodenames"
|
surfaces passed to the spawning ABM as the "nodenames"
|
||||||
parameter, such as
|
parameter, such as {"default:dirt_with_grass",
|
||||||
{"default:dirt_with_grass","default:sand"}. This is so that
|
"default:sand"}. This is so that the plant can be
|
||||||
the plant can be manually placed on something like a flower
|
manually placed on something like a flower pot or
|
||||||
pot or something without it growing and eventually dieing.
|
something without it growing and eventually dieing.
|
||||||
facedir: Same as with spawning a plant. If supplied, this value is
|
facedir: Same as with spawning a plant. If supplied, this value is
|
||||||
passed to the param2 variable when changing the plant. If nil
|
passed to the param2 variable when changing the plant. If
|
||||||
or left out, no new param2 value is applied.
|
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
|
need_wall: Set this to true if you the plant needs to grow against a
|
||||||
wall. Defaults to false.
|
wall. Defaults to false.
|
||||||
grow_vertically: Set this to true if the plant needs to grow vertically, as in
|
grow_vertically: Set this to true if the plant needs to grow vertically, as
|
||||||
climbing poison ivy. Defaults to false.
|
in climbing poison ivy. Defaults to false.
|
||||||
height_limit: Just how tall can a vertically-growing plant go? Set this
|
height_limit: Just how tall can a vertically-growing plant go? Set this
|
||||||
accordingly. The mod will search straight down from the
|
accordingly. The mod will search straight down from the
|
||||||
position being spawned at to find a ground node, below.
|
position being spawned at to find a ground node, below.
|
||||||
Defaults to 62000 (unlimited).
|
Defaults to 62000 (unlimited).
|
||||||
ground_nodes: What nodes should be treated as "the ground" below a
|
ground_nodes: What nodes should be treated as "the ground" below a
|
||||||
vertically-growing plant. Usually this will be the same as
|
vertically-growing plant. Usually this will be the same
|
||||||
the grow_nodes table, but might also include, for example,
|
as the grow_nodes table, but might also include, for
|
||||||
water or some other surrounding material. Defaults to
|
example, water or some other surrounding material.
|
||||||
"default:dirt_with_grass".
|
Defaults to "default:dirt_with_grass".
|
||||||
|
grow_function: Execute the named function (which must be supplied as just
|
||||||
|
the name of the function as a string) when growing this
|
||||||
|
node, rather than using the method provided by the default
|
||||||
|
growing code. Note that if this is specified, only the
|
||||||
|
gdelay, gchance, and gplant variables will be used, the
|
||||||
|
rest will be ignored by the growing ABM. You can still
|
||||||
|
read them from within the function if you need to. The
|
||||||
|
function will be passed two parameters in order: The
|
||||||
|
position of the node to be "grown" (in the usual table
|
||||||
|
format), and the Perlin noise value at the location in
|
||||||
|
question.
|
||||||
|
seed_diff: The perlin seed diff to be use to calculate the noise
|
||||||
|
value given to the above grow_function. Should be the
|
||||||
|
same as the seed diff used when first spawning the plant
|
||||||
|
that's being grown.
|
||||||
|
|
||||||
-----
|
-----
|
||||||
plant_valid_wall() expects only a single parameter, "pos", which is a table
|
plant_valid_wall() expects only a single parameter, "pos", which is the usual
|
||||||
indicating the X,Y,Z coordinates to search for nearby adjacent walls. This
|
table indicating the coordinates around which to search for adjacent walls.
|
||||||
function returns the location of the first wall found as a facedir value, or
|
This function returns the location of the first wall found as a facedir value,
|
||||||
nil if there are no adjacent walls.
|
or nil if there are no adjacent walls.
|
||||||
|
|
||||||
-----
|
-----
|
||||||
is_node_loaded() is defined in exactly the same manner (that is, "node_pos" is
|
is_node_loaded() is defined in exactly the same manner (that is, "node_pos" is
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
-- Plantlife mod by Vanessa Ezekowitz
|
-- Plantlife library mod by Vanessa Ezekowitz
|
||||||
-- 2012-11-29
|
-- 2013-01-00
|
||||||
--
|
--
|
||||||
-- This mod combines all of the functionality from poison ivy,
|
-- License: WTFPL
|
||||||
-- flowers, and jungle grass. If you have any of these, you no
|
|
||||||
-- longer need them.
|
|
||||||
--
|
|
||||||
-- License:
|
|
||||||
-- CC-BY-SA for most textures, except flowers
|
|
||||||
-- WTFPL for the flowers textures
|
|
||||||
-- WTFPL for all code and everything else
|
|
||||||
|
|
||||||
-- Various settings - most of these probably won't need to be changed
|
-- Various settings - most of these probably won't need to be changed
|
||||||
|
|
||||||
plantlife_seed_diff = 329 -- needs to be global so other mods can see it
|
plantlife_seed_diff = 329 -- needs to be global so other mods can see it
|
||||||
|
|
||||||
local plantlife_debug = false -- ...unless you want the modpack to spam the console ;-)
|
local plantlife_debug = true -- ...unless you want the modpack to spam the console ;-)
|
||||||
|
|
||||||
local perlin_octaves = 3
|
local perlin_octaves = 3
|
||||||
local perlin_persistence = 0.6
|
local perlin_persistence = 0.6
|
||||||
@ -42,15 +35,18 @@ end
|
|||||||
|
|
||||||
-- The spawning ABM
|
-- The spawning ABM
|
||||||
|
|
||||||
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax, altmin, altmax)
|
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax, altmin, altmax, sbiome, sbiomesize, sbiomecount)
|
||||||
if seed_diff == nil then seed_diff = 0 end
|
if seed_diff == nil then seed_diff = 0 end
|
||||||
if lightmin == nil then lightmin = 0 end
|
if lightmin == nil then lightmin = 0 end
|
||||||
if lightmax == nil then lightmax = LIGHT_MAX end
|
if lightmax == nil then lightmax = LIGHT_MAX end
|
||||||
if nneighbors == nil then nneighbors = ssurface end
|
if nneighbors == nil then nneighbors = ssurface end
|
||||||
if ocount == nil then ocount = 0 end
|
if ocount == nil then ocount = -1 end
|
||||||
if depthmax == nil then depthmax = 1 end
|
if depthmax == nil then depthmax = 1 end
|
||||||
if altmin == nil then altmin = -31000 end
|
if altmin == nil then altmin = -31000 end
|
||||||
if altmax == nil then altmax = 31000 end
|
if altmax == nil then altmax = 31000 end
|
||||||
|
if sbiome == nil then sbiome = "" end
|
||||||
|
if sbiomesize == nil then sbiomesize = 0 end
|
||||||
|
if sbiomecount == nil then sbiomecount = 1 end
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { ssurface },
|
nodenames = { ssurface },
|
||||||
interval = sdelay,
|
interval = sdelay,
|
||||||
@ -66,7 +62,12 @@ spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid,
|
|||||||
if minetest.env:find_node_near(p_top, sradius + math.random(-1.5,2), savoid) == nil
|
if minetest.env:find_node_near(p_top, sradius + math.random(-1.5,2), savoid) == nil
|
||||||
and n_light >= lightmin
|
and n_light >= lightmin
|
||||||
and n_light <= lightmax
|
and n_light <= lightmax
|
||||||
and table.getn(minetest.env:find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, nneighbors)) > ocount
|
and
|
||||||
|
(table.getn(minetest.env:find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, nneighbors)) > ocount
|
||||||
|
or ocount == -1)
|
||||||
|
and
|
||||||
|
(table.getn(minetest.env:find_nodes_in_area({x=pos.x-sbiomesize, y=pos.y-1, z=pos.z-sbiomesize}, {x=pos.x+sbiomesize, y=pos.y+1, z=pos.z+sbiomesize}, sbiome)) >= sbiomecount
|
||||||
|
or sbiome == "")
|
||||||
and pos.y >= altmin
|
and pos.y >= altmin
|
||||||
and pos.y <= altmax
|
and pos.y <= altmax
|
||||||
then
|
then
|
||||||
@ -91,7 +92,7 @@ end
|
|||||||
|
|
||||||
-- The growing ABM
|
-- The growing ABM
|
||||||
|
|
||||||
grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_nodes, facedir, need_wall, grow_vertically, height_limit, ground_nodes)
|
grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_nodes, facedir, need_wall, grow_vertically, height_limit, ground_nodes, grow_function, seed_diff)
|
||||||
if need_wall ~= true then need_wall = false end
|
if need_wall ~= true then need_wall = false end
|
||||||
if grow_vertically ~= true then grow_vertically = false end
|
if grow_vertically ~= true then grow_vertically = false end
|
||||||
if height_limit == nil then height_limit = 62000 end
|
if height_limit == nil then height_limit = 62000 end
|
||||||
@ -106,7 +107,7 @@ grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_no
|
|||||||
local n_top = minetest.env:get_node(p_top)
|
local n_top = minetest.env:get_node(p_top)
|
||||||
local n_bot = minetest.env:get_node(p_bot)
|
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})
|
local groundnode = minetest.env:get_node({x=pos.x, y=pos.y-height_limit, z=pos.z})
|
||||||
|
if grow_function == nil then
|
||||||
if string.find(dump(grow_nodes), n_bot.name) ~= nil and n_top.name == "air" then
|
if string.find(dump(grow_nodes), n_bot.name) ~= nil and n_top.name == "air" then
|
||||||
if grow_vertically then
|
if grow_vertically then
|
||||||
if find_first_node(pos, height_limit, ground_nodes) ~= nil then
|
if find_first_node(pos, height_limit, ground_nodes) ~= nil then
|
||||||
@ -140,6 +141,13 @@ grow_plants = function(gdelay, gchance, gplant, gresult, dry_early_node, grow_no
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if seed_diff == nil then seed_diff = 0 end
|
||||||
|
local perlin = minetest.env:get_perlin(seed_diff, perlin_octaves, perlin_persistence, perlin_scale )
|
||||||
|
local noise = perlin:get2d({x=pos.x, y=pos.z})
|
||||||
|
dbg("Want to execute "..grow_function.."("..dump(pos)..","..noise..")")
|
||||||
|
assert(loadstring(grow_function.."("..dump(pos)..","..noise..")"))()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user