climate_api support - add distance fog

Add more appropriate/atmosphere distance fog to the nether, via climate_api mod to avoid conflicting with other mods.
Any game or server with climate_api mod installed will be expecting climate_api to take control of sky values.
This commit is contained in:
Treer 2021-02-02 19:15:51 +11:00
parent 00099f2aa2
commit 3008b167b2
5 changed files with 174 additions and 42 deletions

View File

@ -6,3 +6,4 @@ fire?
loot? loot?
mesecons? mesecons?
moreblocks? moreblocks?
climate_api?

View File

@ -42,12 +42,18 @@ end
-- Global Nether namespace -- Global Nether namespace
nether = {} nether = {}
nether.mapgen = {} -- Shared Nether mapgen namespace, for mapgen files to expose functions and constants
nether.modname = minetest.get_current_modname() nether.modname = minetest.get_current_modname()
nether.path = minetest.get_modpath(nether.modname) nether.path = minetest.get_modpath(nether.modname)
nether.get_translator = S nether.get_translator = S
-- nether.useBiomes allows other mods to know whether they can register ores etc. in the Nether. -- nether.useBiomes allows other mods to know whether they can register ores etc. in the Nether.
-- See mapgen.lua for an explanation of why minetest.read_schematic is being checked -- See mapgen.lua for an explanation of why minetest.read_schematic is being checked
nether.useBiomes = minetest.get_mapgen_setting("mg_name") ~= "v6" and minetest.read_schematic ~= nil nether.useBiomes = minetest.get_mapgen_setting("mg_name") ~= "v6" and minetest.read_schematic ~= nil
nether.fogColor = { -- only used if climate_api is installed
netherCaverns = "#1D0504", -- Distance-fog colour for classic nether
mantle = "#070916", -- Distance-fog colour for the Mantle region
geodes = "#300530" -- Distance-fog colour for secondary region
}
-- Settings -- Settings
@ -227,7 +233,89 @@ The expedition parties have found no diamonds or gold, and after an experienced
end end
}) })
end
-- Set appropriate nether distance-fog if climate_api is available
--
-- Delegating to a mod like climate_api means nether won't unexpectedly stomp on the sky of
-- any other mod.
-- Skylayer is another mod which can perform this role, and skylayer support could be added
-- here as well. However skylayer doesn't provide a position-based method of specifying sky
-- colours out-of-the-box, so the nether mod will have to monitor when players enter and
-- leave the nether.
if minetest.get_modpath("climate_api") and minetest.global_exists("climate_api") and climate_api.register_weather ~= nil then
climate_api.register_influence(
"nether_biome",
function(pos)
local result = "surface"
if pos.y <= nether.DEPTH_CEILING and pos.y >= nether.DEPTH_FLOOR then
result = "nether"
if nether.mapgen.getRegion ~= nil then
-- the biomes-based mapgen supports 2 extra regions
local regions = nether.mapgen.RegionEnum
local region = nether.mapgen.getRegion(pos)
if region == regions.Center or region == regions.CenterShell then
result = "mantle"
elseif region == regions.Negative or region == regions.NegativeShell then
result = "geode"
end
end
end
return result
end
)
-- using sky type "plain" unfortunately means we don't get smooth fading transitions when
-- the color of the sky changes, but it seems to be the only way to obtain a sky colour
-- which doesn't brighten during the daytime.
local undergroundSky = {
sky_data = {
base_color = nil,
type = "plain",
textures = nil,
clouds = false,
},
sun_data = {
visible = false,
sunrise_visible = false
},
moon_data = {
visible = false
},
star_data = {
visible = false
}
}
local netherSky, mantleSky, geodeSky = table.copy(undergroundSky), table.copy(undergroundSky), table.copy(undergroundSky)
netherSky.sky_data.base_color = nether.fogColor.netherCaverns
mantleSky.sky_data.base_color = nether.fogColor.mantle
geodeSky.sky_data.base_color = nether.fogColor.geodes
climate_api.register_weather(
"nether:nether",
{ nether_biome = "nether" },
{ ["climate_api:skybox"] = netherSky }
)
climate_api.register_weather(
"nether:mantle",
{ nether_biome = "mantle" },
{ ["climate_api:skybox"] = mantleSky }
)
climate_api.register_weather(
"nether:geode",
{ nether_biome = "geode" },
{ ["climate_api:skybox"] = geodeSky }
)
end
end -- end of "if nether.NETHER_REALM_ENABLED..."
-- Play bubbling lava sounds if player killed by lava -- Play bubbling lava sounds if player killed by lava

View File

