Compare commits

...

1 Commits

Author SHA1 Message Date
cora 20c1922207 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
2022-09-23 18:45:36 +02:00
1 changed files with 20 additions and 0 deletions

View File

@ -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})