mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-11 04:50:17 +01:00
[solarmana] Switch to minetest.after
This commit is contained in:
parent
f94ecd5fd8
commit
cc8c707571
|
@ -44,84 +44,81 @@ local mana_from_node = {
|
||||||
local time_total_mana_reset = 10.0
|
local time_total_mana_reset = 10.0
|
||||||
local time_next_mana_reset = time_total_mana_reset
|
local time_next_mana_reset = time_total_mana_reset
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
local function tick()
|
||||||
|
-- We do not care if this does not run as often as possible,
|
||||||
|
-- as all it does is change the regeneration to a fixed number
|
||||||
|
minetest.after(time_next_regen_check, tick)
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local pos = player:getpos()
|
||||||
|
local pos_y = pos.y
|
||||||
|
-- the middle of the block with the player's head
|
||||||
|
pos.y = math.floor(pos_y) + 1.5
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
-- We do not care if this does not run as often as possible,
|
-- Currently uses 'get_node_light' to determine whether
|
||||||
-- as all it does is change the regeneration to a fixed number
|
-- a node is "in sunlight".
|
||||||
time_next_regen_check = time_next_regen_check - dtime
|
local light_day = minetest.get_node_light(pos, 0.5)
|
||||||
if time_next_regen_check < 0.0 then
|
local light_night = minetest.get_node_light(pos, 0.0)
|
||||||
time_next_regen_check = time_total_regen_check
|
local light_now = minetest.get_node_light(pos) or 0
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
local regen_to = 0
|
||||||
local name = player:get_player_name()
|
|
||||||
local pos = player:getpos()
|
|
||||||
local pos_y = pos.y
|
|
||||||
-- the middle of the block with the player's head
|
|
||||||
pos.y = math.floor(pos_y) + 1.5
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
|
|
||||||
-- Currently uses 'get_node_light' to determine whether
|
-- simplest version checks for "full sunlight now"
|
||||||
-- a node is "in sunlight".
|
if light_now >= 14 then
|
||||||
local light_day = minetest.get_node_light(pos, 0.5)
|
regen_to = 3
|
||||||
local light_night = minetest.get_node_light(pos, 0.0)
|
end
|
||||||
local light_now = minetest.get_node_light(pos) or 0
|
|
||||||
local regen_to = 0
|
|
||||||
|
|
||||||
-- simplest version checks for "full sunlight now"
|
-- we can get a bit more lenience by testing whether
|
||||||
if light_now >= 14 then
|
-- * a node is "affected by sunlight" (day > night)
|
||||||
regen_to = 3
|
-- * the node is "bright enough now"
|
||||||
end
|
-- However: you could deny yourself mana regeneration
|
||||||
|
-- with torches :-/
|
||||||
|
--[[
|
||||||
|
if light_day > light_night and light_now > 12 then
|
||||||
|
regen_to = 1
|
||||||
|
end
|
||||||
|
--]]
|
||||||
|
|
||||||
-- we can get a bit more lenience by testing whether
|
-- next, check the block we're standing on.
|
||||||
-- * a node is "affected by sunlight" (day > night)
|
pos.y = math.floor(pos_y) - 0.5
|
||||||
-- * the node is "bright enough now"
|
node = minetest.get_node(pos)
|
||||||
-- However: you could deny yourself mana regeneration
|
local nodemana = mana_from_node[node.name]
|
||||||
-- with torches :-/
|
for key, value in pairs(mana_from_node) do
|
||||||
--[[
|
if key:split(":")[1] == "group" then
|
||||||
if light_day > light_night and light_now > 12 then
|
local groupname = key:split(":")[2]
|
||||||
regen_to = 1
|
if minetest.get_node_group(node.name, groupname) > 0 then
|
||||||
end
|
if nodemana then
|
||||||
--]]
|
nodemana = math.max(nodemana, value) -- We get the greater one (if the node is part of 2 or more groups)
|
||||||
|
else
|
||||||
-- next, check the block we're standing on.
|
nodemana = value
|
||||||
pos.y = math.floor(pos_y) - 0.5
|
end
|
||||||
node = minetest.get_node(pos)
|
end
|
||||||
local nodemana = mana_from_node[node.name]
|
end
|
||||||
for key, value in pairs(mana_from_node) do
|
end
|
||||||
if key:split(":")[1] == "group" then
|
if nodemana then
|
||||||
local groupname = key:split(":")[2]
|
if nodemana > 0 then
|
||||||
if minetest.get_node_group(node.name, groupname) > 0 then
|
regen_to = math.max(regen_to, nodemana)
|
||||||
if nodemana then
|
else
|
||||||
nodemana = math.max(nodemana, value) -- We get the greater one (if the node is part of 2 or more groups)
|
regen_to = regen_to + nodemana -- negative, remember?
|
||||||
else
|
end
|
||||||
nodemana = value
|
--print("Regen to "..regen_to.." : "..node.name)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if nodemana then
|
|
||||||
if nodemana > 0 then
|
|
||||||
regen_to = math.max(regen_to, nodemana)
|
|
||||||
else
|
|
||||||
regen_to = regen_to + nodemana -- negative, remember?
|
|
||||||
end
|
|
||||||
--print("Regen to "..regen_to.." : "..node.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
mana.setregen(name, regen_to)
|
mana.setregen(name, regen_to)
|
||||||
--print("Regen to "..regen_to.." : "..light_day.."/"..light_now.."/"..light_night)
|
--print("Regen to "..regen_to.." : "..light_day.."/"..light_now.."/"..light_night)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--[[ Comment this in for testing if you have no mana sink
|
--[[ Comment this in for testing if you have no mana sink
|
||||||
|
|
||||||
time_next_mana_reset = time_next_mana_reset - dtime
|
time_next_mana_reset = time_next_mana_reset - dtime
|
||||||
if time_next_mana_reset < 0.0 then
|
if time_next_mana_reset < 0.0 then
|
||||||
time_next_mana_reset = time_total_mana_reset
|
time_next_mana_reset = time_total_mana_reset
|
||||||
mana.set('singleplayer', 100)
|
mana.set('singleplayer', 100)
|
||||||
print("Resetting mana")
|
print("Resetting mana")
|
||||||
end
|
end
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
end
|
||||||
|
|
||||||
end)
|
tick()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user