@ -45,7 +45,6 @@ local BASALT_COLUMN_LOWER_LIMIT = CENTER_CAVERN_LIMIT * 0.25 -- This value
-- Shared Nether mapgen namespace -- Shared Nether mapgen namespace
-- For mapgen files to share functions and constants -- For mapgen files to share functions and constants
nether.mapgen = {}
local mapgen = nether.mapgen local mapgen = nether.mapgen
mapgen.TCAVE = TCAVE -- const needed in mapgen_mantle.lua mapgen.TCAVE = TCAVE -- const needed in mapgen_mantle.lua
@ -257,6 +256,19 @@ mapgen.np_cave = {
--flags = "" --flags = ""
} }
local cavePointPerlin = nil
mapgen.getCavePointPerlin = function()
cavePointPerlin = cavePointPerlin or minetest.get_perlin(mapgen.np_cave)
return cavePointPerlin
end
mapgen.getCavePerlinAt = function(pos)
cavePointPerlin = cavePointPerlin or minetest.get_perlin(mapgen.np_cave)
return cavePointPerlin:get3d(pos)
end
-- Buffers and objects we shouldn't recreate every on_generate -- Buffers and objects we shouldn't recreate every on_generate
local nobj_cave = nil local nobj_cave = nil
@ -658,7 +670,7 @@ end
-- use knowledge of the nether mapgen algorithm to return a suitable ground level for placing a portal. -- use knowledge of the nether mapgen algorithm to return a suitable ground level for placing a portal.
-- player_name is optional, allowing a player to spawn a remote portal in their own protected areas. -- player_name is optional, allowing a player to spawn a remote portal in their own protected areas.
function nether.find_nether_ground_y(target_x, target_z, start_y, player_name) function nether.find_nether_ground_y(target_x, target_z, start_y, player_name)
local nobj_cave_point = minetest.get_perlin(mapgen.np_cave) local nobj_cave_point = mapgen.getCavePointPerlin()
local air = 0 -- Consecutive air nodes found local air = 0 -- Consecutive air nodes found
local minp_schem, maxp_schem = nether.get_schematic_volume({x = target_x, y = 0, z = target_z}, nil, "nether_portal") local minp_schem, maxp_schem = nether.get_schematic_volume({x = target_x, y = 0, z = target_z}, nil, "nether_portal")

View File

