Compare commits
5 Commits
f7e468bc60
...
7395c5edcb
Author | SHA1 | Date |
---|---|---|
Wuzzy | 7395c5edcb | |
Wuzzy | 2bd52f3f33 | |
Wuzzy | 65e854b8ef | |
Wuzzy | 17927aaa11 | |
Wuzzy | a3653bdab1 |
|
@ -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)
|
||||
|
|
106
init.lua
106
init.lua
|
@ -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
|
||||
|
@ -117,38 +147,37 @@ local function find_biome(pos, biomes)
|
|||
local function search()
|
||||
local attempt = 1
|
||||
while attempt < 3 do
|
||||
for iter = 1, checks do
|
||||
local biome_data = minetest.get_biome_data(pos)
|
||||
-- Sometimes biome_data is nil
|
||||
local biome = biome_data and biome_data.biome
|
||||
for id_ind = 1, #biome_ids do
|
||||
local biome_id = biome_ids[id_ind]
|
||||
pos = adjust_pos_to_biome_limits(pos, biome_id)
|
||||
local spos = table.copy(pos)
|
||||
if biome == biome_id then
|
||||
local good_spawn_height = pos.y <= water_level + 16 and pos.y >= water_level
|
||||
local spawn_y = minetest.get_spawn_level(spos.x, spos.z)
|
||||
if spawn_y then
|
||||
spawn_pos = {x = spos.x, y = spawn_y, z = spos.z}
|
||||
elseif not good_spawn_height then
|
||||
spawn_pos = {x = spos.x, y = spos.y, z = spos.z}
|
||||
elseif attempt >= 2 then
|
||||
spawn_pos = {x = spos.x, y = spos.y, z = spos.z}
|
||||
end
|
||||
if spawn_pos then
|
||||
local adjusted_pos, outside = adjust_pos_to_biome_limits(spawn_pos, biome_id)
|
||||
if is_in_world(spawn_pos) and not outside then
|
||||
return true
|
||||
for iter = 1, checks do
|
||||
local biome_data = minetest.get_biome_data(pos)
|
||||
-- Sometimes biome_data is nil
|
||||
local biome = biome_data and biome_data.biome
|
||||
for id_ind = 1, #biome_ids do
|
||||
local biome_id = biome_ids[id_ind]
|
||||
pos = adjust_pos_to_biome_limits(pos, biome_id)
|
||||
local spos = table.copy(pos)
|
||||
if biome == biome_id then
|
||||
local good_spawn_height = pos.y <= water_level + 16 and pos.y >= water_level
|
||||
local spawn_y = minetest.get_spawn_level(spos.x, spos.z)
|
||||
if spawn_y then
|
||||
spawn_pos = {x = spos.x, y = spawn_y, z = spos.z}
|
||||
elseif not good_spawn_height then
|
||||
spawn_pos = {x = spos.x, y = spos.y, z = spos.z}
|
||||
elseif attempt >= 2 then
|
||||
spawn_pos = {x = spos.x, y = spos.y, z = spos.z}
|
||||
end
|
||||
if spawn_pos then
|
||||
local adjusted_pos, outside = adjust_pos_to_biome_limits(spawn_pos, biome_id)
|
||||
if is_in_world(spawn_pos) and not outside then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pos = next_pos()
|
||||
end
|
||||
|
||||
pos = next_pos()
|
||||
attempt = attempt + 1
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue