Compare commits
10 Commits
26db2a0623
...
26fa0c59a2
Author | SHA1 | Date | |
---|---|---|---|
|
26fa0c59a2 | ||
|
811fa9ffbe | ||
|
6f52aa551c | ||
|
05dc9e0185 | ||
|
1b815adffc | ||
|
eac9e8af82 | ||
|
1c4ee70ef5 | ||
|
5c424199ff | ||
|
4114c51c2e | ||
|
7dfd9aec62 |
37
API.md
37
API.md
@ -1,8 +1,8 @@
|
||||
# Find Biome API
|
||||
|
||||
This mod has a single public function:
|
||||
This mod has two public functions:
|
||||
|
||||
## `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,40 @@ 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
|
||||
|
||||
## `findbiome.list_biomes()`
|
||||
|
||||
Lists all registered biomes in the world.
|
||||
|
||||
### Parameters
|
||||
|
||||
None.
|
||||
|
||||
### Return value
|
||||
|
||||
Returns `<biomes>, <success>`.
|
||||
|
||||
* `<success>` is `true` on success and `false` on failure.
|
||||
* `<biomes>` is a table.
|
||||
* If there are no errors, it will be a list of all registered biomes, in alphabetical order.
|
||||
* Possible errors: (the message will be the first table value)
|
||||
* If no biomes are found, it will be `"No biomes."` and `true`.
|
||||
* If `v6` mapgen is used and `biomeinfo` is not enabled, it will be
|
||||
`"Not supported. The “biomeinfo” mod is required for v6 mapgen support!"` and `false`.
|
||||
* If not all mods have loaded into the world yet, it will be `"Wait until all mods have loaded!"` and `false`.
|
||||
|
||||
### Additional notes
|
||||
|
||||
* If the mapgen `v6` is used, this function only works if the mod `biomeinfo` is
|
||||
active, too. See the `biomeinfo` mod for more information.
|
||||
* The error messages are always sent in English so the API user can check for them. It is possible to then use a translator on the returned value before showing it to the player, if that is what is wanted. See how errors are handled by the chat command.
|
||||
* It is better to just check the success value, unless the error message may interfere with other functions.
|
@ -2,10 +2,10 @@
|
||||
|
||||
## Description
|
||||
This is a mod to help with mod/game development for Minetest.
|
||||
It adds a command (“findbiome”) to find a biome nearby and teleport you to it
|
||||
and another command (“listbiomes”) to list biomes.
|
||||
It adds a command (“findbiome”) to find a biome nearby and teleport you to it,
|
||||
and another command (“listbiomes”) to list all biomes.
|
||||
|
||||
Version: 1.0.2
|
||||
Version: 1.1.1
|
||||
|
||||
## Known limitations
|
||||
There's no guarantee you will always find the biome, even if it exists in the world.
|
||||
@ -16,12 +16,13 @@ If the biome could not be found, just move to somewhere else and try again.
|
||||
|
||||
## Modding info
|
||||
|
||||
For modders, this mod offers a single function to search biomes via code.
|
||||
For modders, this mod offers two functions to search or list biomes via code, similar to the chat commands.
|
||||
See `API.md` for details.
|
||||
|
||||
## Authors
|
||||
- paramat (MIT License)
|
||||
- Wuzzy (MIT License)
|
||||
- Skivling (MIT License, `list_biomes()` function)
|
||||
|
||||
This mod is free software. See `license.txt` for license information.
|
||||
|
||||
|
76
init.lua
76
init.lua
@ -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_RESOLUTION
|
||||
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.
|
||||
@ -243,7 +250,37 @@ minetest.register_on_mods_loaded(function()
|
||||
mods_loaded = true
|
||||
end)
|
||||
|
||||
-- Regiver chat commands
|
||||
function findbiome.list_biomes(param)
|
||||
local biomes = {}
|
||||
local b = 0
|
||||
if not mods_loaded then
|
||||
table.insert(biomes, "Wait until all mods have loaded!")
|
||||
return biomes, false
|
||||
end
|
||||
if mg_name == "v6" then
|
||||
if not mod_biomeinfo then
|
||||
table.insert(biomes, "Not supported. The “biomeinfo” mod is required for v6 mapgen support!")
|
||||
return biomes, false
|
||||
end
|
||||
biomes = biomeinfo.get_active_v6_biomes()
|
||||
b = #biomes
|
||||
else
|
||||
biomes = {}
|
||||
for k,v in pairs(minetest.registered_biomes) do
|
||||
table.insert(biomes, k)
|
||||
b = b + 1
|
||||
end
|
||||
end
|
||||
if b == 0 then
|
||||
table.insert(biomes, "No biomes.")
|
||||
return biomes, true
|
||||
else
|
||||
table.sort(biomes)
|
||||
return biomes, true
|
||||
end
|
||||
end
|
||||
|
||||
-- Register chat commands
|
||||
do
|
||||
minetest.register_chatcommand("findbiome", {
|
||||
description = S("Find and teleport to biome"),
|
||||
@ -303,27 +340,12 @@ do
|
||||
params = "",
|
||||
privs = { debug = true },
|
||||
func = function(name, param)
|
||||
if not mods_loaded then
|
||||
local biomes = findbiome.list_biomes()
|
||||
-- Error checking before sending them in chat
|
||||
if not biomes then -- send error message
|
||||
minetest.chat_send_player(name, S(biomes[1]))
|
||||
return false
|
||||
end
|
||||
local biomes
|
||||
local b = 0
|
||||
if mg_name == "v6" then
|
||||
if not mod_biomeinfo then
|
||||
return false, S("Not supported. The “biomeinfo” mod is required for v6 mapgen support!")
|
||||
end
|
||||
biomes = biomeinfo.get_active_v6_biomes()
|
||||
b = #biomes
|
||||
else
|
||||
biomes = {}
|
||||
for k,v in pairs(minetest.registered_biomes) do
|
||||
table.insert(biomes, k)
|
||||
b = b + 1
|
||||
end
|
||||
end
|
||||
if b == 0 then
|
||||
return true, S("No biomes.")
|
||||
else
|
||||
else -- it worked, send all biomes or error message if no biomes were found
|
||||
table.sort(biomes)
|
||||
for b=1, #biomes do
|
||||
minetest.chat_send_player(name, biomes[b])
|
||||
@ -332,4 +354,4 @@ do
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user