init.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. local S = attrans
  2. -- note: scharfenberg coupler is defined in advtrains core
  3. advtrains.register_coupler_type("train_japan_interwagon", attrans("Japanese Train Inter-Wagon Connection"))
  4. local function set_livery(self, puncher, itemstack, data)
  5. local meta = itemstack:get_meta()
  6. local color = meta:get_string("paint_color")
  7. if color and color:find("^#%x%x%x%x%x%x$") then
  8. local alpha = tonumber(meta:get_string("alpha"))
  9. if alpha == 0 then
  10. data.livery = self.base_texture
  11. else
  12. data.livery = self.base_texture.."^("..self.base_livery.."^[colorize:"..color..":255)"
  13. end
  14. self:set_textures(data)
  15. end
  16. end
  17. local function set_textures(self, data)
  18. if data.livery then
  19. self.object:set_properties({textures={data.livery}})
  20. end
  21. end
  22. advtrains.register_wagon("engine_japan", {
  23. mesh="advtrains_engine_japan.b3d",
  24. textures = {"advtrains_engine_japan.png"},
  25. base_texture = "advtrains_engine_japan.png",
  26. base_livery = "advtrains_engine_japan_livery.png",
  27. set_textures = set_textures,
  28. set_livery = set_livery,
  29. drives_on={default=true},
  30. max_speed=20,
  31. seats = {
  32. {
  33. name=S("Driver stand"),
  34. attach_offset={x=0, y=-2, z=13},
  35. view_offset={x=0, y=0, z=0},
  36. group="dstand",
  37. },
  38. {
  39. name="1",
  40. attach_offset={x=-4, y=-2, z=0},
  41. view_offset={x=0, y=0, z=0},
  42. group="pass",
  43. },
  44. {
  45. name="2",
  46. attach_offset={x=4, y=-2, z=0},
  47. view_offset={x=0, y=0, z=0},
  48. group="pass",
  49. },
  50. {
  51. name="3",
  52. attach_offset={x=-4, y=-2, z=-8},
  53. view_offset={x=0, y=0, z=0},
  54. group="pass",
  55. },
  56. {
  57. name="4",
  58. attach_offset={x=4, y=-2, z=-8},
  59. view_offset={x=0, y=0, z=0},
  60. group="pass",
  61. },
  62. },
  63. seat_groups = {
  64. dstand={
  65. name = "Driver Stand",
  66. access_to = {"pass"},
  67. require_doors_open=true,
  68. driving_ctrl_access=true,
  69. },
  70. pass={
  71. name = "Passenger area",
  72. access_to = {"dstand"},
  73. require_doors_open=true,
  74. },
  75. },
  76. assign_to_seat_group = {"dstand", "pass"},
  77. doors={
  78. open={
  79. [-1]={frames={x=0, y=20}, time=1},
  80. [1]={frames={x=40, y=60}, time=1}
  81. },
  82. close={
  83. [-1]={frames={x=20, y=40}, time=1},
  84. [1]={frames={x=60, y=80}, time=1}
  85. }
  86. },
  87. coupler_types_front = {scharfenberg=true},
  88. coupler_types_back = {train_japan_interwagon=true},
  89. door_entry={-1.7},
  90. visual_size = {x=1, y=1},
  91. wagon_span=2.5,
  92. wheel_positions = {1.5, -2.5},
  93. is_locomotive=true,
  94. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  95. drops={"default:steelblock 4"},
  96. horn_sound = "advtrains_japan_horn",
  97. }, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png")
  98. advtrains.register_wagon("wagon_japan", {
  99. mesh="advtrains_wagon_japan.b3d",
  100. textures = {"advtrains_wagon_japan.png"},
  101. base_texture = "advtrains_wagon_japan.png",
  102. base_livery = "advtrains_wagon_japan_livery.png",
  103. set_textures = set_textures,
  104. set_livery = set_livery,
  105. drives_on={default=true},
  106. max_speed=20,
  107. seats = {
  108. {
  109. name="1",
  110. attach_offset={x=-4, y=-2, z=8},
  111. view_offset={x=0, y=0, z=0},
  112. group="pass",
  113. },
  114. {
  115. name="2",
  116. attach_offset={x=4, y=-2, z=8},
  117. view_offset={x=0, y=0, z=0},
  118. group="pass",
  119. },
  120. {
  121. name="1a",
  122. attach_offset={x=-4, y=-2, z=0},
  123. view_offset={x=0, y=0, z=0},
  124. group="pass",
  125. },
  126. {
  127. name="2a",
  128. attach_offset={x=4, y=-2, z=0},
  129. view_offset={x=0, y=0, z=0},
  130. group="pass",
  131. },
  132. {
  133. name="3",
  134. attach_offset={x=-4, y=-2, z=-8},
  135. view_offset={x=0, y=0, z=0},
  136. group="pass",
  137. },
  138. {
  139. name="4",
  140. attach_offset={x=4, y=8, z=-8},
  141. view_offset={x=0, y=0, z=0},
  142. group="pass",
  143. },
  144. },
  145. seat_groups = {
  146. pass={
  147. name = "Passenger area",
  148. access_to = {},
  149. require_doors_open=true,
  150. },
  151. },
  152. assign_to_seat_group = {"pass"},
  153. doors={
  154. open={
  155. [-1]={frames={x=0, y=20}, time=1},
  156. [1]={frames={x=40, y=60}, time=1}
  157. },
  158. close={
  159. [-1]={frames={x=20, y=40}, time=1},
  160. [1]={frames={x=60, y=80}, time=1}
  161. }
  162. },
  163. coupler_types_front = {train_japan_interwagon=true},
  164. coupler_types_back = {train_japan_interwagon=true},
  165. door_entry={-1.7, 1.7},
  166. visual_size = {x=1, y=1},
  167. wagon_span=2.3,
  168. wheel_positions = {2.3, -2.3},
  169. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  170. drops={"default:steelblock 4"},
  171. }, S("Japanese Train Wagon"), "advtrains_wagon_japan_inv.png")
  172. -- Crafting
  173. minetest.register_craft({
  174. output = 'advtrains:engine_japan',
  175. recipe = {
  176. {'default:steelblock', 'default:steelblock', ''},
  177. {'xpanes:pane_flat', 'default:steelblock', 'xpanes:pane_flat'},
  178. {'advtrains:wheel', 'advtrains:wheel', 'advtrains:wheel'},
  179. },
  180. })
  181. minetest.register_craft({
  182. output = 'advtrains:wagon_japan',
  183. recipe = {
  184. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  185. {'xpanes:pane_flat', 'default:steelblock', 'xpanes:pane_flat'},
  186. {'advtrains:wheel', '', 'advtrains:wheel'},
  187. },
  188. })