aboutsummaryrefslogtreecommitdiff
path: root/wagons.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-06-09 21:50:11 +0200
committerorwell96 <mono96.mml@gmail.com>2016-06-09 21:50:11 +0200
commit77de1965f95924ffc9086786bcb22ec02d9a8e19 (patch)
tree96779f349b3d7ca7dc0565a0a67cafd4dcb537e8 /wagons.lua
parent14a71703321cd9d817275cb976fba10a0d6b4386 (diff)
downloadadvtrains-77de1965f95924ffc9086786bcb22ec02d9a8e19.tar.gz
advtrains-77de1965f95924ffc9086786bcb22ec02d9a8e19.tar.bz2
advtrains-77de1965f95924ffc9086786bcb22ec02d9a8e19.zip
fix discouple appearing on wrong side on flipped wagons, and show discouples only when train stands
Diffstat (limited to 'wagons.lua')
-rw-r--r--wagons.lua50
1 files changed, 28 insertions, 22 deletions
diff --git a/wagons.lua b/wagons.lua
index 69504a1..57553d5 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -156,28 +156,6 @@ function wagon:on_step(dtime)
self.initialized=true
end
- --DisCouple
- if self.pos_in_trainparts and self.pos_in_trainparts>1 then
- if not self.discouple_id or not minetest.luaentities[self.discouple_id] 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
- else
- print("Couldn't spawn DisCouple")
- end
- end
- end
-
--driver control
if self.driver and self.is_locomotive then
if self.driver:get_player_control_bits()~=self.old_player_control_bits then
@@ -205,6 +183,34 @@ function wagon:on_step(dtime)
end
local gp=self:train()
+
+ --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
+ 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
+ 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()
+ end
+ end
+ end
--for path to be available. if not, skip step
if not advtrains.get_or_create_path(self.train_id, gp) then
self.object:setvelocity({x=0, y=0, z=0})