Do not recover wagons from minetest's static storage
authororwell96 <mono96.mml@gmail.com>
Mon, 23 Jan 2017 20:36:38 +0000 (21:36 +0100)
committerorwell96 <mono96.mml@gmail.com>
Mon, 23 Jan 2017 20:36:38 +0000 (21:36 +0100)
Since missing wagons are spawned anyway by update_trainpart_properties, this only causes visible trouble when a train gets into loaded area. also avoids placing entities into unloaded terrain randomly.

advtrains/advtrains/wagons.lua

index 2729fd0..2e80fa6 100644 (file)
@@ -56,28 +56,13 @@ end
        wagon will save only uid in staticdata, no serialized table\r
 ]]\r
 function wagon:on_activate(sd_uid, dtime_s)\r
-       atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
-       self.object:set_armor_groups({immortal=1})\r
-       if sd_uid and sd_uid~="" then\r
-               --legacy\r
-               --expect this to be a serialized table and handle\r
-               if minetest.deserialize(sd_uid) then\r
-                       self:init_from_wagon_save(minetest.deserialize(sd_uid).unique_id)\r
-               else\r
-                       self:init_from_wagon_save(sd_uid)\r
-               end\r
+       if sd_uid~="" then\r
+               --destroy when loaded from static block.\r
+               self.object:remove()\r
+               return\r
        end\r
+       self.object:set_armor_groups({immortal=1})\r
        self.entity_name=self.name\r
-       \r
-       --duplicates?\r
-       for ao_id,wagon in pairs(minetest.luaentities) do\r
-               if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!\r
-                       atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
-                       self.object:remove()\r
-                       minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)\r
-                       return\r
-               end\r
-       end\r
 end\r
 \r
 function wagon:get_staticdata()\r