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 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..":"..alpha..")" -- 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("diesel_lokomotive", {
  25. mesh="advtrains_engine_diesel.b3d",
  26. textures = {"advtrains_engine_diesel.png"},
  27. is_locomotive=true,
  28. drives_on={default=true},
  29. max_speed=10,
  30. seats = {
  31. {
  32. name = S("Driver Stand (left)"),
  33. attach_offset = {x=-3, y=2, z=-2},
  34. view_offset = {x=-4, y=3, z=0},
  35. group = "dstand",
  36. },
  37. {
  38. name = S("Trainee Seat (right)"),
  39. attach_offset = {x=3, y=2, z=-2},
  40. view_offset = {x=4, y=3, z=0},
  41. group = "tseat",
  42. },
  43. },
  44. seat_groups = {
  45. dstand = {
  46. name = "Driver Stand",
  47. access_to = {"tseat"},
  48. driving_ctrl_access = true,
  49. },
  50. tseat = {
  51. name = "Trainee Seat",
  52. access_to = {"dstand"},
  53. driving_ctrl_access = false,
  54. },
  55. },
  56. assign_to_seat_group = {"dstand", "tseat"},
  57. visual_size = {x=1, y=1},
  58. wagon_span = 1.95,
  59. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  60. base_texture = "advtrains_engine_diesel.png",
  61. base_livery = "advtrains_engine_diesel_livery.png",
  62. set_textures = jr_set_textures,
  63. set_livery = jr_set_livery,
  64. update_animation=function(self, velocity)
  65. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  66. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
  67. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  68. end
  69. end,
  70. custom_on_activate = function(self, staticdata_table, dtime_s)
  71. minetest.add_particlespawner({
  72. amount = 10,
  73. time = 0,
  74. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  75. minpos = {x=0, y=2.5, z=0.9},
  76. maxpos = {x=0, y=2.5, z=0.9},
  77. minvel = {x=-0.2, y=1.8, z=-0.2},
  78. maxvel = {x=0.2, y=2, z=0.2},
  79. minacc = {x=0, y=-0.1, z=0},
  80. maxacc = {x=0, y=-0.3, z=0},
  81. minexptime = 2,
  82. maxexptime = 4,
  83. minsize = 1,
  84. maxsize = 4,
  85. -- ^ The particle's properties are random values in between the bounds:
  86. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  87. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  88. collisiondetection = true,
  89. -- ^ collisiondetection: if true uses collision detection
  90. vertical = false,
  91. -- ^ vertical: if true faces player using y axis only
  92. texture = "smoke_puff.png",
  93. -- ^ Uses texture (string)
  94. attached = self.object,
  95. })
  96. end,
  97. drops={"advtrains:diesel_lokomotive"},
  98. horn_sound = "advtrains_engine_diesel_horn",
  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")