mirror of
https://github.com/t-affeldt/lighting_monoids.git
synced 2025-07-07 11:00:23 +02:00
Refactor compatibility patches
This commit is contained in:
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
|
Reference in New Issue
Block a user