init.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. local S
  2. if minetest.get_modpath("intllib") then
  3. S = intllib.Getter()
  4. else
  5. S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
  6. end
  7. local function jr_set_livery(self, puncher, itemstack,data)
  8. -- Get color data
  9. local meta = itemstack:get_meta()
  10. local color = meta:get_string("paint_color")
  11. local alpha = tonumber(meta:get_string("alpha"))
  12. if color and color:find("^#%x%x%x%x%x%x$") then
  13. data.livery = self.base_texture.."^("..self.base_livery.."^[colorize:"..color..":255)" -- livery texture has no own texture....
  14. self:set_textures(data)
  15. end
  16. end
  17. local function jr_set_textures(self, data)
  18. if data.livery then
  19. self.object:set_properties({
  20. textures={data.livery}
  21. })
  22. end
  23. end
  24. advtrains.register_wagon("KuHa_E231", {
  25. mesh="advtrains_KuHa_E231.b3d",
  26. textures = {"advtrains_KuHa_E231.png"},
  27. drives_on={default=true},
  28. max_speed=20,
  29. seats = {
  30. {
  31. name=S("Driver stand"),
  32. attach_offset={x=0, y=8, z=18},
  33. view_offset={x=0, y=0, z=0},
  34. driving_ctrl_access=true,
  35. group="dstand",
  36. },
  37. {
  38. name="1",
  39. attach_offset={x=-4, y=8, z=0},
  40. view_offset={x=0, y=0, z=0},
  41. group="pass",
  42. },
  43. {
  44. name="2",
  45. attach_offset={x=4, y=8, z=0},
  46. view_offset={x=0, y=0, z=0},
  47. group="pass",
  48. },
  49. {
  50. name="3",
  51. attach_offset={x=-4, y=8, z=-8},
  52. view_offset={x=0, y=0, z=0},
  53. group="pass",
  54. },
  55. {
  56. name="4",
  57. attach_offset={x=4, y=8, z=-8},
  58. view_offset={x=0, y=0, z=0},
  59. group="pass",
  60. },
  61. },
  62. seat_groups = {
  63. dstand={
  64. name = "Driver Stand",
  65. access_to = {"pass"},
  66. require_doors_open=true,
  67. driving_ctrl_access=true,
  68. },
  69. pass={
  70. name = "Passenger area",
  71. access_to = {"dstand"},
  72. require_doors_open=true,
  73. },
  74. },
  75. assign_to_seat_group = {"dstand", "pass"},
  76. doors={
  77. open={
  78. [-1]={frames={x=0, y=40}, time=1},
  79. [1]={frames={x=80, y=120}, time=1},
  80. sound = "advtrains_train_jre231_door_chime",
  81. },
  82. close={
  83. [-1]={frames={x=40, y=80}, time=1},
  84. [1]={frames={x=120, y=160}, time=1},
  85. sound = "advtrains_train_jre231_door_chime",
  86. }
  87. },
  88. door_entry={-1},
  89. assign_to_seat_group = {"dstand", "pass"},
  90. visual_size = {x=1, y=1},
  91. wagon_span=2.5,
  92. is_locomotive=true,
  93. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  94. drops={"default:steelblock 4"},
  95. horn_sound = "advtrains_train_jre231_horn",
  96. base_texture = "advtrains_KuHa_E231.png",
  97. base_livery = "advtrains_KuHa_E231_livery.png",
  98. set_textures = jr_set_textures,
  99. set_livery = jr_set_livery,
  100. custom_on_velocity_change = function(self, velocity, old_velocity, dtime)
  101. if not velocity or not old_velocity then return end
  102. if old_velocity == 0 and velocity > 0 then
  103. if self.sound_arrive_handle then
  104. minetest.sound_stop(self.sound_arrive_handle)
  105. self.sound_arrive_handle = nil
  106. end
  107. self.sound_depart_handle = minetest.sound_play("advtrains_train_jre231_depart", {object = self.object})
  108. end
  109. if velocity < 2 and (old_velocity >= 2 or old_velocity == velocity) and not self.sound_arrive_handle then
  110. if self.sound_depart_handle then
  111. minetest.sound_stop(self.sound_depart_handle)
  112. self.sound_depart_handle = nil
  113. end
  114. self.sound_arrive_handle = minetest.sound_play("advtrains_train_jre231_arrive", {object = self.object})
  115. elseif (velocity > old_velocity) and self.sound_arrive_handle then
  116. minetest.sound_stop(self.sound_arrive_handle)
  117. self.sound_arrive_handle = nil
  118. end
  119. end,
  120. }, S("KuHa_E231"), "advtrains_KuHa_E231_inv.png^advtrains_jre231_inv_overlay_right.png^advtrains_jre231_inv_overlay_middle.png")
  121. advtrains.register_wagon("MoHa_E231", {
  122. mesh="advtrains_MoHa_E231.b3d",
  123. textures = {"advtrains_MoHa_E231.png"},
  124. drives_on={default=true},
  125. max_speed=20,
  126. seats = {
  127. {
  128. name="1",
  129. attach_offset={x=-4, y=8, z=8},
  130. view_offset={x=0, y=0, z=0},
  131. group="pass",
  132. },
  133. {
  134. name="2",
  135. attach_offset={x=4, y=8, z=8},
  136. view_offset={x=0, y=0, z=0},
  137. group="pass",
  138. },
  139. {
  140. name="1a",
  141. attach_offset={x=-4, y=8, z=0},
  142. view_offset={x=0, y=0, z=0},
  143. group="pass",
  144. },
  145. {
  146. name="2a",
  147. attach_offset={x=4, y=8, z=0},
  148. view_offset={x=0, y=0, z=0},
  149. group="pass",
  150. },
  151. {
  152. name="3",
  153. attach_offset={x=-4, y=8, z=-8},
  154. view_offset={x=0, y=0, z=0},
  155. group="pass",
  156. },
  157. {
  158. name="4",
  159. attach_offset={x=4, y=8, z=-8},
  160. view_offset={x=0, y=0, z=0},
  161. group="pass",
  162. },
  163. },
  164. seat_groups = {
  165. pass={
  166. name = "Passenger area",
  167. access_to = {},
  168. require_doors_open=true,
  169. },
  170. },
  171. assign_to_seat_group = {"pass"},
  172. doors={
  173. open={
  174. [-1]={frames={x=0, y=40}, time=1},
  175. [1]={frames={x=80, y=120}, time=1},
  176. sound = "advtrains_train_jre231_door_chime",
  177. },
  178. close={
  179. [-1]={frames={x=40, y=80}, time=1},
  180. [1]={frames={x=120, y=160}, time=1},
  181. sound = "advtrains_train_jre231_door_chime",
  182. }
  183. },
  184. door_entry={-1, 1},
  185. visual_size = {x=1, y=1},
  186. wagon_span=2.3,
  187. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  188. base_texture = "advtrains_MoHa_E231.png",
  189. base_livery = "advtrains_MoHa_E231_livery.png",
  190. set_textures = jr_set_textures,
  191. set_livery = jr_set_livery,
  192. drops={"default:steelblock 4"},
  193. }, S("MoHa_E231"), "advtrains_MoHa_E231_inv.png^advtrains_jre231_inv_overlay_middle.png^advtrains_jre231_inv_overlay_left.png^advtrains_jre231_inv_overlay_right.png^advtrains_jre231_inv_overlay_top.png")
  194. advtrains.register_wagon("SaHa_E231", {
  195. mesh="advtrains_SaHa_E231.b3d",
  196. textures = {"advtrains_SaHa_E231.png"},
  197. drives_on={default=true},
  198. max_speed=20,
  199. seats = {
  200. {
  201. name="1",
  202. attach_offset={x=-4, y=8, z=8},
  203. view_offset={x=0, y=0, z=0},
  204. group="pass",
  205. },
  206. {
  207. name="2",
  208. attach_offset={x=4, y=8, z=8},
  209. view_offset={x=0, y=0, z=0},
  210. group="pass",
  211. },
  212. {
  213. name="1a",
  214. attach_offset={x=-4, y=8, z=0},
  215. view_offset={x=0, y=0, z=0},
  216. group="pass",
  217. },
  218. {
  219. name="2a",
  220. attach_offset={x=4, y=8, z=0},
  221. view_offset={x=0, y=0, z=0},
  222. group="pass",
  223. },
  224. {
  225. name="3",
  226. attach_offset={x=-4, y=8, z=-8},
  227. view_offset={x=0, y=0, z=0},
  228. group="pass",
  229. },
  230. {
  231. name="4",
  232. attach_offset={x=4, y=8, z=-8},
  233. view_offset={x=0, y=0, z=0},
  234. group="pass",
  235. },
  236. },
  237. seat_groups = {
  238. pass={
  239. name = "Passenger area",
  240. access_to = {},
  241. require_doors_open=true,
  242. },
  243. },
  244. assign_to_seat_group = {"pass"},
  245. doors={
  246. open={
  247. [-1]={frames={x=0, y=40}, time=1},
  248. [1]={frames={x=80, y=120}, time=1},
  249. sound = "advtrains_train_jre231_door_chime",
  250. },
  251. close={
  252. [-1]={frames={x=40, y=80}, time=1},
  253. [1]={frames={x=120, y=160}, time=1},
  254. sound = "advtrains_train_jre231_door_chime",
  255. }
  256. },
  257. door_entry={-1, 1},
  258. visual_size = {x=1, y=1},
  259. wagon_span=2.3,
  260. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  261. drops={"default:steelblock 4"},
  262. base_texture = "advtrains_SaHa_E231.png",
  263. base_livery = "advtrains_MoHa_E231_livery.png",
  264. set_textures = jr_set_textures,
  265. set_livery = jr_set_livery,
  266. }, S("SaHa_E231"), "advtrains_SaHa_E231_inv.png^advtrains_jre231_inv_overlay_left.png^advtrains_jre231_inv_overlay_right.png")
  267. advtrains.register_wagon("MoHa_E230", {
  268. mesh="advtrains_MoHa_E230.b3d",
  269. textures = {"advtrains_MoHa_E230.png"},
  270. drives_on={default=true},
  271. max_speed=20,
  272. seats = {
  273. {
  274. name="1",
  275. attach_offset={x=-4, y=8, z=8},
  276. view_offset={x=0, y=0, z=0},
  277. group="pass",
  278. },
  279. {
  280. name="2",
  281. attach_offset={x=4, y=8, z=8},
  282. view_offset={x=0, y=0, z=0},
  283. group="pass",
  284. },
  285. {
  286. name="1a",
  287. attach_offset={x=-4, y=8, z=0},
  288. view_offset={x=0, y=0, z=0},
  289. group="pass",
  290. },
  291. {
  292. name="2a",
  293. attach_offset={x=4, y=8, z=0},
  294. view_offset={x=0, y=0, z=0},
  295. group="pass",
  296. },
  297. {
  298. name="3",
  299. attach_offset={x=-4, y=8, z=-8},
  300. view_offset={x=0, y=0, z=0},
  301. group="pass",
  302. },
  303. {
  304. name="4",
  305. attach_offset={x=4, y=8, z=-8},
  306. view_offset={x=0, y=0, z=0},
  307. group="pass",
  308. },
  309. },
  310. seat_groups = {
  311. pass={
  312. name = "Passenger area",
  313. access_to = {},
  314. require_doors_open=true,
  315. },
  316. },
  317. assign_to_seat_group = {"pass"},
  318. doors={
  319. open={
  320. [-1]={frames={x=0, y=40}, time=1},
  321. [1]={frames={x=80, y=120}, time=1},
  322. sound = "advtrains_train_jre231_door_chime",
  323. },
  324. close={
  325. [-1]={frames={x=40, y=80}, time=1},
  326. [1]={frames={x=120, y=160}, time=1},
  327. sound = "advtrains_train_jre231_door_chime",
  328. }
  329. },
  330. door_entry={-1, 1},
  331. visual_size = {x=1, y=1},
  332. wagon_span=2.3,
  333. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  334. base_texture = "advtrains_MoHa_E230.png",
  335. base_livery = "advtrains_MoHa_E231_livery.png",
  336. set_textures = jr_set_textures,
  337. set_livery = jr_set_livery,
  338. drops={"default:steelblock 4"},
  339. }, S("MoHa_E230"), "advtrains_MoHa_E230_inv.png^advtrains_jre231_inv_overlay_middle.png^advtrains_jre231_inv_overlay_left.png^advtrains_jre231_inv_overlay_right.png")