mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-25 20:11:06 +01:00
Fix night vision conflicting with weather skycolor
This commit is contained in:
parent
ff24052e7f
commit
b2ad6b79bd
3 changed files with 32 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
local mods_loaded = false
|
||||
local NIGHT_VISION_RATIO = 0.45
|
||||
|
||||
mcl_weather.skycolor = {
|
||||
-- Should be activated before do any effect.
|
||||
|
@ -51,6 +52,23 @@ mcl_weather.skycolor = {
|
|||
end
|
||||
end,
|
||||
|
||||
-- Wrapper for updating day/night ratio that respects night vision
|
||||
override_day_night_ratio = function(player, ratio)
|
||||
local meta = player:get_meta()
|
||||
local night_vision = meta:get_int("night_vision")
|
||||
local arg
|
||||
if night_vision == 1 then
|
||||
if ratio == nil then
|
||||
arg = NIGHT_VISION_RATIO
|
||||
else
|
||||
arg = math.max(ratio, NIGHT_VISION_RATIO)
|
||||
end
|
||||
else
|
||||
arg = ratio
|
||||
end
|
||||
player:override_day_night_ratio(arg)
|
||||
end,
|
||||
|
||||
-- Update sky color. If players not specified update sky for all players.
|
||||
update_sky_color = function(players)
|
||||
-- Override day/night ratio as well
|
||||
|
@ -76,7 +94,7 @@ mcl_weather.skycolor = {
|
|||
player:set_sun({visible = true, sunrise_visible = true})
|
||||
player:set_moon({visible = true})
|
||||
player:set_stars({visible = true})
|
||||
player:override_day_night_ratio(nil)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, nil)
|
||||
else
|
||||
-- Weather skies
|
||||
local day_color = mcl_weather.skycolor.get_sky_layer_color(0.5)
|
||||
|
@ -99,7 +117,7 @@ mcl_weather.skycolor = {
|
|||
|
||||
local lf = mcl_weather.get_current_light_factor()
|
||||
if mcl_weather.skycolor.current_layer_name() == "lightning" then
|
||||
player:override_day_night_ratio(1)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, 1)
|
||||
elseif lf then
|
||||
local w = minetest.get_timeofday()
|
||||
local light = (w * (lf*2))
|
||||
|
@ -107,9 +125,9 @@ mcl_weather.skycolor = {
|
|||
light = 1 - (light - 1)
|
||||
end
|
||||
light = (light * lf) + 0.15
|
||||
player:override_day_night_ratio(light)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, light)
|
||||
else
|
||||
player:override_day_night_ratio(nil)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, nil)
|
||||
end
|
||||
end
|
||||
elseif dim == "end" then
|
||||
|
@ -122,7 +140,7 @@ mcl_weather.skycolor = {
|
|||
player:set_sun({visible = false , sunrise_visible = false})
|
||||
player:set_moon({visible = false})
|
||||
player:set_stars({visible = false})
|
||||
player:override_day_night_ratio(0.5)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, 0.5)
|
||||
elseif dim == "nether" then
|
||||
player:set_sky({ type = "plain",
|
||||
base_color = "#300808",
|
||||
|
@ -131,7 +149,7 @@ mcl_weather.skycolor = {
|
|||
player:set_sun({visible = false , sunrise_visible = false})
|
||||
player:set_moon({visible = false})
|
||||
player:set_stars({visible = false})
|
||||
player:override_day_night_ratio(nil)
|
||||
mcl_weather.skycolor.override_day_night_ratio(player, nil)
|
||||
elseif dim == "void" then
|
||||
player:set_sky({ type = "plain",
|
||||
base_color = "#000000",
|
||||
|
|
|
@ -211,16 +211,14 @@ minetest.register_globalstep(function(dtime)
|
|||
is_cat[player].timer = is_cat[player].timer + dtime
|
||||
|
||||
if player:get_pos() then mcl_potions._add_spawner(player, "#1010AA") end
|
||||
if minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 then
|
||||
player:override_day_night_ratio(0.45)
|
||||
else player:override_day_night_ratio(nil)
|
||||
end
|
||||
|
||||
if is_cat[player].timer >= is_cat[player].dur then
|
||||
is_cat[player] = nil
|
||||
meta = player:get_meta()
|
||||
meta:set_string("_is_cat", minetest.serialize(is_cat[player]))
|
||||
meta:set_int("night_vision", 0)
|
||||
end
|
||||
mcl_weather.skycolor.update_sky_color({player})
|
||||
|
||||
else
|
||||
is_cat[player] = nil
|
||||
|
@ -366,7 +364,8 @@ function mcl_potions._reset_player_effects(player)
|
|||
playerphysics.remove_physics_factor(player, "speed", "mcl_potions:swiftness")
|
||||
|
||||
is_cat[player] = nil
|
||||
player:override_day_night_ratio(nil)
|
||||
meta:set_int("night_vision", 0)
|
||||
mcl_weather.skycolor.update_sky_color({player})
|
||||
|
||||
is_fire_proof[player] = nil
|
||||
|
||||
|
@ -826,6 +825,7 @@ end
|
|||
|
||||
function mcl_potions.night_vision_func(player, null, duration)
|
||||
|
||||
meta = player:get_meta()
|
||||
if not is_cat[player] then
|
||||
|
||||
is_cat[player] = {dur = duration, timer = 0}
|
||||
|
@ -838,6 +838,8 @@ function mcl_potions.night_vision_func(player, null, duration)
|
|||
victim.timer = 0
|
||||
|
||||
end
|
||||
meta:set_int("night_vision", 1)
|
||||
mcl_weather.skycolor.update_sky_color({player})
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
name = mcl_potions
|
||||
depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, playerphysics
|
||||
depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics
|
||||
|
|
Loading…
Reference in a new issue