Add support for v6 mapgen

master
Wuzzy 2019-08-26 21:03:31 +02:00
parent 30c78c1004
commit 68543e38e3
3 changed files with 66 additions and 35 deletions

View File

@ -8,7 +8,6 @@ and another command (“listbiomes”) to list biomes.
Version: 0.1.0 Version: 0.1.0
## Known bugs and limitations ## Known bugs and limitations
- v6 mapgen is not supported.
- Will only search for biomes in the same height as you. - Will only search for biomes in the same height as you.
- Might teleport you outside the map boundaries if you're close to one. - Might teleport you outside the map boundaries if you're close to one.

View File

@ -1,8 +1,5 @@
local S = minetest.get_translator("findbiome") local S = minetest.get_translator("findbiome")
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
if mg_name == "v6" then
minetest.log("info", "[findbiome] This mod doesn't work in mapgen v6!")
end
-- Parameters -- Parameters
------------- -------------
@ -29,16 +26,6 @@ function find_biome(pos, biomes)
-- Pos: Starting point for biome checks. This also sets the y co-ordinate for all -- 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. -- points checked, so the suitable biomes must be active at this y.
-- Table of suitable biomes
local biome_ids = {}
for i=1, #biomes do
local id = minetest.get_biome_id(biomes[i])
if not id then
return nil, false
end
table.insert(biome_ids, id)
end
-- Initial variables -- Initial variables
local edge_len = 1 local edge_len = 1
@ -92,8 +79,44 @@ function find_biome(pos, biomes)
return false return false
end end
local function search_v6()
for iter = 1, checks do
local found_biome = biomeinfo.get_v6_biome(pos)
for i = 1, #biomes do
local searched_biome = biomes[i]
minetest.log("pos="..minetest.pos_to_string(pos))
minetest.log("biome_f="..tostring(found_biome))
minetest.log("biome_s="..tostring(searched_biome))
if found_biome == searched_biome then
local spawn_y = minetest.get_spawn_level(pos.x, pos.z)
if spawn_y then
spawn_pos = {x = pos.x, y = spawn_y, z = pos.z}
-- FIXME: Don't return true when spawn_pos is out of map bounds
return true
end
end
end
success = search() pos = next_pos()
end
return false
end
if mg_name == "v6" then
success = search_v6()
else
-- Table of suitable biomes
local biome_ids = {}
for i=1, #biomes do
local id = minetest.get_biome_id(biomes[i])
if not id then
return nil, false
end
table.insert(biome_ids, id)
end
success = search()
end
return spawn_pos, success return spawn_pos, success
end end
@ -109,24 +132,30 @@ minetest.register_on_mods_loaded(function()
return false, S("No player.") return false, S("No player.")
end end
local pos = player:get_pos() local pos = player:get_pos()
local id = minetest.get_biome_id(param) local invalid_biome = true
if not id then if mg_name == "v6" then
if mg_name == "v6" then local biomes = biomeinfo.get_active_v6_biomes()
return false, S("No biome found! Sorry, finding biomes of the v6 mapgen is not supported!") for b=1, #biomes do
else if param == biomes[b] then
return false, S("Biome does not exist!") invalid_biome = false
break
end
end end
else
local id = minetest.get_biome_id(param)
if id then
invalid_biome = false
end
end
if invalid_biome then
return false, S("Biome does not exist!")
end end
local biome_pos, success = find_biome(pos, {param}) local biome_pos, success = find_biome(pos, {param})
if success then if success then
player:set_pos(biome_pos) player:set_pos(biome_pos)
return true, S("Biome found at @1.", minetest.pos_to_string(biome_pos)) return true, S("Biome found at @1.", minetest.pos_to_string(biome_pos))
else else
if mg_name == "v6" then return false, S("No biome found!")
return false, S("No biome found! Sorry, finding biomes of the v6 mapgen is not supported!")
else
return false, S("No biome found!")
end
end end
end, end,
}) })
@ -136,18 +165,20 @@ minetest.register_on_mods_loaded(function()
params = "", params = "",
privs = { debug = true }, privs = { debug = true },
func = function(name, param) func = function(name, param)
local biomes = {} local biomes
local b = 0 local b = 0
for k,v in pairs(minetest.registered_biomes) do if mg_name == "v6" then
table.insert(biomes, k) biomes = biomeinfo.get_active_v6_biomes()
b = b + 1 b = #biomes
else
biomes = {}
for k,v in pairs(minetest.registered_biomes) do
table.insert(biomes, k)
b = b + 1
end
end end
if b == 0 then if b == 0 then
if mg_name == "v6" then return true, S("No biomes.")
return false, S("This command can't find biomes of the v6 mapgen!")
else
return true, S("No biomes.")
end
else else
table.sort(biomes) table.sort(biomes)
for b=1, #biomes do for b=1, #biomes do

View File

@ -1,2 +1,3 @@
name=findbiome name=findbiome
description=Add commands to list and find biomes description=Add commands to list and find biomes
depends=biomeinfo