aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-06-09 22:16:24 +0200
committerorwell96 <mono96.mml@gmail.com>2016-06-09 22:16:24 +0200
commit4e6c147d56c8cf31f80804da2250d90f8ef60d9d (patch)
tree42fa499884f613eb6d383bb967d11517e83f69cf
parentf9a7fa68b176f499375e1b6cbffcf5f2c52317e1 (diff)
downloadadvtrains-4e6c147d56c8cf31f80804da2250d90f8ef60d9d.tar.gz
advtrains-4e6c147d56c8cf31f80804da2250d90f8ef60d9d.tar.bz2
advtrains-4e6c147d56c8cf31f80804da2250d90f8ef60d9d.zip
check for object load via the getyaw trick and not by checking the object table
-rw-r--r--couple.lua4
-rw-r--r--trainlogic.lua4
-rw-r--r--wagons.lua16
3 files changed, 13 insertions, 11 deletions
diff --git a/couple.lua b/couple.lua
index 9f5cc83..eae5e1c 100644
--- a/couple.lua
+++ b/couple.lua
@@ -36,6 +36,10 @@ minetest.register_entity("advtrains:discouple", {
if not self.wagon then
self.object:remove()
end
+ --getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
+ if not self.wagon.object:getyaw() then
+ self.object:remove()
+ end
local velocityvec=self.wagon.object:getvelocity()
self.updatepct_timer=(self.updatepct_timer or 0)-dtime
if not self.old_velocity_vector or not vector.equals(velocityvec, self.old_velocity_vector) or self.updatepct_timer<=0 then--only send update packet if something changed
diff --git a/trainlogic.lua b/trainlogic.lua
index f7a9363..7d7fe9f 100644
--- a/trainlogic.lua
+++ b/trainlogic.lua
@@ -81,6 +81,10 @@ advtrains.save = function()
else
data.driver_name=nil
end
+ if data.discouple then
+ data.discouple.object:remove()
+ data.discouple=nil
+ end
end
--print(dump(advtrains.wagon_save))
datastr = minetest.serialize(advtrains.wagon_save)
diff --git a/wagons.lua b/wagons.lua
index 6e737d5..58dc458 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -129,7 +129,7 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
table.remove(self:train().trainparts, self.pos_in_trainparts)
advtrains.update_trainpart_properties(self.train_id)
advtrains.wagon_save[self.unique_id]=nil
- if self.discouple_id and minetest.object_refs[self.discouple_id] then minetest.object_refs[self.discouple_id]:remove() end
+ if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects
return
@@ -189,27 +189,21 @@ function wagon:on_step(dtime)
--DisCouple
if self.pos_in_trainparts and self.pos_in_trainparts>1 then
if gp.velocity==0 then
- if not self.discouple_id or not minetest.luaentities[self.discouple_id] then
+ if not self.discouple or not self.discouple.object:getyaw() then
local object=minetest.add_entity(pos, "advtrains:discouple")
if object then
- print("spawning discouple")
local le=object:get_luaentity()
le.wagon=self
--box is hidden when attached, so unuseful.
--object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0})
- --find in object_refs
- for aoi, compare in pairs(minetest.object_refs) do
- if compare==object then
- self.discouple_id=aoi
- end
- end
+ self.discouple=le
else
print("Couldn't spawn DisCouple")
end
end
else
- if self.discouple_id and minetest.luaentities[self.discouple_id] then
- minetest.object_refs[self.discouple_id]:remove()
+ if self.discouple and self.discouple.object:getyaw() then
+ self.discouple.object:remove()
end
end
end