From 8d4f1575f18c832571f9ca77e0dd418833a84ee7 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Mon, 22 Jan 2024 04:45:19 +0100 Subject: [PATCH] Added darkness --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 27 +++++++------ mods/ITEMS/mcl_potions/functions.lua | 46 +++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 6d9efd47a..edadbbeb8 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -120,20 +120,25 @@ mcl_weather.skycolor = { override_day_night_ratio = function(player, ratio) local meta = player:get_meta() local has_night_vision = meta:get_int("night_vision") == 1 + local has_darkness = meta:get_int("darkness") == 1 local is_visited_shepherd = meta:get_int("mcl_shepherd:special") == 1 local arg - -- Apply night vision only for dark sky - local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none" - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then - if ratio == nil then - arg = NIGHT_VISION_RATIO - else - arg = math.max(ratio, NIGHT_VISION_RATIO) - end + if has_darkness and not is_visited_shepherd then + arg = 0 else - arg = ratio + -- Apply night vision only for dark sky + local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none" + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then + if ratio == nil then + arg = NIGHT_VISION_RATIO + else + arg = math.max(ratio, NIGHT_VISION_RATIO) + end + else + arg = ratio + end end player:override_day_night_ratio(arg) end, diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index afbbc2128..6a1d14a5f 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -406,6 +406,52 @@ mcl_potions.register_effect({ uses_factor = false, }) +mcl_potions.register_effect({ + name = "darkness", + description = S("Darkness"), + get_tt = function(factor) + return S("surrounded by darkness") + end, + res_condition = function(object) + return (not object:is_player()) + end, + on_start = function(object, factor) + object:get_meta():set_int("darkness", 1) + mcl_weather.skycolor.update_sky_color({object}) + object:set_sky({fog = { + fog_distance = 10, + }}) + EF.darkness[object].flash = 0.6 + end, + on_step = function(dtime, object, factor, duration) + if object:get_meta():get_int("night_vision") ~= 1 then + local flash = EF.darkness[object].flash + if flash < 0.1 then EF.darkness[object].flashdir = true + elseif flash > 0.6 then EF.darkness[object].flashdir = false end + flash = EF.darkness[object].flashdir and (flash + dtime) or (flash - dtime) + object:set_sky({fog = { + fog_start = flash, + }}) + EF.darkness[object].flash = flash + else + object:set_sky({fog = { + fog_start = 0.99, + }}) + end + mcl_weather.skycolor.update_sky_color({object}) + end, + on_end = function(object) + object:get_meta():set_int("darkness", 0) + mcl_weather.skycolor.update_sky_color({object}) + object:set_sky({fog = { + fog_distance = -1, + fog_start = -1, + }}) + end, + particle_color = "#000000", + uses_factor = false, +}) + mcl_potions.register_effect({ name = "health_boost", description = S("Health Boost"),