Expose res and checks to find_biome function

This commit is contained in:
Wuzzy 2024-01-11 19:57:46 +01:00
parent 26db2a0623
commit 7dfd9aec62
2 changed files with 18 additions and 6 deletions

7
API.md
View File

@ -2,7 +2,7 @@
This mod has a single public function:
## `findbiome.find_biome(pos, biomes)`
## `findbiome.find_biome(pos, biomes, res, checks)`
Attempts to find a position of any biome listed in `biomes`, starting the search from `pos`.
The algorithm will start check positions around `pos`, starting at `pos` and extend its
@ -13,6 +13,8 @@ and the biome position is returned.
* `pos`: Position at where to start the search
* `biomes`: List of the technical names of the biomes to search for
* `res`: (optional): Size of search grid resolution (smaller = more precise, but also smaller area) (default: 64)
* `checks`: (optional): Number of points checked in total (default: 16384)
### Return value
@ -23,9 +25,12 @@ Returns `<biome position>, <success>`.
### Additional notes
* This function checks nodes on a square spiral going outwards from `pos`
* Although unlikely, there is *no 100% guarantee* that the biome will always be found if
it exists in the world. Very small and/or rare biomes tend to get “overlooked”.
* The search might include different Y levels than provided in `pos.y` in order
to find biomes that are restricted by Y coordinates
* If the mapgen `v6` is used, this function only works if the mod `biomeinfo` is
active, too. See the `biomeinfo` mod for more information
* Be careful not to check too many points, as this can lead to potentially longer
searches which may freeze the server for a while

View File

@ -23,13 +23,13 @@ else
playable_limit_max = vector.new(limit_estimate, limit_estimate, limit_estimate)
end
-- Parameters
-------------
-- Default parameters
---------------------
-- Resolution of search grid in nodes.
local res = 64
local DEFAULT_SEARCH_GRID_RESOLUTION = 64
-- Number of points checked in the square search grid (edge * edge).
local checks = 128 * 128
local DEFAULT_CHECKED_POINTS = 128 * 128
-- End of parameters
--------------------
@ -123,7 +123,14 @@ local function find_default_biome()
return nil
end
function findbiome.find_biome(pos, biomes)
function findbiome.find_biome(pos, biomes, res, checks)
if not res then
res = DEFAULT_SEARCH_GRID_SIZE
end
if not checks then
checks = DEFAULT_CHECKED_POINTS
end
pos = vector.round(pos)
-- Pos: Starting point for biome checks. This also sets the y co-ordinate for all
-- points checked, so the suitable biomes must be active at this y.