init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. local S = attrans
  2. -- length of the steam engine loop sound
  3. local SND_LOOP_LEN = 5
  4. advtrains.register_wagon("newlocomotive", {
  5. mesh="advtrains_engine_steam.b3d",
  6. textures = {"advtrains_engine_steam.png"},
  7. is_locomotive=true,
  8. drives_on={default=true},
  9. max_speed=10,
  10. seats = {
  11. {
  12. name=S("Driver Stand (left)"),
  13. attach_offset={x=-5, y=0, z=-10},
  14. view_offset={x=0, y=6, z=0},
  15. group = "dstand",
  16. },
  17. {
  18. name=S("Driver Stand (right)"),
  19. attach_offset={x=5, y=0, z=-10},
  20. view_offset={x=0, y=6, z=0},
  21. group = "dstand",
  22. },
  23. },
  24. seat_groups = {
  25. dstand={
  26. name = "Driver Stand",
  27. driving_ctrl_access=true,
  28. access_to = {},
  29. },
  30. },
  31. assign_to_seat_group = {"dstand"},
  32. coupler_types_front = {chain=true},
  33. coupler_types_back = {chain=true},
  34. visual_size = {x=1, y=1},
  35. wagon_span=2.3,
  36. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  37. custom_on_velocity_change=function(self, velocity)
  38. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  39. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
  40. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  41. end
  42. end,
  43. custom_on_activate = function(self, staticdata_table, dtime_s)
  44. minetest.add_particlespawner({
  45. amount = 10,
  46. time = 0,
  47. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  48. minpos = {x=0, y=2, z=1.2},
  49. maxpos = {x=0, y=2, z=1.2},
  50. minvel = {x=-0.2, y=1.8, z=-0.2},
  51. maxvel = {x=0.2, y=2, z=0.2},
  52. minacc = {x=0, y=-0.1, z=0},
  53. maxacc = {x=0, y=-0.3, z=0},
  54. minexptime = 2,
  55. maxexptime = 4,
  56. minsize = 1,
  57. maxsize = 5,
  58. -- ^ The particle's properties are random values in between the bounds:
  59. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  60. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  61. collisiondetection = true,
  62. -- ^ collisiondetection: if true uses collision detection
  63. vertical = false,
  64. -- ^ vertical: if true faces player using y axis only
  65. texture = "smoke_puff.png",
  66. -- ^ Uses texture (string)
  67. attached = self.object,
  68. })
  69. end,
  70. drops={"default:steelblock 1"},
  71. horn_sound = "advtrains_steam_whistle",
  72. }, S("Steam Engine"), "advtrains_engine_steam_inv.png")
  73. advtrains.register_wagon("detailed_steam_engine", {
  74. mesh="advtrains_detailed_steam_engine.b3d",
  75. textures = {"advtrains_detailed_steam_engine.png"},
  76. is_locomotive=true,
  77. drives_on={default=true},
  78. max_speed=10,
  79. seats = {
  80. {
  81. name=S("Driver Stand (left)"),
  82. attach_offset={x=-8, y=0, z=-10},
  83. view_offset={x=9, y=-2, z=-6},
  84. group = "dstand",
  85. },
  86. {
  87. name=S("Driver Stand (right)"),
  88. attach_offset={x=8, y=0, z=-10},
  89. view_offset={x=0, y=6, z=0},
  90. group = "dstand",
  91. },
  92. },
  93. seat_groups = {
  94. dstand={
  95. name = "Driver Stand",
  96. driving_ctrl_access=true,
  97. access_to = {},
  98. },
  99. },
  100. assign_to_seat_group = {"dstand"},
  101. coupler_types_front = {chain=true},
  102. coupler_types_back = {chain=true},
  103. visual_size = {x=1, y=1},
  104. wagon_span=2.05,
  105. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  106. custom_on_velocity_change=function(self, velocity)
  107. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  108. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
  109. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  110. end
  111. end,
  112. custom_on_step=function(self, dtime)
  113. if self:train().velocity > 0 then -- First make sure that the train isn't standing
  114. if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 then
  115. -- start the sound if it was never started or has expired
  116. self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object=self.object})
  117. self.sound_loop_tmr = SND_LOOP_LEN
  118. end
  119. --decrease the sound timer
  120. self.sound_loop_tmr = self.sound_loop_tmr - dtime
  121. else
  122. -- If the train is standing, the sound will be stopped in some time. We do not need to interfere with it.
  123. self.sound_loop_tmr = nil
  124. end
  125. end,
  126. custom_on_activate = function(self, staticdata_table, dtime_s)
  127. minetest.add_particlespawner({
  128. amount = 10,
  129. time = 0,
  130. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  131. minpos = {x=0, y=2.3, z=1.45},
  132. maxpos = {x=0, y=2.3, z=1.4},
  133. minvel = {x=-0.2, y=1.8, z=-0.2},
  134. maxvel = {x=0.2, y=2, z=0.2},
  135. minacc = {x=0, y=-0.1, z=0},
  136. maxacc = {x=0, y=-0.3, z=0},
  137. minexptime = 2,
  138. maxexptime = 4,
  139. minsize = 1,
  140. maxsize = 5,
  141. -- ^ The particle's properties are random values in between the bounds:
  142. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  143. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  144. collisiondetection = true,
  145. -- ^ collisiondetection: if true uses collision detection
  146. vertical = false,
  147. -- ^ vertical: if true faces player using y axis only
  148. texture = "smoke_puff.png",
  149. -- ^ Uses texture (string)
  150. attached = self.object,
  151. })
  152. end,
  153. drops={"default:steelblock 1"},
  154. horn_sound = "advtrains_steam_whistle",
  155. }, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png")
  156. advtrains.register_wagon("wagon_default", {
  157. mesh="advtrains_passenger_wagon.b3d",
  158. textures = {"advtrains_wagon.png"},
  159. drives_on={default=true},
  160. max_speed=10,
  161. seats = {
  162. {
  163. name="1",
  164. attach_offset={x=2, y=6, z=8},
  165. view_offset={x=0, y=-4, z=0},
  166. group="pass",
  167. },
  168. {
  169. name="2",
  170. attach_offset={x=-1, y=6, z=8},
  171. view_offset={x=0, y=-4, z=0},
  172. group="pass",
  173. },
  174. {
  175. name="3",
  176. attach_offset={x=-4, y=8, z=-8},
  177. view_offset={x=0, y=0, z=0},
  178. group="pass",
  179. },
  180. {
  181. name="4",
  182. attach_offset={x=4, y=8, z=-8},
  183. view_offset={x=0, y=0, z=0},
  184. group="pass",
  185. },
  186. },
  187. seat_groups = {
  188. pass={
  189. name = "Passenger area",
  190. access_to = {},
  191. },
  192. },
  193. assign_to_seat_group = {"pass"},
  194. coupler_types_front = {chain=true},
  195. coupler_types_back = {chain=true},
  196. visual_size = {x=1, y=1},
  197. wagon_span=2.634,
  198. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  199. drops={"default:steelblock 1"},
  200. }, S("Passenger Wagon"), "advtrains_wagon_inv.png")
  201. advtrains.register_wagon("wagon_box", {
  202. mesh="advtrains_wagon_box.b3d",
  203. textures = {"advtrains_wagon_box.png"},
  204. drives_on={default=true},
  205. max_speed=10,
  206. seats = {},
  207. coupler_types_front = {chain=true},
  208. coupler_types_back = {chain=true},
  209. visual_size = {x=1, y=1},
  210. wagon_span=2,
  211. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  212. drops={"default:steelblock 1"},
  213. has_inventory = true,
  214. get_inventory_formspec = advtrains.standard_inventory_formspec,
  215. inventory_list_sizes = {
  216. box=8*3,
  217. },
  218. }, S("Box Wagon"), "advtrains_wagon_box_inv.png")
  219. minetest.register_craft({
  220. output = 'advtrains:newlocomotive',
  221. recipe = {
  222. {'', '', 'advtrains:chimney'},
  223. {'advtrains:driver_cab', 'dye:black', 'advtrains:boiler'},
  224. {'advtrains:wheel', 'advtrains:wheel', 'advtrains:wheel'},
  225. },
  226. })
  227. minetest.register_craft({
  228. output = 'advtrains:detailed_steam_engine',
  229. recipe = {
  230. {'', '', 'advtrains:chimney'},
  231. {'advtrains:driver_cab', 'dye:green', 'advtrains:boiler'},
  232. {'advtrains:wheel', 'advtrains:wheel', 'advtrains:wheel'},
  233. },
  234. })
  235. minetest.register_craft({
  236. output = 'advtrains:wagon_default',
  237. recipe = {
  238. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  239. {'default:glass', 'dye:dark_green', 'default:glass'},
  240. {'advtrains:wheel', 'advtrains:wheel', 'advtrains:wheel'},
  241. },
  242. })
  243. minetest.register_craft({
  244. output = 'advtrains:wagon_box',
  245. recipe = {
  246. {'group:wood', 'group:wood', 'group:wood'},
  247. {'group:wood', 'default:chest', 'group:wood'},
  248. {'advtrains:wheel', '', 'advtrains:wheel'},
  249. },
  250. })