From a86fc935aa4a14700c84e0226c600652ec51255d Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 30 May 2022 01:32:20 +0000 Subject: [PATCH] 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 Co-committed-by: Elias Fleckenstein --- mods/ITEMS/mcl_itemframes/init.lua | 5 ++++- mods/ITEMS/mcl_maps/init.lua | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 364bffee6..eac5b066b 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -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 diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index 450d8fbad..fb13625d5 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -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