init.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. -- length of the steam engine loop sound
  8. local SND_LOOP_LEN = 5
  9. advtrains.register_wagon("moretrains_steam_train", {
  10. mesh="moretrains_steam_train.b3d",
  11. textures = {"moretrains_steam_train.png"},
  12. is_locomotive=true,
  13. drives_on={default=true},
  14. max_speed=11,
  15. seats = {
  16. {
  17. name=S("Driver Stand (left)"),
  18. attach_offset={x=-5, y=3, z=-16},
  19. view_offset={x=0, y=7, z=0},
  20. group = "dstand",
  21. },
  22. {
  23. name=S("Driver Stand (right)"),
  24. attach_offset={x=5, y=3, z=-16},
  25. view_offset={x=0, y=7, z=0},
  26. group = "dstand",
  27. },
  28. },
  29. seat_groups = {
  30. dstand={
  31. name = "Driver Stand",
  32. driving_ctrl_access=true,
  33. access_to = {},
  34. },
  35. },
  36. assign_to_seat_group = {"dstand"},
  37. visual_size = {x=1, y=1},
  38. wagon_span=2.587,
  39. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  40. custom_on_velocity_change=function(self, velocity)
  41. if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
  42. self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*22, 0, true)
  43. self.old_anim_velocity=advtrains.abs_ceil(velocity)
  44. end
  45. end,
  46. custom_on_step=function(self, dtime)
  47. if self:train().velocity > 0 then -- First make sure that the train isn't standing
  48. if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 then
  49. -- start the sound if it was never started or has expired
  50. self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object=self.object})
  51. self.sound_loop_tmr = SND_LOOP_LEN
  52. end
  53. --decrease the sound timer
  54. self.sound_loop_tmr = self.sound_loop_tmr - dtime
  55. else
  56. -- If the train is standing, the sound will be stopped in some time. We do not need to interfere with it.
  57. self.sound_loop_tmr = nil
  58. end
  59. end,
  60. custom_on_activate = function(self, staticdata_table, dtime_s)
  61. minetest.add_particlespawner({
  62. amount = 10,
  63. time = 0,
  64. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  65. minpos = {x=0, y=2.32, z=2.08},
  66. maxpos = {x=0, y=2.4, z=2.03},
  67. minvel = {x=-0.2, y=1.8, z=-0.2},
  68. maxvel = {x=0.2, y=2, z=0.2},
  69. minacc = {x=0, y=-0.1, z=0},
  70. maxacc = {x=0, y=-0.3, z=0},
  71. minexptime = 2,
  72. maxexptime = 4,
  73. minsize = 1,
  74. maxsize = 5,
  75. -- ^ The particle's properties are random values in between the bounds:
  76. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  77. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  78. collisiondetection = true,
  79. -- ^ collisiondetection: if true uses collision detection
  80. vertical = false,
  81. -- ^ vertical: if true faces player using y axis only
  82. texture = "smoke_puff.png",
  83. -- ^ Uses texture (string)
  84. attached = self.object,
  85. })
  86. end,
  87. drops={"default:steelblock 1"},
  88. horn_sound = "advtrains_steam_whistle",
  89. }, S("Steam Train #1"), "moretrains_steam_train_inv.png")
  90. advtrains.register_wagon("moretrains_tender", {
  91. mesh="moretrains_steam_tender.b3d",
  92. textures = {"moretrains_steam_tender.png"},
  93. drives_on={default=true},
  94. max_speed=30,
  95. seats = {},
  96. visual_size = {x=1, y=1},
  97. wagon_span=1.667,
  98. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  99. drops={"default:steelblock 1"},
  100. has_inventory = true,
  101. get_inventory_formspec = advtrains.standard_inventory_formspec,
  102. inventory_list_sizes = {
  103. box=1*8,
  104. },
  105. }, S("Tender #1"), "moretrains_steam_tender_inv.png")
  106. minetest.register_craft({
  107. output = 'advtrains:moretrains_steam_train',
  108. recipe = {
  109. {'', '', 'advtrains:chimney'},
  110. {'advtrains:driver_cab', 'dye:blue', 'advtrains:boiler'},
  111. {'advtrains:wheel', 'advtrains:wheel', 'advtrains:wheel'},
  112. },
  113. })
  114. minetest.register_craft({
  115. output = 'advtrains:moretrains_tender',
  116. recipe = {
  117. {'default:steel_ingot', 'default:coalblock', 'default:steel_ingot'},
  118. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  119. {'advtrains:wheel', '', 'advtrains:wheel'},
  120. },
  121. })