-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
120 lines (101 loc) · 2.69 KB
/
init.lua
File metadata and controls
120 lines (101 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
-- Load files
local modpath = minetest.get_modpath("corruptionmt")
dofile(modpath.."/choker.lua")
dofile(modpath.."/corrupt_mind.lua")
dofile(modpath.."/ebonsphere.lua")
dofile(modpath.."/eyeman.lua")
dofile(modpath.."/ebonwood.lua")
dofile(modpath.."/ores.lua")
dofile(modpath.."/nodes.lua")
dofile(modpath.."/biome.lua")
dofile(modpath.."/mobs.lua")
dofile(modpath.."/items.lua")
dofile(modpath.."/eyerachnid.lua")
dofile(modpath.."/shadow_steel.lua")
dofile(modpath.."/plants.lua")
local CHECK_RADIUS = 6
local FADE_SPEED = 0.5
local STEP = 0.1
-- Default sky color (close to Minetest)
local NORMAL = { r = 140, g = 182, b = 255 }
-- Biome sky colors
local CORRUPTION = { r = 160, g = 80, b = 200 } -- purple
local CRIMSON = { r = 200, g = 120, b = 120 } -- pale red (blends better)
local players = {}
local timer = 0
-- Helpers
local function lerp(a, b, t)
return a + (b - a) * t
end
local function lerp_color(c1, c2, t)
return {
r = lerp(c1.r, c2.r, t),
g = lerp(c1.g, c2.g, t),
b = lerp(c1.b, c2.b, t),
}
end
local function rgb_to_hex(c)
return string.format("#%02X%02X%02X",
math.floor(c.r),
math.floor(c.g),
math.floor(c.b)
)
end
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < STEP then return end
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:get_pos())
players[name] = players[name] or {
factor = 0,
target = nil,
}
-- Detect biome
local in_corruption = minetest.find_node_near(pos, CHECK_RADIUS, {
"group:corruption_biome"
})
local in_crimson = minetest.find_node_near(pos, CHECK_RADIUS, {
"group:crimson_biome"
})
-- Choose biome (corruption overrides crimson if overlapping)
local target_color = nil
if in_corruption then
target_color = CORRUPTION
elseif in_crimson then
target_color = CRIMSON
end
local state = players[name]
local target = target_color and 1 or 0
local delta = STEP / FADE_SPEED
-- Reset fade if switching biome type
if state.target ~= target_color then
state.factor = 0
state.target = target_color
end
-- Move fade factor
if state.factor < target then
state.factor = math.min(1, state.factor + delta)
elseif state.factor > target then
state.factor = math.max(0, state.factor - delta)
end
-- Apply sky
if target_color then
local color = lerp_color(NORMAL, target_color, state.factor)
player:set_sky({
base_color = rgb_to_hex(color),
type = "plain",
clouds = false,
})
else
player:set_sky({
type = "regular",
clouds = true,
})
end
end
end)
minetest.register_on_leaveplayer(function(player)
players[player:get_player_name()] = nil
end)