mirror of
https://github.com/t-affeldt/lighting_monoids.git
synced 2025-04-11 07:20:37 +02:00
Refactor compatibility patches
This commit is contained in:
parent
623ee19115
commit
a71489327a
44
compatibility/enable_shadows.lua
Normal file
44
compatibility/enable_shadows.lua
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
--[[
|
||||||
|
This code is mostly taken from the original enable_shadows mod
|
||||||
|
and tweaked to work with the new monoids.
|
||||||
|
enable_shadows is licensed under MIT, respective Copyright (c) 2022 ROllerozxa
|
||||||
|
]]
|
||||||
|
|
||||||
|
local S = minetest.get_translator("enable_shadows")
|
||||||
|
local storage = minetest.get_mod_storage()
|
||||||
|
|
||||||
|
local default_intensity = tonumber(minetest.settings:get("enable_shadows_default_intensity") or 0.33)
|
||||||
|
local intensity = tonumber(storage:get("intensity") or default_intensity)
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
lighting_monoids.shadows:add_change(player, intensity, "enable_shadows:base_value")
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.override_chatcommand("shadow_intensity", {
|
||||||
|
func = function(name, param)
|
||||||
|
local new_intensity
|
||||||
|
if param ~= "" then
|
||||||
|
new_intensity = tonumber(param) or nil
|
||||||
|
else
|
||||||
|
new_intensity = tonumber(default_intensity) or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if new_intensity < 0 or new_intensity > 1 or new_intensity == nil then
|
||||||
|
minetest.chat_send_player(name, minetest.colorize("#ff0000", S("Invalid intensity.")))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if new_intensity ~= default_intensity then
|
||||||
|
minetest.chat_send_player(name, S("Set intensity to @1.", new_intensity))
|
||||||
|
storage:set_float("intensity", new_intensity)
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, S("Set intensity to default value (@1).", default_intensity))
|
||||||
|
storage:set_string("intensity", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
intensity = new_intensity
|
||||||
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
lighting_monoids.shadows:add_change(player, new_intensity, "enable_shadows:base_value")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
14
compatibility/weather.lua
Normal file
14
compatibility/weather.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
-- Hook into MTG weather mod for compatibility (requires PR #3020)
|
||||||
|
if weather ~= nil and weather.on_update ~= nil then
|
||||||
|
weather.on_update = function(player, overrides)
|
||||||
|
if overrides == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if overrides.shadows and overrides.shadows.intensity then
|
||||||
|
local intensity = overrides.shadows.intensity
|
||||||
|
lighting_monoids.shadows:add_change(player, intensity, "weather:cloud_shadows")
|
||||||
|
end
|
||||||
|
overrides.lighting = nil
|
||||||
|
return overrides
|
||||||
|
end
|
||||||
|
end
|
35
init.lua
35
init.lua
@ -3,6 +3,8 @@ lighting_monoids = {}
|
|||||||
local SET_BASE_SHADOW = minetest.settings:get_bool("lighting_monoids.set_base_shadow", true)
|
local SET_BASE_SHADOW = minetest.settings:get_bool("lighting_monoids.set_base_shadow", true)
|
||||||
local BASE_SHADOW_INTENSITY = tonumber(minetest.settings:get("lighting_monoids.base_shadow_intensity") or 0.33)
|
local BASE_SHADOW_INTENSITY = tonumber(minetest.settings:get("lighting_monoids.base_shadow_intensity") or 0.33)
|
||||||
|
|
||||||
|
local MODPATH = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
local function multiply(a, b)
|
local function multiply(a, b)
|
||||||
if a == nil then a = 1 end
|
if a == nil then a = 1 end
|
||||||
if b == nil then b = 1 end
|
if b == nil then b = 1 end
|
||||||
@ -28,7 +30,9 @@ lighting_monoids.shadows = player_monoids.make_monoid({
|
|||||||
local lighting = player:get_lighting()
|
local lighting = player:get_lighting()
|
||||||
lighting.shadows = lighting.shadows or {}
|
lighting.shadows = lighting.shadows or {}
|
||||||
lighting.shadows.intensity = multiplier
|
lighting.shadows.intensity = multiplier
|
||||||
player:set_lighting(lighting)
|
if player.set_lighting ~= nil then
|
||||||
|
player:set_lighting(lighting)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -40,31 +44,18 @@ lighting_monoids.saturation = player_monoids.make_monoid({
|
|||||||
apply = function(multiplier, player)
|
apply = function(multiplier, player)
|
||||||
local lighting = player:get_lighting()
|
local lighting = player:get_lighting()
|
||||||
lighting.saturation = multiplier
|
lighting.saturation = multiplier
|
||||||
player:set_lighting(lighting)
|
if player.set_lighting ~= nil then
|
||||||
|
player:set_lighting(lighting)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Hook into MTG weather mod for compatibility (requires PR #3020)
|
if minetest.get_modpath("weather") then
|
||||||
if minetest.get_modpath("weather") and weather and weather.on_update then
|
dofile(MODPATH .. DIR_DELIM .. "compatibility" .. DIR_DELIM .. "weather.lua")
|
||||||
weather.on_update = function(player, overrides)
|
end
|
||||||
if overrides == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if overrides.shadows and overrides.shadows.intensity then
|
|
||||||
local intensity = overrides.shadows.intensity
|
|
||||||
lighting_monoids.shadows:add_change(player, intensity, "weather:cloud_shadows")
|
|
||||||
end
|
|
||||||
overrides.lighting = nil
|
|
||||||
return overrides
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set base shadow intensity according to mod config
|
if minetest.get_modpath("enable_shadows") then
|
||||||
-- only basic integration, doesn't update when command is used
|
dofile(MODPATH .. DIR_DELIM .. "compatibility" .. DIR_DELIM .. "enable_shadows.lua")
|
||||||
elseif minetest.get_modpath("enable_shadows") then
|
|
||||||
local intensity = tonumber(minetest.settings:get("enable_shadows_default_intensity") or 0.33)
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
lighting_monoids.shadows:add_change(player, intensity, "enable_shadows:base_value")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- set base shadow
|
-- set base shadow
|
||||||
elseif SET_BASE_SHADOW then
|
elseif SET_BASE_SHADOW then
|
||||||
|
2
mod.conf
2
mod.conf
@ -2,7 +2,7 @@ name = lighting_monoids
|
|||||||
title = Monoids for Player Lighting
|
title = Monoids for Player Lighting
|
||||||
author = TestificateMods
|
author = TestificateMods
|
||||||
depends = player_monoids
|
depends = player_monoids
|
||||||
optional_depends = enable_shadows,weather
|
optional_depends = enable_shadows, weather
|
||||||
description = """
|
description = """
|
||||||
|
|
||||||
"""
|
"""
|
Loading…
x
Reference in New Issue
Block a user