mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
mcl_maps: add callback to load_map function (#2261)
Fixes maps in itemframes not loading after restart (#2255) Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2261 Co-authored-by: Elias Fleckenstein <eliasfleckenstein@web.de> Co-committed-by: Elias Fleckenstein <eliasfleckenstein@web.de>
This commit is contained in:
parent
50c802df98
commit
a86fc935aa
@ -64,7 +64,10 @@ minetest.register_entity("mcl_itemframes:map", {
|
||||
},
|
||||
on_activate = function(self, 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,
|
||||
get_staticdata = function(self)
|
||||
return self.id
|
||||
|
@ -139,7 +139,7 @@ function mcl_maps.create_map(pos)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function mcl_maps.load_map(id)
|
||||
function mcl_maps.load_map(id, callback)
|
||||
if id == "" or creating_maps[id] then
|
||||
return
|
||||
end
|
||||
@ -152,16 +152,19 @@ function mcl_maps.load_map(id)
|
||||
-- Minetest 5.3 and 5.4 until media loads
|
||||
loaded_maps[id] = true
|
||||
dynamic_add_media(map_textures_path .. texture, function() end)
|
||||
if callback then callback(texture) end
|
||||
else
|
||||
-- minetest.dynamic_add_media() never blocks
|
||||
-- in Minetest 5.5, callback runs after load
|
||||
dynamic_add_media(map_textures_path .. texture, function()
|
||||
loaded_maps[id] = true
|
||||
if callback then callback(texture) end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
if loaded_maps[id] then
|
||||
if callback then callback(texture) end
|
||||
return texture
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user