init.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. advtrains.register_wagon("rocket", {
  8. mesh="advtrains_rocket.b3d",
  9. textures = {"advtrains_rocket.png"},
  10. is_locomotive=true,
  11. drives_on={default=true},
  12. max_speed=5,
  13. seats = {
  14. {
  15. name=S("Driver Stand"),
  16. attach_offset={x=0, y=10, z=-10},
  17. view_offset={x=0, y=6, z=0},
  18. group = "dstand",
  19. },
  20. },
  21. seat_groups = {
  22. dstand={
  23. name = "Driver Stand",
  24. driving_ctrl_access = true,
  25. access_to = {},
  26. },
  27. },
  28. assign_to_seat_group = {"dstand"},
  29. visual_size = {x=1, y=1},
  30. wagon_span=1.6,
  31. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  32. update_animation=function(self, velocity)
  33. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  34. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
  35. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  36. end
  37. end,
  38. custom_on_activate = function(self, staticdata_table, dtime_s)
  39. minetest.add_particlespawner({
  40. amount = 20,
  41. time = 0,
  42. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  43. minpos = {x=0, y=3.2, z=1.4},
  44. maxpos = {x=0, y=3.2, z=1.4},
  45. minvel = {x=-0.2, y=1.8, z=-0.2},
  46. maxvel = {x=0.2, y=2, z=0.2},
  47. minacc = {x=0, y=-0.1, z=0},
  48. maxacc = {x=0, y=-0.3, z=0},
  49. minexptime = 2,
  50. maxexptime = 4,
  51. minsize = 2,
  52. maxsize = 8,
  53. -- ^ The particle's properties are random values in between the bounds:
  54. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  55. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  56. collisiondetection = true,
  57. -- ^ collisiondetection: if true uses collision detection
  58. vertical = false,
  59. -- ^ vertical: if true faces player using y axis only
  60. texture = "smoke_puff.png",
  61. -- ^ Uses texture (string)
  62. attached = self.object,
  63. })
  64. end,
  65. drops={"advtrains:rocket"},
  66. }, S("Rocket"), "advtrains_rocket_inv.png")
  67. advtrains.register_wagon("rocket_wagon_tender", {
  68. mesh="advtrains_rocket_wagon.b3d",
  69. textures = {"advtrains_rocket_wagon.png"},
  70. drives_on={default=true},
  71. max_speed=3,
  72. seats = {},
  73. visual_size = {x=1, y=1},
  74. wagon_span=1.0,
  75. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  76. drops={"default:steelblock 4"},
  77. has_inventory = true,
  78. get_inventory_formspec = advtrains.standard_inventory_formspec,
  79. inventory_list_sizes = {
  80. box=8*2,
  81. },
  82. }, S("Rocket tender"), "advtrains_wagon_rocket_tender_inv.png")
  83. advtrains.register_wagon("rocket_wagon_box", {
  84. mesh="advtrains_rocket_wagon_long.b3d",
  85. textures = {"advtrains_rocket_wagon.png"},
  86. drives_on={default=true},
  87. max_speed=3,
  88. seats = {},
  89. visual_size = {x=1, y=1},
  90. wagon_span=1.9,
  91. collisionbox = {-1.0,-0.5,-1.0, 1.0,1.5,1.0},
  92. drops={"default:steelblock 4"},
  93. has_inventory = true,
  94. get_inventory_formspec = advtrains.standard_inventory_formspec,
  95. inventory_list_sizes = {
  96. box=8*6,
  97. },
  98. }, S("Rocket Box Wagon"), "advtrains_wagon_rocket_box_inv.png")
  99. --craftings for train
  100. minetest.register_craft({
  101. output = 'advtrains:rocket',
  102. recipe = {
  103. {'advtrains:chimney', '', ''},
  104. {'advtrains:chimney', 'advtrains:boiler', 'group:wood'},
  105. {'advtrains:wheel', '', 'advtrains:wheel'},
  106. },
  107. })
  108. minetest.register_craft({
  109. output = 'advtrains:rocket_wagon_tender',
  110. recipe = {
  111. {'', '', 'advtrains_train_rocket:barrel_stack'},
  112. {'group:wood', 'group:wood', 'group:wood'},
  113. {'advtrains:wheel', '', 'advtrains:wheel'},
  114. },
  115. })
  116. minetest.register_craft({
  117. output = 'advtrains:rocket_wagon_tender',
  118. recipe = {
  119. {'advtrains_train_rocket:barrel', 'advtrains_train_rocket:barrel', 'advtrains_train_rocket:barrel'},
  120. {'group:wood', 'group:wood', 'group:wood'},
  121. {'advtrains:wheel', '', 'advtrains:wheel'},
  122. },
  123. })
  124. --barrels for craftings and decoration
  125. local barrel_formspec =
  126. "size[8,9]" ..
  127. "list[current_name;main;0,0.3;8,4;]" ..
  128. "list[current_player;main;0,4.85;8,1;]" ..
  129. "list[current_player;main;0,6.08;8,3;8]" ..
  130. "listring[current_name;main]" ..
  131. "listring[current_player;main]"
  132. --..
  133. --default.get_hotbar_bg(0,4.85)
  134. minetest.register_node("advtrains_train_rocket:barrel", {
  135. description = "barrel",
  136. tiles = {"advtrains_rocket_wagon.png"},
  137. groups = {choppy = 3, oddly_breakable_by_hand = 3, flammable = 3,},
  138. drawtype = "mesh",
  139. paramtype2 = "facedir",
  140. mesh = "advtrains_barrel.b3d",
  141. visual_scale = 0.4,
  142. paramtype = "light",
  143. sounds = default.node_sound_wood_defaults(),
  144. on_construct = function(pos)
  145. local meta = minetest.get_meta(pos)
  146. meta:set_string("formspec", barrel_formspec)
  147. local inv = meta:get_inventory()
  148. inv:set_size("main", 8*1)
  149. end,
  150. can_dig = function(pos,player)
  151. local meta = minetest.get_meta(pos);
  152. local inv = meta:get_inventory()
  153. return inv:is_empty("main")
  154. end,
  155. on_metadata_inventory_move = function(pos, from_list, from_index,
  156. to_list, to_index, count, player)
  157. minetest.log("action", player:get_player_name() ..
  158. " moves stuff in chest at " .. minetest.pos_to_string(pos))
  159. end,
  160. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  161. minetest.log("action", player:get_player_name() ..
  162. " moves " .. stack:get_name() ..
  163. " to chest at " .. minetest.pos_to_string(pos))
  164. end,
  165. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  166. minetest.log("action", player:get_player_name() ..
  167. " takes " .. stack:get_name() ..
  168. " from chest at " .. minetest.pos_to_string(pos))
  169. end,
  170. on_blast = function(pos)
  171. local drops = {}
  172. default.get_inventory_drops(pos, "main", drops)
  173. drops[#drops+1] = "advtrains_train_rocket:barrel"
  174. minetest.remove_node(pos)
  175. return drops
  176. end,
  177. })
  178. minetest.register_node("advtrains_train_rocket:barrel_stack", {
  179. description = "stacked barrel",
  180. tiles = {"advtrains_rocket_wagon.png"},
  181. groups = {choppy = 3, oddly_breakable_by_hand = 3, flammable = 3,},
  182. drawtype = "mesh",
  183. paramtype2 = "facedir",
  184. mesh = "advtrains_barrel_stack.b3d",
  185. visual_scale = 0.4,
  186. paramtype = "light",
  187. sounds = default.node_sound_wood_defaults(),
  188. selection_box = {
  189. type = "fixed",
  190. fixed = {
  191. {-1.0, -0.5, -0.5, 1.0, 1.25, 0.5},
  192. },
  193. },
  194. collision_box = {
  195. type = "fixed",
  196. fixed = {
  197. {-1.5, -0.5, -0.5, 0.5, 1.25, 0.5},
  198. },
  199. },
  200. on_construct = function(pos)
  201. local meta = minetest.get_meta(pos)
  202. meta:set_string("formspec", barrel_formspec)
  203. local inv = meta:get_inventory()
  204. inv:set_size("main", 8*3)
  205. end,
  206. can_dig = function(pos,player)
  207. local meta = minetest.get_meta(pos);
  208. local inv = meta:get_inventory()
  209. return inv:is_empty("main")
  210. end,
  211. on_metadata_inventory_move = function(pos, from_list, from_index,
  212. to_list, to_index, count, player)
  213. minetest.log("action", player:get_player_name() ..
  214. " moves stuff in chest at " .. minetest.pos_to_string(pos))
  215. end,
  216. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  217. minetest.log("action", player:get_player_name() ..
  218. " moves " .. stack:get_name() ..
  219. " to chest at " .. minetest.pos_to_string(pos))
  220. end,
  221. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  222. minetest.log("action", player:get_player_name() ..
  223. " takes " .. stack:get_name() ..
  224. " from chest at " .. minetest.pos_to_string(pos))
  225. end,
  226. on_blast = function(pos)
  227. local drops = {}
  228. default.get_inventory_drops(pos, "main", drops)
  229. drops[#drops+1] = "advtrains_train_rocket:barrel_stack"
  230. minetest.remove_node(pos)
  231. return drops
  232. end,
  233. })
  234. --craftings for barrels
  235. minetest.register_craft({
  236. output = 'advtrains_train_rocket:barrel',
  237. recipe = {
  238. {'group:wood', 'group:wood', 'group:wood'},
  239. {'default:steel_ingot','','default:steel_ingot'},
  240. {'group:wood', 'group:wood', 'group:wood'},
  241. },
  242. })
  243. minetest.register_craft({
  244. output = 'advtrains_train_rocket:barrel_stack',
  245. recipe = {
  246. {'', 'advtrains_train_rocket:barrel', ''},
  247. {'group:stick', 'group:stick', 'group:stick'},
  248. {'advtrains_train_rocket:barrel', '', 'advtrains_train_rocket:barrel'},
  249. },
  250. })