1
0
Fork 0

mcl_maps: add callback to load_map function (#2261)

Fixes maps in itemframes not loading after restart (#2255)
Reviewed-on: MineClone2/MineClone2#2261
Co-authored-by: Elias Fleckenstein <eliasfleckenstein@web.de>
Co-committed-by: Elias Fleckenstein <eliasfleckenstein@web.de>
This commit is contained in:
Lizzy Fleckenstein 2022-05-30 01:32:20 +00:00 committed by cora
parent 50c802df98
commit a86fc935aa
2 changed files with 8 additions and 2 deletions

View File

@ -64,7 +64,10 @@ minetest.register_entity("mcl_itemframes:map", {
}, },
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
self.id = staticdata self.id = staticdata
self.object:set_properties({textures = {mcl_maps.load_map(self.id)}}) mcl_maps.load_map(self.id, function(texture)
-- will not crash even if self.object is invalid by now
self.object:set_properties({textures = {texture}})
end)
end, end,
get_staticdata = function(self) get_staticdata = function(self)
return self.id return self.id

View File

@ -139,7 +139,7 @@ function mcl_maps.create_map(pos)
return itemstack return itemstack
end end
function mcl_maps.load_map(id) function mcl_maps.load_map(id, callback)
if id == "" or creating_maps[id] then if id == "" or creating_maps[id] then
return return
end end
@ -152,16 +152,19 @@ function mcl_maps.load_map(id)
-- Minetest 5.3 and 5.4 until media loads -- Minetest 5.3 and 5.4 until media loads
loaded_maps[id] = true loaded_maps[id] = true
dynamic_add_media(map_textures_path .. texture, function() end) dynamic_add_media(map_textures_path .. texture, function() end)
if callback then callback(texture) end
else else
-- minetest.dynamic_add_media() never blocks -- minetest.dynamic_add_media() never blocks
-- in Minetest 5.5, callback runs after load -- in Minetest 5.5, callback runs after load
dynamic_add_media(map_textures_path .. texture, function() dynamic_add_media(map_textures_path .. texture, function()
loaded_maps[id] = true loaded_maps[id] = true
if callback then callback(texture) end
end) end)
end end
end end
if loaded_maps[id] then if loaded_maps[id] then
if callback then callback(texture) end
return texture return texture
end end
end end