Initial v6 mapgen support using biomeinfo.
parent
12644592af
commit
7228237e9f
42
init.lua
42
init.lua
|
@ -2,16 +2,23 @@
|
|||
-- Adds HUD display of current mapgen biome information.
|
||||
--
|
||||
-- by David G (kestral246@gmail.com)
|
||||
-- 2019-12-06
|
||||
-- 2020-01-01
|
||||
--
|
||||
-- Add chat command /biomes
|
||||
-- Add support for v6 using Wuzzy's biomeinfo mod
|
||||
|
||||
display_biome = {}
|
||||
local storage = minetest.get_mod_storage()
|
||||
|
||||
-- Optional V6 Support
|
||||
local is_v6 = minetest.get_mapgen_setting("mg_name") == "v6" and minetest.get_modpath("biomeinfo") ~= nil
|
||||
|
||||
-- Configuration option
|
||||
local start_enabled = minetest.settings:get_bool("display_biome_enabled", false)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
if storage:get(pname) and storage:get(pname) == "1" then -- enabled
|
||||
if (storage:get(pname) and storage:get(pname) == "1") or start_enabled then -- enabled
|
||||
display_biome[pname] = {
|
||||
last_ippos = {x=0,y=0,z=0},
|
||||
id = player:hud_add({
|
||||
|
@ -66,31 +73,34 @@ minetest.register_globalstep(function(dtime)
|
|||
if timer < 0.5 then
|
||||
return
|
||||
end
|
||||
|
||||
timer = 0
|
||||
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
if display_biome[pname].enable == true then
|
||||
local ppos = player:get_pos()
|
||||
local ippos = {x=math.floor(ppos.x),y=math.floor(ppos.y),z=math.floor(ppos.z)} -- integer position
|
||||
local bpos = {x=ippos.x,y=ippos.y,z=ippos.z} -- surface position at which to calculate biome
|
||||
|
||||
if not (ippos.x == display_biome[pname].last_ippos.x and ippos.y == display_biome[pname].last_ippos.y and ippos.z == display_biome[pname].last_ippos.z) then -- position changed
|
||||
local ippos = vector.round(player:get_pos()) -- integer position
|
||||
local bpos = vector.new(ippos) -- surface position at which to calculate biome
|
||||
|
||||
if not vector.equals(ippos, display_biome[pname].last_ippos) then -- position changed
|
||||
-- simple search for ground elevation
|
||||
while bpos.y > 0 and minetest.get_node(bpos).name == "air" do
|
||||
bpos.y = bpos.y - 1
|
||||
end
|
||||
|
||||
if minetest.get_biome_data(bpos) and minetest.get_biome_data(bpos).biome then
|
||||
|
||||
local heat, humidity, name
|
||||
if is_v6 then
|
||||
heat = math.floor(biomeinfo.get_v6_heat(bpos) * 100 + 0.5)/100
|
||||
humidity = math.floor(biomeinfo.get_v6_humidity(bpos) * 100 + 0.5)/100
|
||||
name = biomeinfo.get_v6_biome(bpos)
|
||||
else
|
||||
local bdata = minetest.get_biome_data(bpos)
|
||||
|
||||
player:hud_change(display_biome[pname].id, "text",
|
||||
'temp = '..math.floor(bdata.heat + 0.5)..
|
||||
', humid = '..math.floor(bdata.humidity + 0.5)..
|
||||
', '..minetest.get_biome_name(bdata.biome))
|
||||
display_biome[pname].last_ippos = {x=ippos.x,y=ippos.y,z=ippos.z} -- update last player position
|
||||
heat = math.floor(bdata.heat + 0.5)
|
||||
humidity = math.floor(bdata.humidity + 0.5)
|
||||
name = minetest.get_biome_name(bdata.biome)
|
||||
end
|
||||
player:hud_change(display_biome[pname].id, "text",
|
||||
'temp = '..heat..', humid = '..humidity..', '..name)
|
||||
display_biome[pname].last_ippos = vector.new(ippos) -- update last player position
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
1
mod.conf
1
mod.conf
|
@ -1,2 +1,3 @@
|
|||
name = display_biome
|
||||
description = Display HUD with local temperature, humidity, and biome name.
|
||||
optional_depends = biomeinfo
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# This file contains settings of display_biome that can be changed in
|
||||
# minetest.conf
|
||||
|
||||
# Define default start-up state of display_biome.
|
||||
# (default = false)
|
||||
display_biome_enabled (Default start-up state) bool false
|
Loading…
Reference in New Issue