forked from VoxeLibre/VoxeLibre
use globalstep instead of abm
This commit is contained in:
parent
10a607be7e
commit
c695776105
|
@ -63,7 +63,42 @@ local function beacon_blockcheck(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function effect_player(effect,pos,power_level, effect_level)
|
||||||
|
local all_objects = minetest.get_objects_inside_radius(pos, (power_level+1)*10)
|
||||||
|
for _,obj2 in ipairs(all_objects) do
|
||||||
|
if obj2:is_player() then
|
||||||
|
if effect == "swiftness" then
|
||||||
|
mcl_potions.swiftness_func(obj2,effect_level,16)
|
||||||
|
return
|
||||||
|
elseif effect == "leaping" then
|
||||||
|
mcl_potions.leaping_func(obj2, effect_level, 16)
|
||||||
|
return
|
||||||
|
elseif effect == "strenght" then
|
||||||
|
mcl_potions.strength_func(obj2, effect_level, 16)
|
||||||
|
return
|
||||||
|
elseif effect == "regeneration" then
|
||||||
|
mcl_potions.regeneration_func(obj2, effect_level, 16)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function globalstep_function(pos, forceexecute)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if(meta:get_int("last-effect-cycle")+10 < os.time() or forceexecute) then
|
||||||
|
meta:set_int("last-effect-cycle", os.time())
|
||||||
|
local power_level = beacon_blockcheck(pos)
|
||||||
|
local effect_string = meta:get_string("effect")
|
||||||
|
if meta:get_int("effect_level") == 2 and power_level < 4 then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
effect_player(effect_string,pos,power_level,meta:get_int("effect_level"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("mcl_beacons:beacon", {
|
minetest.register_node("mcl_beacons:beacon", {
|
||||||
|
@ -150,6 +185,7 @@ minetest.register_node("mcl_beacons:beacon", {
|
||||||
if successful then
|
if successful then
|
||||||
input:take_item()
|
input:take_item()
|
||||||
inv:set_stack("input",1,input)
|
inv:set_stack("input",1,input)
|
||||||
|
globalstep_function(pos,true)--call it once outside the globalstep so the player gets the effect right after selecting it
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -171,47 +207,17 @@ function register_beaconfuel(itemstring)
|
||||||
table.insert(beacon_fuellist, itemstring)
|
table.insert(beacon_fuellist, itemstring)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function effect_player(effect,pos,power_level, effect_level)
|
local time_since_last_beacon_interval = os.time()
|
||||||
local all_objects = minetest.get_objects_inside_radius(pos, (power_level+1)*10)
|
|
||||||
for _,obj2 in ipairs(all_objects) do
|
minetest.register_globalstep(function(dtime)
|
||||||
if obj2:is_player() then
|
if time_since_last_beacon_interval + 10 < os.time() then
|
||||||
if effect == "swiftness" then
|
time_since_last_beacon_interval = os.time()
|
||||||
mcl_potions.swiftness_func(obj2,effect_level,16)
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
return
|
local player_pos = player.get_pos(player)
|
||||||
elseif effect == "leaping" then
|
local pos_list = minetest.find_nodes_in_area({x=player_pos.x-50, y=player_pos.y-50, z=player_pos.z-50}, {x=player_pos.x+50, y=player_pos.y+50, z=player_pos.z+50},"mcl_beacons:beacon")
|
||||||
mcl_potions.leaping_func(obj2, effect_level, 16)
|
for _, pos in ipairs(pos_list) do
|
||||||
return
|
globalstep_function(pos, false)
|
||||||
elseif effect == "strenght" then
|
end
|
||||||
mcl_potions.strength_func(obj2, effect_level, 16)
|
|
||||||
return
|
|
||||||
elseif effect == "regeneration" then
|
|
||||||
mcl_potions.regeneration_func(obj2, effect_level, 16)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
|
|
||||||
local function abm_function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if(meta:get_int("last-effect-cycle")+10 < os.time()) then
|
|
||||||
meta:set_int("last-effect-cycle", os.time())
|
|
||||||
local power_level = beacon_blockcheck(pos)
|
|
||||||
local effect_string = meta:get_string("effect")
|
|
||||||
if meta:get_int("effect_level") == 2 and power_level < 4 then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
effect_player(effect_string,pos,power_level,meta:get_int("effect_level"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_abm{
|
|
||||||
label = "beacon check & apply effect(s)",
|
|
||||||
nodenames = {"mcl_beacons:beacon"},
|
|
||||||
interval = 1,
|
|
||||||
chance = 1,
|
|
||||||
action = abm_function,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue