From 6db8d9fc268835be095b745be981efd03ae6e498 Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sat, 22 Feb 2020 16:55:42 -0500 Subject: [PATCH] Adjust things to work in twilight. - Lenses no longer produce light from sun at all; artificial light is always needed. - Grass and trees survive, don't do dual-time check. - Breeze sounds work in twilight. - Sponge drying only requires twilight, now also can happen under artificial light. - Peat to grass happens under twilight. --- mods/nc_api/util_misc.lua | 7 +++++++ mods/nc_envsound/init.lua | 5 ++--- mods/nc_optics/lens.lua | 14 +++----------- mods/nc_player_names/init.lua | 2 +- mods/nc_sponge/abm.lua | 6 +++--- mods/nc_terrain/abm.lua | 7 +++---- mods/nc_tree/ambiance.lua | 2 +- mods/nc_tree/api.lua | 2 +- mods/nc_tree/compost.lua | 4 ++-- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/mods/nc_api/util_misc.lua b/mods/nc_api/util_misc.lua index b73e0ebe..2c43a6d4 100644 --- a/mods/nc_api/util_misc.lua +++ b/mods/nc_api/util_misc.lua @@ -430,6 +430,13 @@ function nodecore.get_depth_light(y, qty) return qty end +nodecore.light_sun = 15 +nodecore.light_sky = math_floor(0.5 + nodecore.light_sun * nodecore.get_depth_light(0)) + +function nodecore.is_full_sun(pos) + return minetest.get_node_light(pos) == nodecore.light_sun +end + function nodecore.get_node_light(pos) local artificial = minetest.get_node_light(pos, 0) local natural = math_floor(0.5 + minetest.get_node_light(pos, 0.5) diff --git a/mods/nc_envsound/init.lua b/mods/nc_envsound/init.lua index 79914c87..6070569d 100644 --- a/mods/nc_envsound/init.lua +++ b/mods/nc_envsound/init.lua @@ -28,14 +28,13 @@ local function check(pos, done, srcs) end if minetest.get_node(sp).name ~= "air" then return end - local light = nodecore.get_node_light(sp, 0.5) - if light == 15 then + if nodecore.is_full_sun(sp) then if sp.y <= 0 then return end minetest.sound_play("nc_envsound_air", { pos = sp, gain = nodecore.windiness(sp.y) / 100 }) - elseif light < 4 then + elseif nodecore.get_node_light(sp) < 4 then minetest.sound_play("nc_envsound_drip", { pos = sp, pitchvary = 0.4, diff --git a/mods/nc_optics/lens.lua b/mods/nc_optics/lens.lua index 7f01df01..26fd16ca 100644 --- a/mods/nc_optics/lens.lua +++ b/mods/nc_optics/lens.lua @@ -13,17 +13,9 @@ local function lens_check(pos, node, check) end local fore = vector.add(pos, face.f) - local on - if face.f.y == 1 then - local ll = nodecore.get_node_light(fore) - on = ll and ll >= 14 - end - if not on then - local nnode = minetest.get_node(fore) - local def = minetest.registered_items[nnode.name] or {} - on = def.light_source and def.light_source > 4 - end - if on then + local nnode = minetest.get_node(fore) + local def = minetest.registered_items[nnode.name] or {} + if def.light_source and def.light_source > 4 then return modname .. ":lens_on", {face.k} end diff --git a/mods/nc_player_names/init.lua b/mods/nc_player_names/init.lua index 748d26f9..366634e0 100644 --- a/mods/nc_player_names/init.lua +++ b/mods/nc_player_names/init.lua @@ -55,7 +55,7 @@ local function canseeface(p1, p2) if dsqr < 1 then return end local ll = nodecore.get_node_light({x = o2.x, y = o2.y + e2, z = o2.z}) if not ll then return end - local ld = (ll / 15 * distance) + local ld = (ll / nodecore.light_max * distance) if dsqr > (ld * ld) then return end -- Make sure players' eyes are inside the same fluid. diff --git a/mods/nc_sponge/abm.lua b/mods/nc_sponge/abm.lua index 4884160c..e833d19b 100644 --- a/mods/nc_sponge/abm.lua +++ b/mods/nc_sponge/abm.lua @@ -57,7 +57,7 @@ nodecore.register_limited_abm({ nodenames = {modname .. ":sponge_wet"}, action = function(pos) local above = {x = pos.x, y = pos.y + 1, z = pos.z} - if nodecore.get_node_light(above) >= 15 and #findwater(pos) < 1 then + if nodecore.is_full_sun(above) and #findwater(pos) < 1 then minetest.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos}) return minetest.set_node(pos, {name = modname .. ":sponge"}) end @@ -72,8 +72,8 @@ nodecore.register_aism({ action = function(stack, data) if data.player and (data.list ~= "main" or data.slot ~= data.player:get_wield_index()) then return end - local ll = data.pos and nodecore.get_node_light(data.pos) - if ll and ll >= 15 and #findwater(data.pos) < 1 then + if data.pos and nodecore.is_full_sun(data.pos) + and #findwater(data.pos) < 1 then minetest.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = data.pos}) local taken = stack:take_item(1) taken:set_name(modname .. ":sponge") diff --git a/mods/nc_terrain/abm.lua b/mods/nc_terrain/abm.lua index 921a6996..5ff06331 100644 --- a/mods/nc_terrain/abm.lua +++ b/mods/nc_terrain/abm.lua @@ -35,10 +35,9 @@ local function grassable(above) or (def.damage_per_second and def.damage_per_second > 0) then return false end - local ln = nodecore.get_node_light(above) or 0 - if ln >= 10 then return true end - local ld = nodecore.get_node_light(above, 0.5) or 0 - if ld >= 10 then return end + local ln = nodecore.get_node_light(above) + if not ln then return end + return ln >= 10 end local grasscost = 1000 diff --git a/mods/nc_tree/ambiance.lua b/mods/nc_tree/ambiance.lua index a9524124..d5bfa1b9 100644 --- a/mods/nc_tree/ambiance.lua +++ b/mods/nc_tree/ambiance.lua @@ -14,7 +14,7 @@ nodecore.register_ambiance({ pos.y = pos.y + 1 if pos.y <= 0 then return end return minetest.get_node(pos).name == "air" - and nodecore.get_node_light(pos, 0.5) == 15 + and nodecore.is_full_sun(pos) and {gain = nodecore.windiness(pos.y) / 20} end }) diff --git a/mods/nc_tree/api.lua b/mods/nc_tree/api.lua index 35f5f05c..2946257b 100644 --- a/mods/nc_tree/api.lua +++ b/mods/nc_tree/api.lua @@ -49,7 +49,7 @@ end function nodecore.tree_growth_rate(pos) local above = {x = pos.x, y = pos.y + 1, z = pos.z} if minetest.get_node(above).name ~= "air" then return end - local ll = nodecore.get_node_light(above, 0.5) + local ll = nodecore.get_node_light(above) if (not ll) or (ll < 8) then return end for y = 2, 5 do local p ={x = pos.x, y = pos.y + y, z = pos.z} diff --git a/mods/nc_tree/compost.lua b/mods/nc_tree/compost.lua index 1456d9f7..b57c119a 100644 --- a/mods/nc_tree/compost.lua +++ b/mods/nc_tree/compost.lua @@ -69,8 +69,8 @@ nodecore.register_soaking_abm({ soakcheck = function(data, pos) if data.total < compostcost then return end minetest.get_meta(pos):from_table({}) - if math_random(1, 100) == 1 and nodecore.get_node_light( - {x = pos.x, y = pos.y + 1, z = pos.z}) == 15 then + if math_random(1, 100) == 1 and nodecore.is_full_sun( + {x = pos.x, y = pos.y + 1, z = pos.z}) then nodecore.set_loud(pos, {name = "nc_terrain:dirt_with_grass"}) return end