Modify mcl_entity_invs to add support for save/load items hooks in entities, add save/load hooks to minecarts to store item list in the minecart data and not in the entity data so that respawn doesn't destroy items
This commit is contained in:
parent
09bd2647f5
commit
30b7e34b14
|
@ -35,7 +35,9 @@ function mcl_entity_invs.load_inv(ent,size)
|
||||||
mcl_log("load_inv 3")
|
mcl_log("load_inv 3")
|
||||||
inv = minetest.create_detached_inventory(ent._inv_id, inv_callbacks)
|
inv = minetest.create_detached_inventory(ent._inv_id, inv_callbacks)
|
||||||
inv:set_size("main", size)
|
inv:set_size("main", size)
|
||||||
if ent._items then
|
if ent._mcl_entity_invs_load_items then
|
||||||
|
inv:set_list("main",ent:_mcl_entity_invs_load_items())
|
||||||
|
elseif ent._items then
|
||||||
inv:set_list("main",ent._items)
|
inv:set_list("main",ent._items)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -46,9 +48,14 @@ end
|
||||||
|
|
||||||
function mcl_entity_invs.save_inv(ent)
|
function mcl_entity_invs.save_inv(ent)
|
||||||
if ent._inv then
|
if ent._inv then
|
||||||
ent._items = {}
|
local items = {}
|
||||||
for i,it in ipairs(ent._inv:get_list("main")) do
|
for i,it in ipairs(ent._inv:get_list("main")) do
|
||||||
ent._items[i] = it:to_string()
|
items[i] = it:to_string()
|
||||||
|
end
|
||||||
|
if ent._mcl_entity_invs_save_items then
|
||||||
|
ent:_mcl_entity_invs_save_items(items)
|
||||||
|
else
|
||||||
|
ent._items = items
|
||||||
end
|
end
|
||||||
minetest.remove_detached_inventory(ent._inv_id)
|
minetest.remove_detached_inventory(ent._inv_id)
|
||||||
ent._inv = nil
|
ent._inv = nil
|
||||||
|
|
|
@ -143,6 +143,16 @@ function DEFAULT_CART_DEF:get_staticdata()
|
||||||
return minetest.serialize({uuid = self._staticdata.uuid, seq=self._seq})
|
return minetest.serialize({uuid = self._staticdata.uuid, seq=self._seq})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DEFAULT_CART_DEF:_mcl_entity_invs_load_items()
|
||||||
|
local staticdata = self._staticdata
|
||||||
|
return staticdata.inventory or {}
|
||||||
|
end
|
||||||
|
function DEFAULT_CART_DEF:_mcl_entity_invs_save_items(items)
|
||||||
|
local staticdata = self._staticdata
|
||||||
|
print("Saving entity inventory items="..dump(items))
|
||||||
|
staticdata.inventory = table.copy(items)
|
||||||
|
end
|
||||||
|
|
||||||
function DEFAULT_CART_DEF:add_node_watch(pos)
|
function DEFAULT_CART_DEF:add_node_watch(pos)
|
||||||
local staticdata = self._staticdata
|
local staticdata = self._staticdata
|
||||||
local watches = staticdata.node_watches or {}
|
local watches = staticdata.node_watches or {}
|
||||||
|
@ -246,7 +256,6 @@ function DEFAULT_CART_DEF:on_step(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
mod.update_cart_orientation(self)
|
mod.update_cart_orientation(self)
|
||||||
|
|
||||||
end
|
end
|
||||||
function mod.kill_cart(staticdata)
|
function mod.kill_cart(staticdata)
|
||||||
local pos
|
local pos
|
||||||
|
|
Loading…
Reference in New Issue