diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-06-01 11:03:50 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-06-01 11:03:50 +0200 |
commit | 8954740dd756dc7e442aca3dfd25bf25faafe006 (patch) | |
tree | bce26a43b7ffb92d61f29201d8418f5e99ccbe3d /wagons.lua | |
parent | 04e48bab20c0f812b82adeb3099918b1ad4b91cb (diff) | |
download | advtrains-8954740dd756dc7e442aca3dfd25bf25faafe006.tar.gz advtrains-8954740dd756dc7e442aca3dfd25bf25faafe006.tar.bz2 advtrains-8954740dd756dc7e442aca3dfd25bf25faafe006.zip |
added discouple entity
Diffstat (limited to 'wagons.lua')
-rw-r--r-- | wagons.lua | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -127,6 +127,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
return
@@ -154,6 +155,28 @@ 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
@@ -251,7 +274,7 @@ function wagon:on_step(dtime) end
self.updatepct_timer=(self.updatepct_timer or 0)-dtime
- if true or not self.old_velocity_vector or not vector.equals(velocityvec, self.old_velocity_vector) or self.old_yaw~=yaw or self.updatepct_timer<=0 then--only send update packet if something changed
+ if not self.old_velocity_vector or not vector.equals(velocityvec, self.old_velocity_vector) or self.old_yaw~=yaw or self.updatepct_timer<=0 then--only send update packet if something changed
self.object:setpos(actual_pos)
self.object:setvelocity(velocityvec)
self.object:setyaw(yaw)
|