1
0
Fork 0

Merge pull request 'Migrate beacons back to abm' (#3631) from beacon-abm into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3631
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
skelly_horse_thunder
ancientmarinerdev 2023-04-27 18:09:37 +00:00
commit 0d80f1126c
1 changed files with 45 additions and 42 deletions

View File

@ -178,6 +178,22 @@ local function beacon_blockcheck(pos)
end
end
local function clear_obstructed_beam(pos)
for y=pos.y+1, pos.y+100 do
local nodename = minetest.get_node({x=pos.x,y=y, z = pos.z}).name
if nodename ~= "mcl_core:bedrock" and nodename ~= "air" and nodename ~= "mcl_core:void" and nodename ~= "ignore" then --ignore means not loaded, let's just assume that's air
if nodename ~="mcl_beacons:beacon_beam" then
if minetest.get_item_group(nodename,"glass") == 0 and minetest.get_item_group(nodename,"material_glass") == 0 then
remove_beacon_beam(pos)
return true
end
end
end
end
return false
end
local function effect_player(effect,pos,power_level, effect_level,player)
local distance = vector.distance(player:get_pos(), pos)
if distance > (power_level+1)*10 then return end
@ -192,31 +208,25 @@ local function effect_player(effect,pos,power_level, effect_level,player)
end
end
local function globalstep_function(pos,player)
local meta = minetest.get_meta(pos)
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
local obstructed = false
for y=pos.y+1, pos.y+100 do
local function apply_effects_to_all_players(pos)
local meta = minetest.get_meta(pos)
local effect_string = meta:get_string("effect")
local effect_level = meta:get_int("effect_level")
local nodename = minetest.get_node({x=pos.x,y=y, z = pos.z}).name
if nodename ~= "mcl_core:bedrock" and nodename ~= "air" and nodename ~= "mcl_core:void" and nodename ~= "ignore" then --ignore means not loaded, let's just assume that's air
if nodename ~="mcl_beacons:beacon_beam" then
if minetest.get_item_group(nodename,"glass") == 0 and minetest.get_item_group(nodename,"material_glass") == 0 then
obstructed = true
remove_beacon_beam(pos)
return
end
end
end
end
if obstructed then
return
end
effect_player(effect_string,pos,power_level,meta:get_int("effect_level"),player)
local power_level = beacon_blockcheck(pos)
if effect_level == 2 and power_level < 4 then --no need to run loops when beacon is in an invalid setup :P
return
end
local beacon_distance = (power_level + 1) * 10
for _, player in pairs(minetest.get_connected_players()) do
if vector.distance(pos, player:get_pos()) <= beacon_distance then
if not clear_obstructed_beam(pos) then
effect_player(effect_string, pos, power_level, effect_level, player)
end
end
end
end
@ -330,7 +340,7 @@ minetest.register_node("mcl_beacons:beacon", {
minetest.set_node({x=pos.x,y=y,z=pos.z},{name="mcl_beacons:beacon_beam",param2=beam_palette_index})
end
end
globalstep_function(pos,sender)--call it once outside the globalstep so the player gets the effect right after selecting it
apply_effects_to_all_players(pos) --call it once outside the globalstep so the player gets the effect right after selecting it
end
end
end,
@ -352,23 +362,6 @@ function register_beaconfuel(itemstring)
table.insert(beacon_fuellist, itemstring)
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 3 then
for _, player in ipairs(minetest.get_connected_players()) do
local player_pos = player:get_pos()
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")
for _, pos in ipairs(pos_list) do
globalstep_function(pos,player)
end
end
timer = 0
end
end)
minetest.register_abm{
label="update beacon beam",
nodenames = {"mcl_beacons:beacon_beam"},
@ -392,6 +385,16 @@ minetest.register_abm{
end,
}
minetest.register_abm{
label="apply beacon effects to players",
nodenames = {"mcl_beacons:beacon"},
interval = 3,
chance = 1,
action = function(pos)
apply_effects_to_all_players(pos)
end,
}
minetest.register_craft({
output = "mcl_beacons:beacon",
recipe = {