slopes.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. --[[
  2. More Blocks: slope definitions
  3. Copyright (c) 2011-2017 Hugo Locurcio and contributors.
  4. Licensed under the zlib license. See LICENSE.md for more information.
  5. --]]
  6. local S = moreblocks.intllib
  7. local box_slope = {
  8. type = "fixed",
  9. fixed = {
  10. {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
  11. {-0.5, -0.25, -0.25, 0.5, 0, 0.5},
  12. {-0.5, 0, 0, 0.5, 0.25, 0.5},
  13. {-0.5, 0.25, 0.25, 0.5, 0.5, 0.5}
  14. }
  15. }
  16. local box_slope_half = {
  17. type = "fixed",
  18. fixed = {
  19. {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
  20. {-0.5, -0.375, -0.25, 0.5, -0.25, 0.5},
  21. {-0.5, -0.25, 0, 0.5, -0.125, 0.5},
  22. {-0.5, -0.125, 0.25, 0.5, 0, 0.5},
  23. }
  24. }
  25. local box_slope_half_raised = {
  26. type = "fixed",
  27. fixed = {
  28. {-0.5, -0.5, -0.5, 0.5, 0.125, 0.5},
  29. {-0.5, 0.125, -0.25, 0.5, 0.25, 0.5},
  30. {-0.5, 0.25, 0, 0.5, 0.375, 0.5},
  31. {-0.5, 0.375, 0.25, 0.5, 0.5, 0.5},
  32. }
  33. }
  34. --==============================================================
  35. local box_slope_inner = {
  36. type = "fixed",
  37. fixed = {
  38. {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
  39. {-0.5, -0.5, -0.25, 0.5, 0, 0.5},
  40. {-0.5, -0.5, -0.5, 0.25, 0, 0.5},
  41. {-0.5, 0, -0.5, 0, 0.25, 0.5},
  42. {-0.5, 0, 0, 0.5, 0.25, 0.5},
  43. {-0.5, 0.25, 0.25, 0.5, 0.5, 0.5},
  44. {-0.5, 0.25, -0.5, -0.25, 0.5, 0.5},
  45. }
  46. }
  47. local box_slope_inner_half = {
  48. type = "fixed",
  49. fixed = {
  50. {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
  51. {-0.5, -0.375, -0.25, 0.5, -0.25, 0.5},
  52. {-0.5, -0.375, -0.5, 0.25, -0.25, 0.5},
  53. {-0.5, -0.25, -0.5, 0, -0.125, 0.5},
  54. {-0.5, -0.25, 0, 0.5, -0.125, 0.5},
  55. {-0.5, -0.125, 0.25, 0.5, 0, 0.5},
  56. {-0.5, -0.125, -0.5, -0.25, 0, 0.5},
  57. }
  58. }
  59. local box_slope_inner_half_raised = {
  60. type = "fixed",
  61. fixed = {
  62. {-0.5, -0.5, -0.5, 0.5, 0.125, 0.5},
  63. {-0.5, 0.125, -0.25, 0.5, 0.25, 0.5},
  64. {-0.5, 0.125, -0.5, 0.25, 0.25, 0.5},
  65. {-0.5, 0.25, -0.5, 0, 0.375, 0.5},
  66. {-0.5, 0.25, 0, 0.5, 0.375, 0.5},
  67. {-0.5, 0.375, 0.25, 0.5, 0.5, 0.5},
  68. {-0.5, 0.375, -0.5, -0.25, 0.5, 0.5},
  69. }
  70. }
  71. --==============================================================
  72. local box_slope_outer = {
  73. type = "fixed",
  74. fixed = {
  75. {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
  76. {-0.5, -0.25, -0.25, 0.25, 0, 0.5},
  77. {-0.5, 0, 0, 0, 0.25, 0.5},
  78. {-0.5, 0.25, 0.25, -0.25, 0.5, 0.5}
  79. }
  80. }
  81. local box_slope_outer_half = {
  82. type = "fixed",
  83. fixed = {
  84. {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
  85. {-0.5, -0.375, -0.25, 0.25, -0.25, 0.5},
  86. {-0.5, -0.25, 0, 0, -0.125, 0.5},
  87. {-0.5, -0.125, 0.25, -0.25, 0, 0.5}
  88. }
  89. }
  90. local box_slope_outer_half_raised = {
  91. type = "fixed",
  92. fixed = {
  93. {-0.5, -0.5, -0.5, 0.5, 0.125, 0.5},
  94. {-0.5, 0.125, -0.25, 0.25, 0.25, 0.5},
  95. {-0.5, 0.25, 0, 0, 0.375, 0.5},
  96. {-0.5, 0.375, 0.25, -0.25, 0.5, 0.5}
  97. }
  98. }
  99. -- Node will be called <modname>:slope_<subname>
  100. function register_slope(modname, subname, recipeitem, groups, images, description, drop, light)
  101. local use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true
  102. stairsplus:register_slope(modname, subname, recipeitem, {
  103. groups = groups,
  104. tiles = images,
  105. description = description,
  106. drop = drop,
  107. light_source = light,
  108. sounds = default.node_sound_stone_defaults(),
  109. use_texture_alpha = use_texture_alpha
  110. })
  111. end
  112. local slopes_defs = {
  113. [""] = {
  114. mesh = "moreblocks_slope.obj",
  115. collision_box = box_slope,
  116. selection_box = box_slope,
  117. },
  118. ["_half"] = {
  119. mesh = "moreblocks_slope_half.obj",
  120. collision_box = box_slope_half,
  121. selection_box = box_slope_half,
  122. },
  123. ["_half_raised"] = {
  124. mesh = "moreblocks_slope_half_raised.obj",
  125. collision_box = box_slope_half_raised,
  126. selection_box = box_slope_half_raised,
  127. },
  128. --==============================================================
  129. ["_inner"] = {
  130. mesh = "moreblocks_slope_inner.obj",
  131. collision_box = box_slope_inner,
  132. selection_box = box_slope_inner,
  133. },
  134. ["_inner_half"] = {
  135. mesh = "moreblocks_slope_inner_half.obj",
  136. collision_box = box_slope_inner_half,
  137. selection_box = box_slope_inner_half,
  138. },
  139. ["_inner_half_raised"] = {
  140. mesh = "moreblocks_slope_inner_half_raised.obj",
  141. collision_box = box_slope_inner_half_raised,
  142. selection_box = box_slope_inner_half_raised,
  143. },
  144. --==============================================================
  145. ["_inner_cut"] = {
  146. mesh = "moreblocks_slope_inner_cut.obj",
  147. collision_box = box_slope_inner,
  148. selection_box = box_slope_inner,
  149. },
  150. ["_inner_cut_half"] = {
  151. mesh = "moreblocks_slope_inner_cut_half.obj",
  152. collision_box = box_slope_inner_half,
  153. selection_box = box_slope_inner_half,
  154. },
  155. ["_inner_cut_half_raised"] = {
  156. mesh = "moreblocks_slope_inner_cut_half_raised.obj",
  157. collision_box = box_slope_inner_half_raised,
  158. selection_box = box_slope_inner_half_raised,
  159. },
  160. --==============================================================
  161. ["_outer"] = {
  162. mesh = "moreblocks_slope_outer.obj",
  163. collision_box = box_slope_outer,
  164. selection_box = box_slope_outer,
  165. },
  166. ["_outer_half"] = {
  167. mesh = "moreblocks_slope_outer_half.obj",
  168. collision_box = box_slope_outer_half,
  169. selection_box = box_slope_outer_half,
  170. },
  171. ["_outer_half_raised"] = {
  172. mesh = "moreblocks_slope_outer_half_raised.obj",
  173. collision_box = box_slope_outer_half_raised,
  174. selection_box = box_slope_outer_half_raised,
  175. },
  176. --==============================================================
  177. ["_outer_cut"] = {
  178. mesh = "moreblocks_slope_outer_cut.obj",
  179. collision_box = box_slope_outer,
  180. selection_box = box_slope_outer,
  181. },
  182. ["_outer_cut_half"] = {
  183. mesh = "moreblocks_slope_outer_cut_half.obj",
  184. collision_box = box_slope_outer_half,
  185. selection_box = box_slope_outer_half,
  186. },
  187. ["_outer_cut_half_raised"] = {
  188. mesh = "moreblocks_slope_outer_cut_half_raised.obj",
  189. collision_box = box_slope_outer_half_raised,
  190. selection_box = box_slope_outer_half_raised,
  191. },
  192. ["_cut"] = {
  193. mesh = "moreblocks_slope_cut.obj",
  194. collision_box = box_slope_outer,
  195. selection_box = box_slope_outer,
  196. },
  197. }
  198. for k,v in pairs(slopes_defs) do
  199. table.insert(stairsplus.shapes_list, { "slope_", k })
  200. end
  201. function stairsplus:register_slope_alias(modname_old, subname_old, modname_new, subname_new)
  202. local defs = stairsplus.copytable(slopes_defs)
  203. for alternate, def in pairs(defs) do
  204. minetest.register_alias(modname_old .. ":slope_" .. subname_old .. alternate, modname_new .. ":slope_" .. subname_new .. alternate)
  205. end
  206. end
  207. function stairsplus:register_slope_alias_force(modname_old, subname_old, modname_new, subname_new)
  208. local defs = stairsplus.copytable(slopes_defs)
  209. for alternate, def in pairs(defs) do
  210. minetest.register_alias_force(modname_old .. ":slope_" .. subname_old .. alternate, modname_new .. ":slope_" .. subname_new .. alternate)
  211. end
  212. end
  213. function stairsplus:register_slope(modname, subname, recipeitem, fields)
  214. local defs = stairsplus.copytable(slopes_defs)
  215. local desc = S("%s Slope"):format(fields.description)
  216. local use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or fields.use_texture_alpha
  217. for alternate, def in pairs(defs) do
  218. for k, v in pairs(fields) do
  219. def[k] = v
  220. end
  221. def.drawtype = "mesh"
  222. def.paramtype = "light"
  223. def.paramtype2 = def.paramtype2 or "facedir"
  224. def.use_texture_alpha = use_texture_alpha
  225. def.on_place = minetest.rotate_node
  226. def.description = desc
  227. def.groups = stairsplus:prepare_groups(fields.groups)
  228. if alternate == "_half" or alternate == "_half_raised" then
  229. def.groups.not_blocking_trains = 1
  230. end
  231. if fields.drop and not (type(fields.drop) == "table") then
  232. def.drop = modname.. ":slope_" ..fields.drop..alternate
  233. end
  234. minetest.register_node(":" ..modname.. ":slope_" ..subname..alternate, def)
  235. end
  236. circular_saw.known_nodes[recipeitem] = {modname, subname}
  237. -- Some saw-less recipes:
  238. minetest.register_craft({
  239. type = "shapeless",
  240. output = recipeitem,
  241. recipe = {modname .. ":slope_" .. subname, modname .. ":slope_" .. subname},
  242. })
  243. minetest.register_craft({
  244. type = "shapeless",
  245. output = recipeitem,
  246. recipe = {modname .. ":slope_" .. subname .. "_half", modname .. ":slope_" .. subname .. "_half_raised"},
  247. })
  248. minetest.register_craft({
  249. type = "shapeless",
  250. output = recipeitem,
  251. recipe = {modname .. ":slope_" .. subname .. "_half", modname .. ":slope_" .. subname .. "_half",
  252. modname .. ":slope_" .. subname .. "_half", modname .. ":slope_" .. subname .. "_half"},
  253. })
  254. minetest.register_craft({
  255. type = "shapeless",
  256. output = recipeitem,
  257. recipe = {modname .. ":slope_" .. subname .. "_outer", modname .. ":slope_" .. subname .. "_inner"},
  258. })
  259. minetest.register_craft({
  260. type = "shapeless",
  261. output = recipeitem,
  262. recipe = {modname .. ":slope_" .. subname .. "_outer_half", modname .. ":slope_" .. subname .. "_inner_half_raised"},
  263. })
  264. minetest.register_craft({
  265. type = "shapeless",
  266. output = recipeitem,
  267. recipe = {modname .. ":slope_" .. subname .. "_outer_half_raised", modname .. ":slope_" .. subname .. "_inner_half"},
  268. })
  269. minetest.register_craft({
  270. type = "shapeless",
  271. output = recipeitem,
  272. recipe = {modname .. ":slope_" .. subname .. "_outer_cut", modname .. ":slope_" .. subname .. "_inner_cut"},
  273. })
  274. minetest.register_craft({
  275. type = "shapeless",
  276. output = recipeitem,
  277. recipe = {modname .. ":slope_" .. subname .. "_outer_cut_half", modname .. ":slope_" .. subname .. "_inner_cut_half_raised"},
  278. })
  279. minetest.register_craft({
  280. type = "shapeless",
  281. output = recipeitem,
  282. recipe = {modname .. ":slope_" .. subname .. "_cut", modname .. ":slope_" .. subname .. "_cut"},
  283. })
  284. minetest.register_craft({
  285. type = "shapeless",
  286. output = modname .. ":slab_" .. subname,
  287. recipe = {modname .. ":slope_" .. subname .. "_half", modname .. ":slope_" .. subname .. "_half"},
  288. })
  289. minetest.register_craft({
  290. type = "shapeless",
  291. output = modname .. ":slab_" .. subname,
  292. recipe = {modname .. ":slope_" .. subname .. "_outer_half", modname .. ":slope_" .. subname .. "_inner_half"},
  293. })
  294. minetest.register_craft({
  295. type = "shapeless",
  296. output = modname .. ":slab_" .. subname,
  297. recipe = {modname .. ":slope_" .. subname .. "_outer_cut_half", modname .. ":slope_" .. subname .. "_inner_cut_half"},
  298. })
  299. minetest.register_craft({
  300. type = "shapeless",
  301. output = modname .. ":slope_" .. subname .. "_half_raised",
  302. recipe = {modname .. ":slope_" .. subname .. "_half", modname .. ":slope_" .. subname .. "_half",
  303. modname .. ":slope_" .. subname .. "_half"},
  304. })
  305. minetest.register_craft({
  306. type = "shapeless",
  307. output = modname .. ":slope_" .. subname .. "_half_raised",
  308. recipe = {modname .. ":slab_" .. subname, modname .. ":slope_" .. subname .. "_half"},
  309. })
  310. minetest.register_craft({
  311. type = "shapeless",
  312. output = modname .. ":slope_" .. subname .. "_inner_half_raised",
  313. recipe = {modname .. ":slab_" .. subname, modname .. ":slope_" .. subname .. "_inner_half"},
  314. })
  315. minetest.register_craft({
  316. type = "shapeless",
  317. output = modname .. ":slope_" .. subname .. "_outer_half_raised",
  318. recipe = {modname .. ":slab_" .. subname, modname .. ":slope_" .. subname .. "_outer_half"},
  319. })
  320. minetest.register_craft({
  321. type = "shapeless",
  322. output = modname .. ":slope_" .. subname .. "_inner_cut_half_raised",
  323. recipe = {modname .. ":slab_" .. subname, modname .. ":slope_" .. subname .. "_inner_cut_half"},
  324. })
  325. end