@ -49,7 +49,6 @@ local np_basalt = {
local nobj_basalt = nil local nobj_basalt = nil
local nbuf_basalt = {} local nbuf_basalt = {}
local cavePerlin = nil
-- Content ids -- Content ids
@ -414,52 +413,84 @@ mapgen.excavate_tunnel_to_center_of_the_nether = function(data, area, nvals_cave
end end
-- an enumerated list of the different regions in the nether
mapgen.RegionEnum = {
Overworld = "overworld", -- Outside the Nether / none of the regions in the Nether
Positive = "positive", -- The classic nether caverns are here - where cavePerlin > 0.6
PositiveShell = "positive shell", -- the nether side of the wall/buffer area separating classic nether from the mantle
Center = "center", -- The Mantle caverns are here
CenterShell = "center shell", -- the mantle side of the wall/buffer area separating the positive and negative regions from the center region
Negative = "negative", -- Secondary/spare region - where cavePerlin < -0.6
NegativeShell = "negative shell", -- the spare region side of the wall/buffer area separating the negative region from the mantle
}
-- Returns (region, noise) where region is a value from mapgen.RegionEnum
-- and noise is the unadjusted cave perlin value
mapgen.getRegion = function(pos)
if pos.y > nether.DEPTH_CEILING or pos.y < nether.DEPTH_FLOOR then
return mapgen.RegionEnum.Overworld, nil
end
local caveNoise = mapgen.getCavePerlinAt(pos)
local sea_level, cavern_limit_distance = mapgen.find_nearest_lava_sealevel(pos.y)
local tcave_adj, centerRegionLimit_adj = mapgen.get_mapgenblend_adjustments(pos.y)
local tcave = mapgen.TCAVE + tcave_adj
local tmantle = mapgen.CENTER_REGION_LIMIT + centerRegionLimit_adj
local cavern_noise_adj =
mapgen.CENTER_REGION_LIMIT * (cavern_limit_distance * cavern_limit_distance * cavern_limit_distance) -
centerRegionLimit_adj -- cavern_noise_adj gets added to noise value instead of added to the limit np_noise is compared against, so subtract centerRegionLimit_adj so subtract centerRegionLimit_adj instead of adding
local region
if caveNoise > tcave then
region = mapgen.RegionEnum.Positive
elseif -caveNoise > tcave then
region = mapgen.RegionEnum.Negative
elseif math_abs(caveNoise) < tmantle then
if math_abs(caveNoise) + cavern_noise_adj < mapgen.CENTER_CAVERN_LIMIT then
region = mapgen.RegionEnum.Center
else
region = mapgen.RegionEnum.CenterShell
end
elseif caveNoise > 0 then
region = mapgen.RegionEnum.PositiveShell
else
region = mapgen.RegionEnum.NegativeShell
end
return region, caveNoise
end
minetest.register_chatcommand("nether_whereami", minetest.register_chatcommand("nether_whereami",
{ {
description = "Describes which region of the nether the player is in", description = "Describes which region of the nether the player is in",
privs = {debug = true}, privs = {debug = true},
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if player == nil then return false, "Unknown player position" end if player == nil then return false, "Unknown player position" end
local playerPos = vector.round(player:get_pos())
local pos = vector.round(player:get_pos()) local region, caveNoise = mapgen.getRegion(playerPos)
if pos.y > nether.DEPTH_CEILING or pos.y < nether.DEPTH_FLOOR then local seaLevel, cavernLimitDistance = mapgen.find_nearest_lava_sealevel(playerPos.y)
return true, "The Overworld" local tcave_adj, centerRegionLimit_adj = mapgen.get_mapgenblend_adjustments(playerPos.y)
end
cavePerlin = cavePerlin or minetest.get_perlin(mapgen.np_cave) local regionLabels = {
local densityNoise = cavePerlin:get_3d(pos) [mapgen.RegionEnum.Overworld] = "The Overworld",
local sea_level, cavern_limit_distance = mapgen.find_nearest_lava_sealevel(pos.y) [mapgen.RegionEnum.Positive] = "Positive nether",
local tcave_adj, centerRegionLimit_adj = mapgen.get_mapgenblend_adjustments(pos.y) [mapgen.RegionEnum.PositiveShell] = "Shell between positive nether and center region",
local tcave = mapgen.TCAVE + tcave_adj [mapgen.RegionEnum.Center] = "Center/Mantle, inside cavern",
local tmantle = mapgen.CENTER_REGION_LIMIT + centerRegionLimit_adj [mapgen.RegionEnum.CenterShell] = "Center/Mantle, but outside the caverns",
local cavern_noise_adj = [mapgen.RegionEnum.Negative] = "Negative nether",
mapgen.CENTER_REGION_LIMIT * (cavern_limit_distance * cavern_limit_distance * cavern_limit_distance) - [mapgen.RegionEnum.NegativeShell] = "Shell between negative nether and center region"
centerRegionLimit_adj -- cavern_noise_adj gets added to noise value instead of added to the limit np_noise is compared against, so subtract centerRegionLimit_adj so subtract centerRegionLimit_adj instead of adding }
local desc = regionLabels[region]
local desc local sea_pos = playerPos.y - seaLevel
if densityNoise > tcave then
desc = "Positive nether"
elseif -densityNoise > tcave then
desc = "Negative nether"
elseif math_abs(densityNoise) < tmantle then
desc = "Mantle"
if math_abs(densityNoise) + cavern_noise_adj < mapgen.CENTER_CAVERN_LIMIT then
desc = desc .. " inside cavern"
else
desc = desc .. " but outside cavern"
end
elseif densityNoise > 0 then
desc = "Shell between positive nether and center region"
else
desc = "Shell between negative nether and center region"
end
local sea_pos = pos.y - sea_level
if sea_pos > 0 then if sea_pos > 0 then
desc = desc .. ", " .. sea_pos .. "m above lava-sea level" desc = desc .. ", " .. sea_pos .. "m above lava-sea level"
else else
@ -470,7 +501,7 @@ minetest.register_chatcommand("nether_whereami",
desc = desc .. ", approaching y boundary of Nether" desc = desc .. ", approaching y boundary of Nether"
end end
return true, "[Perlin " .. (math_floor(densityNoise * 1000) / 1000) .. "] " .. desc return true, "[Perlin " .. (math_floor(caveNoise * 1000) / 1000) .. "] " .. desc
end end
} }
) )

View File

@ -1,4 +1,4 @@
name = nether name = nether
description = Adds a deep underground realm with different mapgen that you can reach with obsidian portals. description = Adds a deep underground realm with different mapgen that you can reach with obsidian portals.
depends = stairs, default depends = stairs, default
optional_depends = moreblocks, mesecons, loot, dungeon_loot, doc_basics, fire optional_depends = moreblocks, mesecons, loot, dungeon_loot, doc_basics, fire, climate_api