From 20c1922207f8e4bc2251e47cc814d6ecf0ea4bfa Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 23 Sep 2022 18:45:36 +0200 Subject: [PATCH] Detached inventory on_deactivate test a 2nd "Testy" inv will be created with every inv-entity on this testing branch which you can access with /invtest. This was to verify that on_deactivate is in fact called by /clearobjects: place a chest boat, run /invtest - verify the inventory works run /clearobjects - verify the inv no longer works --- mods/ENTITIES/mcl_entity_invs/init.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mods/ENTITIES/mcl_entity_invs/init.lua b/mods/ENTITIES/mcl_entity_invs/init.lua index 3255b84f4..19877fc83 100644 --- a/mods/ENTITIES/mcl_entity_invs/init.lua +++ b/mods/ENTITIES/mcl_entity_invs/init.lua @@ -25,7 +25,9 @@ local function load_inv(ent,size) local inv = minetest.get_inventory({type="detached", name=ent._inv_id}) if not inv then inv = minetest.create_detached_inventory(ent._inv_id, inv_callbacks) + invt = minetest.create_detached_inventory("testy", {}) inv:set_size("main", size) + invt:set_size("main", size) if ent._items then inv:set_list("main",ent._items) end @@ -98,6 +100,7 @@ function mcl_entity_invs.register_inv(entity_name,show_name,size) local old_ode = minetest.registered_entities[entity_name].on_deactivate minetest.registered_entities[entity_name].on_deactivate = function(self,removal) minetest.remove_detached_inventory(self._inv_id) + minetest.remove_detached_inventory("testy") if old_ode then return old_ode(self,removal) end end @@ -108,3 +111,20 @@ function mcl_entity_invs.register_inv(entity_name,show_name,size) if old_od then return old_od(self,clicker) end end end + +minetest.register_chatcommand("invtest",{func=function(n,p) + local formspec = "size[9,8.75]" + .. "label[0,0;" .. minetest.formspec_escape( + minetest.colorize("#313131", "Testy")) .. "]" + .. "list[detached:testy;main;0,0.5;9,3;]" + .. mcl_formspec.get_itemslot_bg(0,0.5,9,3) + .. "label[0,4.0;" .. minetest.formspec_escape( + minetest.colorize("#313131", "Inventory")) .. "]" + .. "list[current_player;main;0,4.5;9,3;9]" + .. mcl_formspec.get_itemslot_bg(0,4.5,9,3) + .. "list[current_player;main;0,7.74;9,1;]" + .. mcl_formspec.get_itemslot_bg(0,7.74,9,1) + .. "listring[detached:testy;main]" + .. "listring[current_player;main]" + minetest.show_formspec(n,"testy",formspec) +end})