init.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 escape_texture(str)
  8. return str:gsub("[%[%()^:]", "\\%1")
  9. end
  10. local function set_textures(self, data)
  11. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  12. if inv then
  13. if inv:is_empty("box") then
  14. self.object:set_properties({
  15. mesh="moretrains_gondola.b3d",
  16. })
  17. return
  18. end
  19. local stack = inv:get_stack("box",1)
  20. local name = stack:get_name()
  21. local ndef = minetest.registered_nodes[name]
  22. if ndef then
  23. local dtype = ndef.drawtype
  24. if dtype == "normal" or dtype == "allfaces" or dtype == "allfaces_optional" or dtype == "glasslike" or dtype == "glasslike_framed" or dtype == "glasslike_framed_optional" or dtype == "liquid" then
  25. local texture = ndef.tiles or "default_cobble.png"
  26. if type(texture) == "table" then
  27. texture = texture[1] or "default_cobble.png"
  28. end
  29. self.object:set_properties({
  30. mesh="moretrains_gondola_mese.b3d",
  31. textures={"[combine:256x256:0,0=moretrains_wagon_gondola_cobble.png:0,109="..escape_texture(texture).."\\^\\[resize\\:16x16"}
  32. })
  33. return
  34. end
  35. end
  36. local idef = minetest.registered_items[name]
  37. if idef and idef.groups.advtrains_trackplacer and idef.groups.advtrains_trackplacer > 0 then
  38. self.object:set_properties({
  39. mesh="moretrains_gondola_rails.b3d",
  40. textures = {"moretrains_wagon_gondola.png"},
  41. })
  42. else
  43. self.object:set_properties({
  44. mesh="moretrains_gondola_toiletpaper.b3d",
  45. textures = {"moretrains_wagon_gondola.png"},
  46. })
  47. end
  48. end
  49. end
  50. local function convert(self, dtime, data, train)
  51. data.type = "advtrains:moretrains_wagon_gondola"
  52. end
  53. advtrains.register_wagon("moretrains_wagon_gondola", {
  54. mesh="moretrains_gondola.b3d",
  55. textures = {"moretrains_wagon_gondola.png"},
  56. set_textures = set_textures,
  57. seats = {},
  58. drives_on={default=true},
  59. max_speed=20,
  60. visual_size = {x=1, y=1},
  61. wagon_span=2.784,
  62. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  63. drops={"default:steelblock"},
  64. has_inventory = true,
  65. get_inventory_formspec = function(self, pname, invname)
  66. return "size[8,11]"..
  67. "list["..invname..";box;0,0;8,3;]"..
  68. "list[current_player;main;0,5;8,4;]"..
  69. "listring[]"
  70. end,
  71. inventory_list_sizes = {
  72. box=8*3,
  73. },
  74. }, S("Gondola wagon (empty)"), "moretrains_wagon_gondola_inv.png")
  75. advtrains.register_wagon("moretrains_wagon_gondola_mese", {
  76. mesh="moretrains_gondola_mese.b3d",
  77. textures = {"moretrains_wagon_gondola.png"},
  78. seats = {},
  79. drives_on={default=true},
  80. custom_on_step = convert,
  81. max_speed=20,
  82. visual_size = {x=1, y=1},
  83. wagon_span=2.784,
  84. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  85. drops={"default:steelblock"},
  86. has_inventory = true,
  87. get_inventory_formspec = function(self, pname, invname)
  88. return "size[8,11]"..
  89. "list["..invname..";box;0,0;8,3;]"..
  90. "list[current_player;main;0,5;8,4;]"..
  91. "listring[]"
  92. end,
  93. inventory_list_sizes = {
  94. box=8*3,
  95. },
  96. }, S("Gondola wagon with mese"), "moretrains_wagon_gondola_mese_inv.png")
  97. advtrains.register_wagon("moretrains_wagon_gondola_cobble", {
  98. mesh="moretrains_gondola_mese.b3d",
  99. textures = {"[combine:256x256:0,0=moretrains_wagon_gondola_cobble.png:0,109=default_obsidian_glass.png\\^\\[resize\\:16x16"},
  100. seats = {},
  101. custom_on_step = convert,
  102. drives_on={default=true},
  103. max_speed=20,
  104. visual_size = {x=1, y=1},
  105. wagon_span=2.784,
  106. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  107. drops={"default:steelblock"},
  108. has_inventory = true,
  109. get_inventory_formspec = function(self, pname, invname)
  110. return "size[8,11]"..
  111. "list["..invname..";box;0,0;8,3;]"..
  112. "list[current_player;main;0,5;8,4;]"..
  113. "listring[]"
  114. end,
  115. inventory_list_sizes = {
  116. box=8*3,
  117. },
  118. }, S("Gondola wagon with cobble stone"), "moretrains_wagon_gondola_cobble_inv.png")
  119. advtrains.register_wagon("moretrains_wagon_gondola_toiletpaper", {
  120. mesh="moretrains_gondola_toiletpaper.b3d",
  121. textures = {"moretrains_wagon_gondola.png"},
  122. set_textures = set_textures,
  123. custom_on_step = convert,
  124. seats = {},
  125. drives_on={default=true},
  126. max_speed=20,
  127. visual_size = {x=1, y=1},
  128. wagon_span=2.784,
  129. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  130. drops={"default:steelblock"},
  131. has_inventory = true,
  132. get_inventory_formspec = function(self, pname, invname)
  133. return "size[8,11]"..
  134. "list["..invname..";box;0,0;8,3;]"..
  135. "list[current_player;main;0,5;8,4;]"..
  136. "listring[]"
  137. end,
  138. inventory_list_sizes = {
  139. box=8*3,
  140. },
  141. }, S("Gondola wagon with toilet paper"), "moretrains_wagon_gondola_toiletpaper_inv.png")
  142. advtrains.register_wagon("moretrains_wagon_gondola_rails", {
  143. mesh="moretrains_gondola_rails.b3d",
  144. textures = {"moretrains_wagon_gondola.png"},
  145. custom_on_step = convert,
  146. seats = {},
  147. drives_on={default=true},
  148. max_speed=20,
  149. visual_size = {x=1, y=1},
  150. wagon_span=2.784,
  151. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  152. drops={"default:steelblock"},
  153. has_inventory = true,
  154. get_inventory_formspec = function(self, pname, invname)
  155. return "size[8,11]"..
  156. "list["..invname..";box;0,0;8,3;]"..
  157. "list[current_player;main;0,5;8,4;]"..
  158. "listring[]"
  159. end,
  160. inventory_list_sizes = {
  161. box=8*3,
  162. },
  163. }, S("Gondola wagon with rails"), "moretrains_wagon_gondola_rails_inv.png")
  164. minetest.register_craft({
  165. output = 'advtrains:moretrains_wagon_gondola',
  166. recipe = {
  167. {'group:wood', 'default:chest', 'group:wood'},
  168. {'advtrains:wheel', '', 'advtrains:wheel'},
  169. },
  170. })