aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-06-19 19:49:24 +0200
committerorwell96 <orwell@bleipb.de>2018-06-19 19:49:24 +0200
commit08ac0f9c05c4623a278/* Minetest Copyright (C) 2010-2018 nerzhul, Loic BLOT <loic.blot@unix-experience.fr> This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include <unordered_map> #include "irrlichttypes.h" class TestClientActiveObjectMgr; class TestServerActiveObjectMgr;
- wdata.ser_inv=advtrains.serialize_inventory(inv)
+ if inv then -- inventory is not initialized when wagon was never loaded
+ -- TOOD: What happens with unloading rails when they don't find the inventory?
+ wdata.ser_inv=advtrains.serialize_inventory(inv)
+ end
end
-- TODO apply save-keys here too
end
@@ -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