Respawn flags on loading chunk, part 2

This commit is contained in:
Wuzzy 2022-07-03 00:48:54 +02:00
parent f4964faaca
commit ae0929a6dd

View file

@ -55,12 +55,6 @@ minetest.register_entity( "pride_flags:wavingflag", {
return return
end end
local aflag = active_flags[ self.node_idx ]
if aflag then
minetest.log("error", "stop_a")
return
end
self:reset_texture( self.flag_idx ) self:reset_texture( self.flag_idx )
active_flags[ self.node_idx ] = self.object active_flags[ self.node_idx ] = self.object
@ -243,13 +237,14 @@ local function spawn_flag( pos )
return obj return obj
end end
local function spawn_flag_and_set_meta( pos ) local function spawn_flag_and_set_texture( pos )
local flag = spawn_flag( pos ) local flag = spawn_flag( pos )
if flag and flag:get_luaentity() then if flag and flag:get_luaentity() then
local meta = minetest.get_meta( pos ) local meta = minetest.get_meta( pos )
local flag_idx = meta:get_int("flag_idx") local flag_idx = meta:get_int("flag_idx")
flag:get_luaentity():reset_texture( flag_idx ) flag:get_luaentity():reset_texture( flag_idx )
end end
return flag
end end
local function cycle_flag( pos, player, cycle_backwards ) local function cycle_flag( pos, player, cycle_backwards )
@ -271,7 +266,7 @@ local function cycle_flag( pos, player, cycle_backwards )
local meta = minetest.get_meta( pos ) local meta = minetest.get_meta( pos )
meta:set_int("flag_idx", flag_idx) meta:set_int("flag_idx", flag_idx)
else else
spawn_flag_and_set_meta( pos ) spawn_flag_and_set_texture( pos )
end end
end end
end end
@ -328,6 +323,15 @@ minetest.register_node( "pride_flags:upper_mast", {
local aflag = active_flags[ node_idx ] local aflag = active_flags[ node_idx ]
if aflag then if aflag then
local lua = aflag:get_luaentity( ) local lua = aflag:get_luaentity( )
if not lua then
aflag = spawn_flag_and_set_texture( pos )
if aflag then
lua = aflag:get_luaentity()
if not lua then
return
end
end
end
local flag_pos_idx = lua.node_idx local flag_pos_idx = lua.node_idx
local flag_pos = minetest.get_position_from_hash( flag_pos_idx ) local flag_pos = minetest.get_position_from_hash( flag_pos_idx )
flag_pos = get_flag_pos( flag_pos, new_param2 ) flag_pos = get_flag_pos( flag_pos, new_param2 )
@ -346,10 +350,8 @@ minetest.register_lbm({
local node_idx = minetest.hash_node_position( pos ) local node_idx = minetest.hash_node_position( pos )
local aflag = active_flags[ node_idx ] local aflag = active_flags[ node_idx ]
if aflag then if aflag then
minetest.log("error", "stop")
return return
end end
spawn_flag_and_set_meta( pos ) spawn_flag_and_set_texture( pos )
minetest.log("error", "sp:"..minetest.pos_to_string(pos))
end end
}) })