diff options
author | orwell96 <orwell@bleipb.de> | 2018-06-19 19:49:24 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2018-06-19 19:49:24 +0200 |
commit | 08ac0f9c05c4623a2783749b1dee2dafa234cee6 (patch) | |
tree | e1ff64ecfcaf7688ef112b4b06f41e65a787dca2 /advtrains/wagons.lua | |
parent | eab240bdce187db0de7b2b2a20b8eabdb4bd3946 (diff) | |
download | advtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.tar.gz advtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.tar.bz2 advtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.zip |
Check for inventory existence before serializing, and do not create it again if it already exists.
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r-- | advtrains/wagons.lua | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 6cc0072..cb139da 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -77,23 +77,27 @@ function wagon:set_id(wid) if self.has_inventory then
--to be used later
- local inv=minetest.create_detached_inventory("advtrains_wgn_"..self.id, {
- allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
- return invcallback(wid, player:get_player_name(), count, 0)
- end,
- allow_put = function(inv, listname, index, stack, player)
- return invcallback(wid, player:get_player_name(), stack:get_count(), 0)
- end,
- allow_take = function(inv, listname, index, stack, player)
- return invcallback(wid, player:get_player_name(), stack:get_count(), 0)
+ local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.id})
+ -- create inventory, if not yet created
+ if not inv then
+ inv=minetest.create_detached_inventory("advtrains_wgn_"..self.id, {
+ allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
+ return invcallback(wid, player:get_player_name(), count, 0)
+ end,
+ allow_put = function(inv, listname, index, stack, player)
+ return invcallback(wid, player:get_player_name(), stack:get_count(), 0)
+ end,
+ allow_take = function(inv, listname, index, stack, player)
+ return invcallback(wid, player:get_player_name(), stack:get_count(), 0)
+ end
+ })
+ if data.ser_inv then
+ advtrains.deserialize_inventory(data.ser_inv, inv)
end
- })
- if data.ser_inv then
- advtrains.deserialize_inventory(data.ser_inv, inv)
- end
- if self.inventory_list_sizes then
- for lst, siz in pairs(self.inventory_list_sizes) do
- inv:set_size(lst, siz)
+ if self.inventory_list_sizes then
+ for lst, siz in pairs(self.inventory_list_sizes) do
+ inv:set_size(lst, siz)
+ end
end
end
end
|