Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 23 additions & 73 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,10 @@ end)

local tperlin
local hperlin
local np_temp = nil
local np_humid = nil

-- noise vals for default mgv7
if mg == "v7" then
-- 2D noise for temperature
tperlin =0

-- 2D noise for humidity
hperlin =0
end

if minetest.get_modpath("skylands") or minetest.get_modpath("watershed") then
-- noise vals for watershed and skylands
-- 3D noise for temperature
np_temp = {
offset = 0,
scale = 1,
spread = {x=512, y=512, z=512},
seed = 9130,
octaves = 3,
persist = 0.5
}

-- 3D noise for humidity

np_humid = {
offset = 0,
scale = 1,
spread = {x=512, y=512, z=512},
seed = -55500,
octaves = 3,
persist = 0.5
}
if minetest.get_modpath("skylands") then
skyland = true
end
if minetest.get_modpath("watershed") then
wshed = true
end
end

--make it so that the engine knows it needs to switch between 2D and 3D noise depending on altitude
if mg == "v7" and skyland == true then
height_threshold =true
end

tempidity = {}
tempidity.hud = {}
local timer = 0

minetest.register_globalstep(function(dtime)
--something
local point = {x=1,y=1,z=1}
Expand All @@ -73,32 +27,10 @@ minetest.register_globalstep(function(dtime)
local name = player:get_player_name()

--actual display temp/humidity
local temperature = 0
local humidity = 0

--in order: if mgv7+skylands, or watershed, or NOT mgv7 (assume only skylands)
if (height_threshold and pos.y >= 700) or wshed or mg ~= "v7" then
--use 3D values
local nvals_temp = minetest.get_perlin_map(np_temp, point):get3dMap_flat(pos)
local nvals_humid = minetest.get_perlin_map(np_humid, point):get3dMap_flat(pos)
local temp = nvals_temp[1]
local humid = nvals_humid[1]

--set temperature and humidity
temperature = math.floor((temp * 20) * 100) / 100 -- in Celsius
humidity = math.floor((humid + 1.75)/3.5 * 100) / 100 --in %
--otherwise, if ONLY mgv7
elseif mg == "v7" then
--get 2d temperature
local tnoise = minetest.get_perlin(35293, 1, 0, 500):get2d({x=pos.x,y=pos.z})
temperature = math.floor((25 + tnoise * 50)*100) / 100 -- convert to Celsius

--get 2d humidity
local hnoise = minetest.get_perlin(12094, 2, 0.6, 750):get2d({x=pos.x,y=pos.z})
humidity = math.floor((50 + hnoise * 31.25)*100) / 100 --unit conversion
else --none of the above. skip calculations
break --nope.avi
end
local biome_data = minetest.get_biome_data(pos)
local biome_name = minetest.get_biome_name(biome_data.biome)
local temperature = biome_data.heat
local humidity = biome_data.humidity

--check if a HUD for the player is already set up
if not tempidity.hud[name] then
Expand Down Expand Up @@ -128,9 +60,22 @@ minetest.register_globalstep(function(dtime)
scale = {x=200, y=60},
alignment = {x=1, y=1},
})
--biome...
tempidity.hud[name].BiomeId = player:hud_add({
hud_elem_type = "text",
name = "Biome",
number = 0xFFFFFF,
position = {x=1, y=1},
offset = {x=-128, y=-40},
direction = 0,
text = biome_name,
scale = {x=200, y=60},
alignment = {x=1, y=1},
})
--store the values to potentially reduce calculations
tempidity.hud[name].oldTemp = temperature
tempidity.hud[name].oldHumid = humidity
tempidity.hud[name].oldBiome = biome_name
return
--HUD already exists
--see if temperature is the same here, if not, redraw
Expand All @@ -143,6 +88,11 @@ minetest.register_globalstep(function(dtime)
player:hud_change(tempidity.hud[name].HumidId, "text",
"Humidity: "..humidity)
tempidity.hud[name].oldHumid = humidity
--same for biome
elseif tempidity.hud[name].oldBiome ~= biome_name then
player:hud_change(tempidity.hud[name].BiomeId, "text",
biome_name)
tempidity.hud[name].oldBiome = biome_name
end
end
end)
Expand Down