From 5b44eeb61175387f101d6027a1218b0eb3514569 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 17 Jan 2021 02:47:04 +0400 Subject: [PATCH] Teach observer to detect TNT in realtime mode, fix crash in mcl_spawn on restart server in less than 30s in new world --- mods/ITEMS/REDSTONE/mcl_observers/init.lua | 30 ++++++++++++++++++++++ mods/PLAYER/mcl_spawn/init.lua | 14 ++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mcl_observers/init.lua b/mods/ITEMS/REDSTONE/mcl_observers/init.lua index 759e0599..932f4f64 100644 --- a/mods/ITEMS/REDSTONE/mcl_observers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_observers/init.lua @@ -284,6 +284,7 @@ if realtime then mcl_observers.set_node = minetest.set_node mcl_observers.swap_node = minetest.swap_node mcl_observers.remove_node = minetest.remove_node + mcl_observers.bulk_set_node = minetest.bulk_set_node minetest.add_node=function(pos,node) mcl_observers.add_node(pos,node) @@ -393,6 +394,35 @@ if realtime then mcl_observers.observer_activate({x=pos.x,y=pos.y+1,z=pos.z}) end end + minetest.bulk_set_node=function(lst, node) + mcl_observers.bulk_set_node(lst, node) + for _, pos in pairs(lst) do + local n=minetest.get_node({x=pos.x+1,y=pos.y,z=pos.z}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_o" and minetest.facedir_to_dir(n.param2).x==-1 then + mcl_observers.observer_activate({x=pos.x+1,y=pos.y,z=pos.z}) + end + n=minetest.get_node({x=pos.x-1,y=pos.y,z=pos.z}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_o" and minetest.facedir_to_dir(n.param2).x==1 then + mcl_observers.observer_activate({x=pos.x-1,y=pos.y,z=pos.z}) + end + n=minetest.get_node({x=pos.x,y=pos.y,z=pos.z+1}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_o" and minetest.facedir_to_dir(n.param2).z==-1 then + mcl_observers.observer_activate({x=pos.x,y=pos.y,z=pos.z+1}) + end + n=minetest.get_node({x=pos.x,y=pos.y,z=pos.z-1}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_o" and minetest.facedir_to_dir(n.param2).z==1 then + mcl_observers.observer_activate({x=pos.x,y=pos.y,z=pos.z-1}) + end + n=minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_u" then + mcl_observers.observer_activate({x=pos.x,y=pos.y-1,z=pos.z}) + end + n=minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}) + if n and n.name and string.sub(n.name,1,24)=="mcl_observers:observer_d" then + mcl_observers.observer_activate({x=pos.x,y=pos.y+1,z=pos.z}) + end + end + end else -- if realtime then ^^^ else: minetest.register_abm({ diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 33bcce1e..cb042426 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -372,11 +372,15 @@ function mcl_spawn.shadow_worker() minetest.after(respawn_search_interval, mcl_spawn.shadow_worker) end -minetest.after(respawn_search_initial_delay, mcl_spawn.shadow_worker) -minetest.register_on_shutdown(function() +minetest.after(respawn_search_initial_delay, function() + mcl_spawn.shadow_worker() + + minetest.register_on_shutdown(function() storage:set_int("mcl_spawn_success", success and 1 or 0) - storage:set_string("mcl_spawn_world_spawn_point", minetest.pos_to_string(wsp)) + if wsp and wsp.x then + storage:set_string("mcl_spawn_world_spawn_point", minetest.pos_to_string(wsp)) + end storage:set_int("mcl_spawn_searched", searched and 1 or 0) storage:set_int("mcl_spawn_check", check) storage:set_string("mcl_spawn_cp", minetest.pos_to_string(cp)) @@ -384,5 +388,5 @@ minetest.register_on_shutdown(function() storage:set_int("mcl_spawn_edge_dist", edge_dist) storage:set_int("mcl_spawn_dir_step", dir_step) storage:set_int("mcl_spawn_dir_ind", dir_ind) - end -) + end) +end)