init.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 loco_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. if color and color:find("^#%x%x%x%x%x%x$") then
  12. data.livery = self.base_texture.."^("..self.base_livery.."^[multiply:"..color..")" -- livery texture has no own texture....
  13. self:set_textures(data)
  14. end
  15. end
  16. local function loco_set_textures(self, data)
  17. if data.livery then
  18. self.object:set_properties({
  19. textures={data.livery}
  20. })
  21. end
  22. end
  23. advtrains.register_wagon("diesel_lokomotive", {
  24. mesh="advtrains_engine_diesel.b3d",
  25. textures = {"advtrains_engine_diesel.png"},
  26. is_locomotive=true,
  27. drives_on={default=true},
  28. max_speed=10,
  29. seats = {
  30. {
  31. name = S("Driver Stand (left)"),
  32. attach_offset = {x=-3, y=2, z=-2},
  33. view_offset = {x=-4, y=3, z=0},
  34. group = "dstand",
  35. },
  36. {
  37. name = S("Trainee Seat (right)"),
  38. attach_offset = {x=3, y=2, z=-2},
  39. view_offset = {x=4, y=3, z=0},
  40. group = "tseat",
  41. },
  42. },
  43. seat_groups = {
  44. dstand = {
  45. name = "Driver Stand",
  46. access_to = {"tseat"},
  47. driving_ctrl_access = true,
  48. },
  49. tseat = {
  50. name = "Trainee Seat",
  51. access_to = {"dstand"},
  52. driving_ctrl_access = false,
  53. },
  54. },
  55. assign_to_seat_group = {"dstand", "tseat"},
  56. visual_size = {x=1, y=1},
  57. wagon_span = 1.95,
  58. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  59. base_texture = "advtrains_engine_diesel.png",
  60. base_livery = "advtrains_engine_diesel_livery.png",
  61. set_textures = loco_set_textures,
  62. set_livery = loco_set_livery,
  63. update_animation=function(self, velocity)
  64. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  65. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
  66. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  67. end
  68. end,
  69. custom_on_activate = function(self, staticdata_table, dtime_s)
  70. minetest.add_particlespawner({
  71. amount = 10,
  72. time = 0,
  73. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  74. minpos = {x=0, y=2.5, z=0.9},
  75. maxpos = {x=0, y=2.5, z=0.9},
  76. minvel = {x=-0.2, y=1.8, z=-0.2},
  77. maxvel = {x=0.2, y=2, z=0.2},
  78. minacc = {x=0, y=-0.1, z=0},
  79. maxacc = {x=0, y=-0.3, z=0},
  80. minexptime = 2,
  81. maxexptime = 4,
  82. minsize = 1,
  83. maxsize = 4,
  84. -- ^ The particle's properties are random values in between the bounds:
  85. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  86. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  87. collisiondetection = true,
  88. -- ^ collisiondetection: if true uses collision detection
  89. vertical = false,
  90. -- ^ vertical: if true faces player using y axis only
  91. texture = "smoke_puff.png",
  92. -- ^ Uses texture (string)
  93. attached = self.object,
  94. })
  95. end,
  96. drops={"advtrains:diesel_lokomotive"},
  97. horn_sound = "advtrains_engine_diesel_horn",
  98. glow = 1
  99. }, S("Diesel Engine"), "advtrains_engine_diesel_inv.png")
  100. advtrains.register_wagon("wagon_gravel", {
  101. mesh="advtrains_wagon_gravel.b3d",
  102. textures = {"advtrains_wagon_gravel.png"},
  103. drives_on={default=true},
  104. max_speed=10,
  105. seats = {},
  106. visual_size = {x=1, y=1},
  107. wagon_span=1.55,
  108. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  109. drops={"advtrains:wagon_gravel"},
  110. has_inventory = true,
  111. get_inventory_formspec = function(self, pname, invname)
  112. return "size[8,11]"..
  113. "list["..invname..";box;0,0;8,6;]"..
  114. "list[current_player;main;0,7;8,4;]"..
  115. "listring[]"
  116. end,
  117. inventory_list_sizes = {
  118. box=8*6,
  119. },
  120. }, S("Gravel Wagon"), "advtrains_wagon_gravel_inv.png")
  121. advtrains.register_wagon("wagon_track", {
  122. mesh="advtrains_wagon_stick.b3d",
  123. textures = {"advtrains_wagon_stick.png"},
  124. drives_on={default=true},
  125. max_speed=10,
  126. seats = {},
  127. visual_size = {x=1, y=1},
  128. wagon_span=1.55,
  129. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  130. drops={"advtrains:wagon_track"},
  131. has_inventory = true,
  132. get_inventory_formspec = function(self, pname, invname)
  133. return "size[8,11]"..
  134. "list["..invname..";box;0,0;8,6;]"..
  135. "list[current_player;main;0,7;8,4;]"..
  136. "listring[]"
  137. end,
  138. inventory_list_sizes = {
  139. box=8*6,
  140. },
  141. }, S("Track Wagon"), "advtrains_wagon_track_inv.png")
  142. advtrains.register_wagon("wagon_lava", {
  143. mesh="advtrains_wagon_lava.b3d",
  144. textures = {"advtrains_wagon_lava.png"},
  145. drives_on={default=true},
  146. max_speed=10,
  147. seats = {},
  148. visual_size = {x=1, y=1},
  149. wagon_span=1.55,
  150. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  151. drops={"advtrains:wagon_lava"},
  152. has_inventory = true,
  153. get_inventory_formspec = function(self, pname, invname)
  154. return "size[8,11]"..
  155. "list["..invname..";box;0,0;8,6;]"..
  156. "list[current_player;main;0,7;8,4;]"..
  157. "listring[]"
  158. end,
  159. inventory_list_sizes = {
  160. box=8*6,
  161. },
  162. }, S("Lava Wagon"), "advtrains_wagon_lava_inv.png")
  163. advtrains.register_wagon("wagon_tree", {
  164. mesh="advtrains_wagon_tree.b3d",
  165. textures = {"advtrains_wagon_tree.png"},
  166. drives_on={default=true},
  167. max_speed=10,
  168. seats = {},
  169. visual_size = {x=1, y=1},
  170. wagon_span=1.55,
  171. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  172. drops={"advtrains:wagon_tree"},
  173. has_inventory = true,
  174. get_inventory_formspec = function(self, pname, invname)
  175. return "size[8,11]"..
  176. "list["..invname..";box;0,0;8,6;]"..
  177. "list[current_player;main;0,7;8,4;]"..
  178. "listring[]"
  179. end,
  180. inventory_list_sizes = {
  181. box=8*6,
  182. },
  183. }, S("Tree Wagon"), "advtrains_wagon_tree_inv.png")