Compare commits

...

5 Commits

Author SHA1 Message Date
Wuzzy 7395c5edcb Version 1.0.1 2019-09-29 11:56:24 +02:00
Wuzzy 2bd52f3f33 Add chatcommands on init time 2019-09-29 11:55:38 +02:00
Wuzzy 65e854b8ef Version 1.0.0 2019-08-27 20:19:16 +02:00
Wuzzy 17927aaa11 Add basic support for finding default biome 2019-08-27 20:18:41 +02:00
Wuzzy a3653bdab1 Indent code 2019-08-27 16:42:09 +02:00
2 changed files with 84 additions and 30 deletions

View File

@ -5,10 +5,14 @@ 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.
Version: 0.2.0
Version: 1.0.1
## Known limitations
- For exotic biomes restricted by height, this mod does not guarantee you will teleport to land
There's no guarantee you will always find the biome, even if it exists in the world.
This can happen if the biome is very obscure or small, but usually you should be
able to find the biome.
If the biome could not be found, just move to somewhere else and try again.
## Authors
- paramat (MIT License)

View File

@ -78,6 +78,36 @@ local function adjust_pos_to_biome_limits(pos, biome_id)
return bpos, out_of_bounds
end
-- Find the special default biome
local function find_default_biome()
local all_biomes = minetest.registered_biomes
local biome_count = 0
for b, biome in pairs(all_biomes) do
biome_count = biome_count + 1
end
-- Trivial case: No biomes registered, default biome is everywhere.
if biome_count == 0 then
local y = minetest.get_spawn_level(0, 0)
if not y then
y = 0
end
return { x = 0, y = y, z = 0 }
end
local pos = {}
-- Just check a lot of random positions
-- It's a crappy algorithm but better than nothing.
for i=1, 100 do
pos.x = math.random(-playable_limit, playable_limit)
pos.y = math.random(-playable_limit, playable_limit)
pos.z = math.random(-playable_limit, playable_limit)
local biome_data = minetest.get_biome_data(pos)
if biome_data and minetest.get_biome_name(biome_data.biome) == "default" then
return pos
end
end
return nil
end
local function find_biome(pos, biomes)
pos = vector.round(pos)
-- Pos: Starting point for biome checks. This also sets the y co-ordinate for all
@ -148,7 +178,6 @@ local function find_biome(pos, biomes)
end
attempt = attempt + 1
end
return false
end
local function search_v6()
@ -194,12 +223,21 @@ local function find_biome(pos, biomes)
end
local mods_loaded = false
minetest.register_on_mods_loaded(function()
mods_loaded = true
end)
-- Regiver chat commands
do
minetest.register_chatcommand("findbiome", {
description = S("Find and teleport to biome"),
params = S("<biome>"),
privs = { debug = true, teleport = true },
func = function(name, param)
if not mods_loaded then
return false
end
local player = minetest.get_player_by_name(name)
if not player then
return false, S("No player.")
@ -218,6 +256,15 @@ minetest.register_on_mods_loaded(function()
end
end
else
if param == "default" then
local biome_pos = find_default_biome()
if biome_pos then
player:set_pos(biome_pos)
return true, S("Biome found at @1.", minetest.pos_to_string(biome_pos))
else
return false, S("No biome found!")
end
end
local id = minetest.get_biome_id(param)
if id then
invalid_biome = false
@ -241,6 +288,9 @@ minetest.register_on_mods_loaded(function()
params = "",
privs = { debug = true },
func = function(name, param)
if not mods_loaded then
return false
end
local biomes
local b = 0
if mg_name == "v6" then
@ -267,4 +317,4 @@ minetest.register_on_mods_loaded(function()
end
end,
})
end)
end