functions.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. -- Boilerplate to support localized strings if intllib mod is installed.
  2. local S
  3. if (minetest.get_modpath("intllib")) then
  4. dofile(minetest.get_modpath("intllib").."/intllib.lua")
  5. S = intllib.Getter(minetest.get_current_modname())
  6. else
  7. S = function ( s ) return s end
  8. end
  9. -- Nodes will be called simplyslopes:{'',outer_,outer2_,inner_,inner2_}<subname>
  10. function simplyslopes.register_all2(recipeitem)
  11. -- Todo
  12. local thisnode=minetest.registered_nodes[recipeitem]
  13. if thisnode == nil
  14. then -- thisnode is empty, get out of here!
  15. return
  16. end
  17. --create the new node "subname"
  18. local tmp = simplyslopes.splitstring(recipeitem)
  19. local modname=tmp[1]
  20. local subname=tmp[2]
  21. -- Bakedclay and wool mod name their blocks like "bakedclay:white"
  22. if modname == 'bakedclay' or modname == 'wool'
  23. -- We must add modname to subname
  24. then subname= modname .. '_' .. subname
  25. end
  26. local desc = thisnode.description
  27. -- remove "Block" and "Planks" form description;
  28. desc=string.gsub(desc,'Block', '')
  29. desc=string.gsub(desc,'Plank', ' ')
  30. --desc=string.gsub(desc,' ', ' ')
  31. desc=string.gsub(desc,'%s+', ' ')
  32. if (subname == nil)
  33. then error(recipeitem .. ", " .. modname..", "..subname)
  34. end
  35. simplyslopes.register_slope(subname, recipeitem, thisnode.groups, thisnode.tiles, desc, thisnode.sounds)
  36. simplyslopes.register_slopecorner(subname, recipeitem, thisnode.groups, thisnode.tiles, desc, thisnode.sounds)
  37. simplyslopes.register_slopecorner2(subname, recipeitem, thisnode.groups, thisnode.tiles, desc, thisnode.sounds)
  38. simplyslopes.register_slopeinner(subname, recipeitem, thisnode.groups, thisnode.tiles, desc, thisnode.sounds)
  39. simplyslopes.register_slopeinner2(subname, recipeitem, thisnode.groups, thisnode.tiles, desc, thisnode.sounds)
  40. end
  41. -- Node will be called simplyslopes:<subname>
  42. function simplyslopes.register_slope(subname, recipeitem, groups, images, description, snds)
  43. local newitem="simplyslopes:" .. subname,
  44. minetest.register_node(":simplyslopes:" .. subname, {
  45. description = S(description.." Slope"),
  46. drawtype = "mesh",
  47. mesh = "simplyslopes_slope.obj",
  48. tiles = images,
  49. paramtype = "light",
  50. paramtype2 = "facedir",
  51. is_ground_content = false,
  52. groups = groups,
  53. sounds = snds,
  54. selection_box = {
  55. type = "fixed",
  56. fixed = {
  57. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  58. {-0.5, -0.1875, -0.1875, 0.5, 0.1875, 0.5}, -- NodeBox3
  59. {-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- NodeBox2
  60. },
  61. },
  62. collision_box = {
  63. type = "fixed",
  64. fixed = {
  65. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  66. {-0.5, -0.1875, -0.1875, 0.5, 0.1875, 0.5}, -- NodeBox3
  67. {-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- NodeBox2
  68. },
  69. },
  70. on_place = minetest.rotate_node
  71. })
  72. minetest.register_craft({
  73. output = newitem .. ' 6',
  74. recipe = {
  75. {recipeitem, "", ""},
  76. { "",recipeitem, ""},
  77. {"","",recipeitem},
  78. },
  79. })
  80. minetest.register_craft({
  81. type = "shapeless" ,
  82. output = recipeitem ..' 1',
  83. recipe = {newitem, newitem},
  84. })
  85. minetest.register_alias("simplyslopes:slope_" .. subname, "simplyslopes:" .. subname)
  86. end
  87. -- Node will be called simplyslopes:inner_<subname>
  88. function simplyslopes.register_slopeinner(subname, recipeitem, groups, images, description, snds)
  89. local newitem="simplyslopes:inner_" .. subname,
  90. minetest.register_node(":simplyslopes:inner_" .. subname, {
  91. description = description.." Inner Slope Corner",
  92. drawtype = "mesh",
  93. mesh = "simplyslopes_slopeinsidecorner.obj",
  94. tiles = images,
  95. paramtype = "light",
  96. paramtype2 = "facedir",
  97. is_ground_content = false,
  98. groups = groups,
  99. sounds = snds,
  100. selection_box = {
  101. type = "fixed",
  102. fixed = {
  103. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  104. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  105. {-0.5, 0, -0.5, 0, 0.5, 0},
  106. },
  107. },
  108. collision_box = {
  109. type = "fixed",
  110. fixed = {
  111. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  112. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  113. {-0.5, 0, -0.5, 0, 0.5, 0},
  114. },
  115. },
  116. on_place = minetest.rotate_node
  117. })
  118. minetest.register_craft({
  119. output = "simplyslopes:inner_" .. subname ..' 5',
  120. recipe = {
  121. {recipeitem, recipeitem, ""},
  122. {"", "", recipeitem},
  123. {"","", recipeitem},
  124. },
  125. })
  126. minetest.register_craft({
  127. type = "shapeless" ,
  128. output = recipeitem ..' 4',
  129. recipe = {newitem, newitem, newitem, newitem, newitem},
  130. })
  131. minetest.register_alias("simplyslopes:slopeinner_" .. subname, "simplyslopes:inner_" .. subname)
  132. end
  133. -- Node will be called simplyslopes:inner2_<subname>
  134. function simplyslopes.register_slopeinner2(subname, recipeitem, groups, images, description, snds)
  135. local newitem="simplyslopes:inner2_" .. subname,
  136. minetest.register_node(":simplyslopes:inner2_" .. subname, {
  137. description = description.." Inner Slope Corner",
  138. -- drawtype = "nodebox",
  139. drawtype = "mesh",
  140. mesh = "simplyslopes_slopeinsidecorner2.obj",
  141. tiles = images,
  142. paramtype = "light",
  143. paramtype2 = "facedir",
  144. is_ground_content = false,
  145. groups = groups,
  146. sounds = snds,
  147. selection_box = {
  148. type = "fixed",
  149. fixed = {
  150. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  151. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  152. {-0.5, 0, -0.5, 0, 0.5, 0},
  153. },
  154. },
  155. collision_box = {
  156. type = "fixed",
  157. fixed = {
  158. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  159. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  160. {-0.5, 0, -0.5, 0, 0.5, 0},
  161. },
  162. },
  163. on_place = minetest.rotate_node
  164. })
  165. minetest.register_craft({
  166. output = newitem .. ' 6',
  167. recipe = {
  168. {recipeitem, recipeitem, ""},
  169. {"", "", recipeitem},
  170. {recipeitem,"", recipeitem},
  171. },
  172. })
  173. minetest.register_craft({
  174. type = "shapeless" ,
  175. output = recipeitem ..' 5',
  176. recipe = {newitem, newitem, newitem, newitem, newitem, newitem},
  177. })
  178. minetest.register_alias("simplyslopes:slopeinsidecorner2_" .. subname, "simplyslopes:inner2_" .. subname)
  179. end
  180. -- Node will be called simplyslopes:outer_<subname>
  181. function simplyslopes.register_slopecorner(subname, recipeitem, groups, images, description, snds)
  182. local newitem="simplyslopes:outer_" .. subname,
  183. minetest.register_node(":simplyslopes:outer_" .. subname, {
  184. description = description.." Outer Slope Corner",
  185. -- drawtype = "nodebox",
  186. drawtype = "mesh",
  187. mesh = "simplyslopes_slopecorner.obj",
  188. tiles = images,
  189. paramtype = "light",
  190. paramtype2 = "facedir",
  191. is_ground_content = false,
  192. groups = groups,
  193. sounds = snds,
  194. selection_box = {
  195. type = "fixed",
  196. fixed = {
  197. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  198. {-0.5, -0.1875, -0.1875, 0.1875, 0.1875, 0.5}, -- NodeBox3
  199. {-0.5, 0.1875, 0.1875, -0.1875, 0.5, 0.5}, -- NodeBox2
  200. },
  201. },
  202. collision_box = {
  203. type = "fixed",
  204. fixed = {
  205. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  206. {-0.5, -0.1875, -0.1875, 0.5, 0.1875, 0.5}, -- NodeBox3
  207. {-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- NodeBox2
  208. },
  209. },
  210. on_place = minetest.rotate_node
  211. })
  212. minetest.register_craft({
  213. output = newitem .. ' 15',
  214. recipe = {
  215. { "",recipeitem, ""},
  216. {recipeitem,"",recipeitem},
  217. },
  218. minetest.register_craft({
  219. type = "shapeless" ,
  220. output = recipeitem ..' 1',
  221. recipe = {newitem, newitem, newitem, newitem, newitem},
  222. })
  223. })
  224. minetest.register_alias("simplyslopes:slopecorner_" .. subname, "simplyslopes:outer_" .. subname)
  225. end
  226. -- Node will be called simplyslopes:outer2_<subname>
  227. function simplyslopes.register_slopecorner2(subname, recipeitem, groups, images, description, snds)
  228. local newitem="simplyslopes:outer2_" .. subname,
  229. minetest.register_node(":simplyslopes:outer2_" .. subname, {
  230. description = description.." Outer Slope Corner",
  231. -- drawtype = "nodebox",
  232. drawtype = "mesh",
  233. mesh = "simplyslopes_slopecorner2.obj",
  234. tiles = images,
  235. paramtype = "light",
  236. paramtype2 = "facedir",
  237. is_ground_content = false,
  238. sunlight_propagates = true,
  239. groups = groups,
  240. sounds = snds,
  241. selection_box = {
  242. type = "fixed",
  243. fixed = {
  244. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  245. {-0.5, -0.1875, -0.1875, 0.1875, 0.1875, 0.5}, -- NodeBox3
  246. {-0.5, 0.1875, 0.1875, -0.1875, 0.5, 0.5}, -- NodeBox2
  247. },
  248. },
  249. collision_box = {
  250. type = "fixed",
  251. fixed = {
  252. {-0.5, -0.5, -0.5, 0.5, -0.1875, 0.5}, -- NodeBox1
  253. {-0.5, -0.1875, -0.1875, 0.5, 0.1875, 0.5}, -- NodeBox3
  254. {-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- NodeBox2
  255. },
  256. },
  257. on_place = minetest.rotate_node
  258. })
  259. minetest.register_craft({
  260. output = newitem .. ' 18',
  261. recipe = {
  262. { "",recipeitem, ""},
  263. {"",recipeitem,recipeitem},
  264. },
  265. })
  266. minetest.register_craft({
  267. type = "shapeless" ,
  268. output = recipeitem ..' 1',
  269. recipe = {newitem, newitem, newitem, newitem, newitem, newitem},
  270. })
  271. minetest.register_alias("simplyslopes:slopecorner2_" .. subname, "simplyslopes:outer2_" .. subname)
  272. end
  273. -- Split string with the format mod:item to mod and item seperately
  274. function simplyslopes.splitstring(inputstr)
  275. local sep = ':'
  276. local t={}
  277. local i=1
  278. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  279. t[i] = str
  280. i = i + 1
  281. end
  282. return t
  283. end
  284. -- Helper