mirror of
https://github.com/mt-mods/biome_lib.git
synced 2025-06-28 22:36:44 +02:00
Compare commits
50 Commits
2018-11-26
...
2021-04-16
Author | SHA1 | Date | |
---|---|---|---|
f165434a84 | |||
d6cba18844 | |||
f003f19998 | |||
d06ab90e01 | |||
ba46e6c05e | |||
ed0b23677d | |||
3b35fc67c6 | |||
eabc053c05 | |||
dd650da443 | |||
0a34e3c7af | |||
07c2b1d9d4 | |||
1dc0febd8c | |||
50f921a85a | |||
6009f261c2 | |||
531577afcf | |||
e346fd599f | |||
212024a9b4 | |||
1d2593f022 | |||
3bc8737e2d | |||
0ea4cb3848 | |||
bef0a0d87e | |||
89ca62e492 | |||
a325c2ccd8 | |||
8ecb401309 | |||
9ed4858518 | |||
26dbbb5a67 | |||
ec0a0f0c3b | |||
e92361675f | |||
7f1fec6ae0 | |||
f569bb1fbd | |||
f2a807b814 | |||
9b7705c380 | |||
c9f6235815 | |||
ddd88613e0 | |||
27cd07cb36 | |||
ac8738d837 | |||
0005af6022 | |||
228296411e | |||
353ca0cbd4 | |||
d65c72d48b | |||
10a1089767 | |||
5a910875af | |||
a96f015ce9 | |||
d72e15f1d0 | |||
29899f2d36 | |||
0837ff7fd2 | |||
ff9ce531d6 | |||
fa304f9d18 | |||
b7d69a8487 | |||
f056d6d76e |
46
API.txt
46
API.txt
@ -72,6 +72,7 @@ biome = {
|
||||
---- most likely want to use at least some of these to limit how and
|
||||
---- where your objects are spawned.
|
||||
|
||||
label = string, -- set this to identify the ABM for Minetest's profiler
|
||||
avoid_nodes = {table}, -- same meaning as savoid, above
|
||||
avoid_radius = num, -- same as sradius
|
||||
seed_diff = num, -- The Perlin seed difference value passed to the
|
||||
@ -238,7 +239,7 @@ biome = {
|
||||
---- Everything else is optional, but you'll definitely want to use
|
||||
---- some of these other fields to limit where and under what
|
||||
---- conditions the objects are spawned.
|
||||
|
||||
|
||||
below_nodes = {table}, -- List of nodes that must be below the target
|
||||
-- node. Useful in snow biomes to keep objects from
|
||||
-- spawning in snow that's on the wrong surface for
|
||||
@ -342,14 +343,18 @@ into something else over time. This function has no return value, and accepts
|
||||
a biome definition table as the only parameter. These are defined like so:
|
||||
|
||||
options = {
|
||||
grow_plant = "string", -- Name of the node to be grown into something
|
||||
-- else. This value is passed to the ABM as the
|
||||
-- "nodenames" parameter, so it is the plants
|
||||
-- themselves that are the ABM trigger, rather than
|
||||
label = string, -- set this to identify the ABM for Minetest's
|
||||
-- profiler. If not set, biome_lib will set it to
|
||||
-- "biome_lib grow_plants(): " appended with the node
|
||||
-- in grow_plant (or the first item if it's a table)
|
||||
grow_plant = "string" or {table}, -- Name(s) of the node(s) to be grown
|
||||
-- into something else. This value is passed to the
|
||||
-- ABM as the "nodenames" parameter, so the plants
|
||||
-- themselves are the ABM trigger, rather than
|
||||
-- the ground they spawned on. A plant will only grow
|
||||
-- if the node above it is air. Can also be a table,
|
||||
-- but note that all nodes referenced therein will be
|
||||
-- grown into the same object.
|
||||
-- if the node above it is air. If you use a table,
|
||||
-- note that all nodes referenced therein will be
|
||||
-- grown into the same final object.
|
||||
grow_delay = num, -- Passed as the ABM "interval" parameter, as with
|
||||
-- spawning.
|
||||
grow_chance = num, -- Passed as the ABM "chance" parameter.
|
||||
@ -441,12 +446,22 @@ question is already loaded, or false if not.
|
||||
|
||||
|
||||
=====
|
||||
dbg(string)
|
||||
dbg(string, level)
|
||||
|
||||
This is a simple debug output function which takes one string parameter. It
|
||||
just checks if DEBUG is true and outputs the phrase "[Plantlife] " followed by
|
||||
the supplied string, via the print() function, if so.
|
||||
|
||||
'level' is a number that, if supplied, dictates the lowest 'biome_lib_debug'
|
||||
can be set to in minetest.conf for this message to be displayed. Both the
|
||||
default log level and the default message level are 0, thus always showing the
|
||||
supplied message.
|
||||
|
||||
Although it's not set in stone, a good practice is to use a level of 0 (or
|
||||
just omit the value) for anything that generally important enough that it
|
||||
ought always be shown, 1 for errors, 2 for warnings, 3 for info, 4 for verbose
|
||||
spammy stuff.
|
||||
|
||||
=====
|
||||
biome_lib:generate_tree(pos, treemodel)
|
||||
biome_lib:grow_tree(pos, treemodel)
|
||||
@ -583,3 +598,16 @@ And this particular one is mapped slightly differently from the others:
|
||||
|
||||
(Note the +150 and +50 offsets)
|
||||
|
||||
|
||||
==================
|
||||
Default game nodes
|
||||
==================
|
||||
|
||||
Although this project was intended to be used with minetest_game, it can be
|
||||
configured to work with something else instead. All you need to do is provide
|
||||
the names of the nodes in your game you want biome_lib's internals to use.
|
||||
|
||||
See settingtypes.txt for a list. Any item listed there can be changed either
|
||||
by adding it to your minetest.conf, or by using the "all settings" menu in
|
||||
Minetest, whatever's appropriate for your particular setup.
|
||||
|
||||
|
@ -12,7 +12,7 @@ Both mapgen-based spawning and ABM-based spawning is supported. Growing code is
|
||||
|
||||
It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7.
|
||||
|
||||
**Dependencies**: default from minetest_game
|
||||
**Dependencies:** nothing, but if you don't use `minetest_game`, you'll need to supply some settings (see API.txt).
|
||||
|
||||
**Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack),
|
||||
[More Trees](https://github.com/minetest-mods/moretrees)
|
||||
@ -25,4 +25,6 @@ It is primarily intended for mapgen v6, but it should work fine when used with m
|
||||
* biome_lib:find_valid_wall()
|
||||
* biome_lib:is_node_loaded()
|
||||
|
||||
For a complete description of these functions as well as several of the internal variables within the mod, [read the API.txt document](https://raw.githubusercontent.com/minetest-mods/biome_lib/master/API.txt) included in this package.
|
||||
For a complete description of these functions as well as several of the internal variables within the mod, see `API.txt`.
|
||||
|
||||
**Configuration:** This mod has several variables you can set in your `minetest.conf` to change things a bit, from the default nodes it uses, to the debug log level and the block queue behavior. For a list with complete descriptions, see `settingtypes.txt`.
|
||||
|
@ -1,3 +0,0 @@
|
||||
default
|
||||
intllib?
|
||||
|
90
growth.lua
Normal file
90
growth.lua
Normal file
@ -0,0 +1,90 @@
|
||||
local time_scale = ...
|
||||
|
||||
-- The growing ABM
|
||||
|
||||
function biome_lib.check_surface(name, nodes)
|
||||
if not nodes then return true end
|
||||
if type(nodes) == "string" then return nodes == name end
|
||||
if nodes.set and nodes[name] then
|
||||
return true
|
||||
else
|
||||
for _, n in ipairs(nodes) do
|
||||
if name == n then return true end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function biome_lib:grow_plants(opts)
|
||||
|
||||
local options = opts
|
||||
|
||||
options.height_limit = options.height_limit or 5
|
||||
options.ground_nodes = options.ground_nodes or biome_lib.default_ground_nodes
|
||||
options.grow_nodes = options.grow_nodes or biome_lib.default_grow_nodes
|
||||
options.seed_diff = options.seed_diff or 0
|
||||
|
||||
local n
|
||||
|
||||
if type(options.grow_plant) == "table" then
|
||||
n = "multi: "..options.grow_plant[1]..", ..."
|
||||
else
|
||||
n = options.grow_plant
|
||||
end
|
||||
|
||||
options.label = options.label or "biome_lib grow_plants(): "..n
|
||||
|
||||
if options.grow_delay*time_scale >= 1 then
|
||||
options.interval = options.grow_delay*time_scale
|
||||
else
|
||||
options.interval = 1
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = { options.grow_plant },
|
||||
interval = options.interval,
|
||||
chance = options.grow_chance,
|
||||
label = options.label,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local p_bot = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n_top = minetest.get_node(p_top)
|
||||
local n_bot = minetest.get_node(p_bot)
|
||||
local root_node = minetest.get_node({x=pos.x, y=pos.y-options.height_limit, z=pos.z})
|
||||
local walldir = nil
|
||||
if options.need_wall and options.verticals_list then
|
||||
walldir = biome_lib:find_adjacent_wall(p_top, options.verticals_list, options.choose_random_wall)
|
||||
end
|
||||
if biome_lib.default_grow_through_nodes[n_top.name]
|
||||
and (not options.need_wall or (options.need_wall and walldir)) then
|
||||
if options.grow_vertically and walldir then
|
||||
if biome_lib:search_downward(pos, options.height_limit, options.ground_nodes) then
|
||||
minetest.swap_node(p_top, { name = options.grow_plant, param2 = walldir})
|
||||
end
|
||||
|
||||
elseif biome_lib.check_surface(n_bot.name, options.grow_nodes) then
|
||||
if not options.grow_result and not options.grow_function then
|
||||
minetest.swap_node(pos, biome_lib.air)
|
||||
|
||||
else
|
||||
biome_lib:replace_object(pos, options.grow_result, options.grow_function, options.facedir, options.seed_diff)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
-- spawn_tree() on generate is routed through here so that other mods can hook
|
||||
-- into it.
|
||||
|
||||
function biome_lib:generate_tree(pos, nodes_or_function_or_model)
|
||||
minetest.spawn_tree(pos, nodes_or_function_or_model)
|
||||
end
|
||||
|
||||
-- and this one's for the call used in the growing code
|
||||
|
||||
function biome_lib:grow_tree(pos, nodes_or_function_or_model)
|
||||
minetest.spawn_tree(pos, nodes_or_function_or_model)
|
||||
end
|
2
mod.conf
2
mod.conf
@ -1 +1,3 @@
|
||||
name = biome_lib
|
||||
min_minetest_version = 5.2.0
|
||||
optional_depends = default, intllib
|
||||
|
75
search_functions.lua
Normal file
75
search_functions.lua
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
-- function to decide if a node has a wall that's in verticals_list{}
|
||||
-- returns wall direction of valid node, or nil if invalid.
|
||||
|
||||
function biome_lib:find_adjacent_wall(pos, verticals, randomflag)
|
||||
local verts = dump(verticals)
|
||||
if randomflag then
|
||||
local walltab = {}
|
||||
|
||||
if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 3 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 2 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then walltab[#walltab + 1] = 5 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then walltab[#walltab + 1] = 4 end
|
||||
|
||||
if #walltab > 0 then return walltab[math.random(1, #walltab)] end
|
||||
|
||||
else
|
||||
if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then return 3 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then return 2 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then return 5 end
|
||||
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then return 4 end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Function to search downward from the given position, looking for the first
|
||||
-- node that matches the ground table. Returns the new position, or nil if
|
||||
-- height limit is exceeded before finding it.
|
||||
|
||||
function biome_lib:search_downward(pos, heightlimit, ground)
|
||||
for i = 0, heightlimit do
|
||||
if string.find(dump(ground), minetest.get_node({x=pos.x, y=pos.y-i, z = pos.z}).name) then
|
||||
return {x=pos.x, y=pos.y-i, z = pos.z}
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function biome_lib:find_open_side(pos)
|
||||
if minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name == "air" then
|
||||
return {newpos = { x=pos.x-1, y=pos.y, z=pos.z }, facedir = 2}
|
||||
end
|
||||
if minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name == "air" then
|
||||
return {newpos = { x=pos.x+1, y=pos.y, z=pos.z }, facedir = 3}
|
||||
end
|
||||
if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1 }).name == "air" then
|
||||
return {newpos = { x=pos.x, y=pos.y, z=pos.z-1 }, facedir = 4}
|
||||
end
|
||||
if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1 }).name == "air" then
|
||||
return {newpos = { x=pos.x, y=pos.y, z=pos.z+1 }, facedir = 5}
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- "Record" the map chunks being generated by the core mapgen,
|
||||
-- split into individual mapblocks to reduce lag
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||
local timestamp = minetest.get_us_time()
|
||||
for x = 0, 4 do
|
||||
local minx = minp.x + x*16
|
||||
for y = 0, 4 do
|
||||
local miny = minp.y + y*16
|
||||
for z = 0, 4 do
|
||||
local minz = minp.z + z*16
|
||||
|
||||
local bmin = {x=minx, y=miny, z=minz}
|
||||
local bmax = {x=minx + 15, y=miny + 15, z=minz + 15}
|
||||
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, true, timestamp }
|
||||
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false, timestamp }
|
||||
end
|
||||
end
|
||||
end
|
||||
biome_lib.run_block_recheck_list = true
|
||||
end)
|
48
settingtypes.txt
Normal file
48
settingtypes.txt
Normal file
@ -0,0 +1,48 @@
|
||||
# Comma-separated list of things that a spawned node is allowed to grow
|
||||
# through. Air is always added to whatever else you specify here.
|
||||
biome_lib_default_grow_through_nodes (List of things a plant can grow through) string default:snow
|
||||
|
||||
# Comma-separated list of nodes that should be treated as water or water-like
|
||||
# for the sake of looking for neighboring wet ground.
|
||||
biome_lib_default_water_nodes (List of "water-like" sources) string default:water_source,default:water_flowing,default:river_water_source,default:river_water_flowing
|
||||
|
||||
# Comma-separated list of nodes that should be considered "wet" if one of
|
||||
# the configured "water-like" sources is nearby.
|
||||
biome_lib_default_wet_surfaces (List of "wet" nodes) string default:dirt,default:dirt_with_grass,default:sand
|
||||
|
||||
# Comma-separated list of nodes that something must be sitting on to be
|
||||
# able to actively change from one thing to another (such as a sapling
|
||||
# growing into a tree), to be used if the mod that added that growable
|
||||
# thing didn't provide its own list of suitable surfaces.
|
||||
biome_lib_default_grow_nodes (List of default surfaces a plant can thrive on) string default:dirt_with_grass
|
||||
|
||||
# Comma-separated list of nodes to use as the "root" of something that can
|
||||
# gradually climb up a wall (such as ivy), to be used if the mod that added
|
||||
# the climing thing didn't provide its own list.
|
||||
biome_lib_default_ground_nodes (List of default root nodes) string default:dirt_with_grass
|
||||
|
||||
# biome_lib divides its workload into "actions", as dictated by the sum
|
||||
# total of all mods that use it, and this sets how much of that work is done
|
||||
# per globalstep tick. If positive, a single action is executed on that
|
||||
# percentage of ticks, on average. If negative, it becomes positive, and
|
||||
# that many actions are executed on every single tick, skipping none.
|
||||
# More negative means more throughput, at the expense of lag. On fast PC's,
|
||||
# a setting of between -500 and -2000 might be good.
|
||||
biome_lib_queue_ratio (Queue run ratio) int -200
|
||||
|
||||
# Minetest's map generator allows neighboring areas to overflow into one
|
||||
# another, to create smooth terrain, but it often hands the map blocks that
|
||||
# comprise those areas to Lua (and hence, to biome_lib) before that overflow
|
||||
# function happens, which causes the mapgen to overwrite whatever Lua does
|
||||
# to them. This setting (in seconds) makes biome_lib wait before adding its
|
||||
# normal output to those map blocks, to give the engine plenty of time to
|
||||
# run that overflow feature first.
|
||||
biome_lib_block_timeout (Deferred block timeout) int 300
|
||||
|
||||
# This does just what it sounds like - it shows all debug output that's sent
|
||||
# with a level equal to or greater than this value. A setting of 0 shows only
|
||||
# the bare necessities, such as the startup and shutdown messages, 1 adds
|
||||
# internal non-fatal errors to what's shown, 2 adds warnings, 3 adds other
|
||||
# basic info, 4 adds all the verbose debugging spew. 3 is perhaps the most
|
||||
# useful setting.
|
||||
biome_lib_debug_log_level (Debug log level) int 0
|
Reference in New Issue
Block a user