init.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. -- wool sounds
  2. function default.node_sound_wool_defaults(table)
  3. table = table or {}
  4. table.footstep = table.footstep or
  5. {name = "wool_coat_movement", gain = 1.0}
  6. table.dug = table.dug or
  7. {name = "wool_coat_movement", gain = 0.25}
  8. table.place = table.place or
  9. {name = "default_place_node", gain = 1.0}
  10. return table
  11. end
  12. stairs = {
  13. mod = "redo",
  14. wood = default.node_sound_wood_defaults(),
  15. dirt = default.node_sound_dirt_defaults(),
  16. stone = default.node_sound_stone_defaults(),
  17. glass = default.node_sound_glass_defaults(),
  18. leaves = default.node_sound_leaves_defaults(),
  19. metal = default.node_sound_metal_defaults(),
  20. wool = default.node_sound_wool_defaults()
  21. }
  22. -- cache creative
  23. local creative = minetest.settings:get_bool("creative_mode")
  24. function is_creative_enabled_for(name)
  25. if creative or minetest.check_player_privs(name, {creative = true}) then
  26. return true
  27. end
  28. return false
  29. end
  30. -- process textures
  31. local set_textures = function(images, worldaligntex)
  32. local stair_images = {}
  33. for i, image in ipairs(images) do
  34. if type(image) == "string" then
  35. stair_images[i] = {
  36. name = image,
  37. backface_culling = true
  38. }
  39. if worldaligntex then
  40. stair_images[i].align_style = "world"
  41. end
  42. else
  43. stair_images[i] = table.copy(image)
  44. if stair_images[i].backface_culling == nil then
  45. stair_images[i].backface_culling = true
  46. end
  47. if worldaligntex and stair_images[i].align_style == nil then
  48. stair_images[i].align_style = "world"
  49. end
  50. end
  51. end
  52. return stair_images
  53. end
  54. -- placement helper
  55. local stair_place = function(itemstack, placer, pointed_thing, stair_node)
  56. -- if sneak pressed then use param2 in node pointed at when placing
  57. if placer:is_player() and placer:get_player_control().sneak then
  58. local name = placer:get_player_name()
  59. local pos_a = pointed_thing.above
  60. local node_a = minetest.get_node(pos_a)
  61. local def_a = minetest.registered_nodes[node_a.name]
  62. if not def_a.buildable_to
  63. or minetest.is_protected(pos_a, name) then
  64. return itemstack
  65. end
  66. local pos_u = pointed_thing.under
  67. local node_u = minetest.get_node(pos_u)
  68. if minetest.get_item_group(node_u.name, "stair") > 0
  69. or minetest.get_item_group(node_u.name, "slab") > 0 then
  70. minetest.set_node(pos_a, {
  71. name = stair_node,
  72. param2 = node_u.param2
  73. })
  74. if not is_creative_enabled_for(name) then
  75. itemstack:take_item()
  76. end
  77. return itemstack
  78. end
  79. end
  80. core.rotate_and_place(itemstack, placer, pointed_thing,
  81. is_creative_enabled_for(placer:get_player_name()),
  82. {invert_wall = placer:get_player_control().sneak})
  83. return itemstack
  84. end
  85. local function get_light(nodename)
  86. local def = minetest.registered_nodes[nodename]
  87. if def and def.light_source then
  88. return def.light_source
  89. end
  90. return nil
  91. end
  92. local function get_alpha(nodename)
  93. local def = minetest.registered_nodes[nodename]
  94. if def and def.use_texture_alpha then
  95. return def.use_texture_alpha
  96. end
  97. return nil
  98. end
  99. -- if recipeitem can be burned then stair can be as well
  100. local function set_burn(recipeitem, stair_name, v)
  101. local burntime = minetest.get_craft_result({
  102. method = "fuel", width = 1, items = {recipeitem} }).time
  103. if burntime > 0 then
  104. minetest.register_craft({
  105. type = "fuel",
  106. recipe = stair_name,
  107. burntime = math.floor(burntime * v)
  108. })
  109. end
  110. end
  111. -- Node will be called stairs:stair_<subname>
  112. function stairs.register_stair(
  113. subname, recipeitem, groups, images, description, snds, wat)
  114. local stair_images = set_textures(images, wat)
  115. local new_groups = table.copy(groups)
  116. new_groups.stair = 1
  117. minetest.register_node(":stairs:stair_" .. subname, {
  118. description = description,
  119. drawtype = "nodebox",
  120. tiles = stair_images,
  121. paramtype = "light",
  122. paramtype2 = "facedir",
  123. is_ground_content = false,
  124. use_texture_alpha = get_alpha(recipeitem),
  125. light_source = get_light(recipeitem),
  126. groups = new_groups,
  127. sounds = snds,
  128. node_box = {
  129. type = "fixed",
  130. fixed = {
  131. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  132. {-0.5, 0, 0, 0.5, 0.5, 0.5}
  133. }
  134. },
  135. on_place = function(itemstack, placer, pointed_thing)
  136. return stair_place(itemstack, placer, pointed_thing,
  137. "stairs:stair_" .. subname)
  138. end
  139. })
  140. -- if no recipe item provided then skip craft recipes
  141. if not recipeitem then
  142. return
  143. end
  144. -- stair recipes
  145. minetest.register_craft({
  146. output = "stairs:stair_" .. subname .. " 8",
  147. recipe = {
  148. {recipeitem, "", ""},
  149. {recipeitem, recipeitem, ""},
  150. {recipeitem, recipeitem, recipeitem}
  151. }
  152. })
  153. minetest.register_craft({
  154. output = "stairs:stair_" .. subname .. " 8",
  155. recipe = {
  156. {"", "", recipeitem},
  157. {"", recipeitem, recipeitem},
  158. {recipeitem, recipeitem, recipeitem}
  159. }
  160. })
  161. -- stair to original material recipe
  162. minetest.register_craft({
  163. output = recipeitem .. " 3",
  164. recipe = {
  165. {"stairs:stair_" .. subname, "stairs:stair_" .. subname},
  166. {"stairs:stair_" .. subname, "stairs:stair_" .. subname}
  167. }
  168. })
  169. set_burn(recipeitem, "stairs:stair_" .. subname, 0.75)
  170. end
  171. -- Node will be called stairs:slab_<subname>
  172. function stairs.register_slab(
  173. subname, recipeitem, groups, images, description, snds, wat)
  174. local slab_images = set_textures(images, wat)
  175. local new_groups = table.copy(groups)
  176. new_groups.slab = 1
  177. minetest.register_node(":stairs:slab_" .. subname, {
  178. description = description,
  179. drawtype = "nodebox",
  180. tiles = slab_images,
  181. paramtype = "light",
  182. paramtype2 = "facedir",
  183. is_ground_content = false,
  184. use_texture_alpha = get_alpha(recipeitem),
  185. light_source = get_light(recipeitem),
  186. groups = new_groups,
  187. sounds = snds,
  188. node_box = {
  189. type = "fixed",
  190. fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}
  191. },
  192. on_place = function(itemstack, placer, pointed_thing)
  193. return stair_place(itemstack, placer, pointed_thing,
  194. "stairs:slab_" .. subname)
  195. end
  196. })
  197. -- if no recipe item provided then skip craft recipes
  198. if not recipeitem then
  199. return
  200. end
  201. -- slab recipe
  202. minetest.register_craft({
  203. output = "stairs:slab_" .. subname .. " 6",
  204. recipe = {
  205. {recipeitem, recipeitem, recipeitem}
  206. }
  207. })
  208. -- slab to original material recipe
  209. minetest.register_craft({
  210. output = recipeitem,
  211. recipe = {
  212. {"stairs:slab_" .. subname},
  213. {"stairs:slab_" .. subname}
  214. }
  215. })
  216. set_burn(recipeitem, "stairs:slab_" .. subname, 0.5)
  217. end
  218. -- Node will be called stairs:stair_outer_<subname>
  219. function stairs.register_stair_outer(
  220. subname, recipeitem, groups, images, description, snds, wat, fdesc)
  221. local stair_images = set_textures(images, wat)
  222. local new_groups = table.copy(groups)
  223. new_groups.stair = 1
  224. minetest.register_node(":stairs:stair_outer_" .. subname, {
  225. description = fdesc or "Outer " .. description,
  226. drawtype = "nodebox",
  227. tiles = stair_images,
  228. paramtype = "light",
  229. paramtype2 = "facedir",
  230. is_ground_content = false,
  231. use_texture_alpha = get_alpha(recipeitem),
  232. light_source = get_light(recipeitem),
  233. groups = new_groups,
  234. sounds = snds,
  235. node_box = {
  236. type = "fixed",
  237. fixed = {
  238. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  239. {-0.5, 0, 0, 0, 0.5, 0.5}
  240. },
  241. },
  242. on_place = function(itemstack, placer, pointed_thing)
  243. return stair_place(itemstack, placer, pointed_thing,
  244. "stairs:stair_outer_" .. subname)
  245. end
  246. })
  247. -- add alias for old stairs redo name
  248. minetest.register_alias("stairs:corner_" .. subname,
  249. "stairs:stair_outer_" .. subname)
  250. -- if no recipe item provided then skip craft recipes
  251. if not recipeitem then
  252. return
  253. end
  254. -- corner stair recipe
  255. minetest.register_craft({
  256. output = "stairs:stair_outer_" .. subname .. " 6",
  257. recipe = {
  258. {"", "", ""},
  259. {"", recipeitem, ""},
  260. {recipeitem, recipeitem, recipeitem}
  261. },
  262. })
  263. -- corner stair to original material recipe
  264. minetest.register_craft({
  265. output = recipeitem .. " 2",
  266. recipe = {
  267. {"stairs:stair_outer_" .. subname,
  268. "stairs:stair_outer_" .. subname},
  269. {"stairs:stair_outer_" .. subname,
  270. "stairs:stair_outer_" .. subname}
  271. }
  272. })
  273. set_burn(recipeitem, "stairs:stair_outer_" .. subname, 0.625)
  274. end
  275. -- Node will be called stairs:stair_inner_<subname>
  276. function stairs.register_stair_inner(
  277. subname, recipeitem, groups, images, description, snds, wat, fdesc)
  278. local stair_images = set_textures(images, wat)
  279. local new_groups = table.copy(groups)
  280. new_groups.stair = 1
  281. minetest.register_node(":stairs:stair_inner_" .. subname, {
  282. description = fdesc or "Inner " .. description,
  283. drawtype = "nodebox",
  284. tiles = stair_images,
  285. paramtype = "light",
  286. paramtype2 = "facedir",
  287. is_ground_content = false,
  288. use_texture_alpha = get_alpha(recipeitem),
  289. light_source = get_light(recipeitem),
  290. groups = new_groups,
  291. sounds = snds,
  292. node_box = {
  293. type = "fixed",
  294. fixed = {
  295. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  296. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  297. {-0.5, 0, -0.5, 0, 0.5, 0}
  298. }
  299. },
  300. on_place = function(itemstack, placer, pointed_thing)
  301. return stair_place(itemstack, placer, pointed_thing,
  302. "stairs:stair_inner_" .. subname)
  303. end,
  304. })
  305. -- add alias for old stairs redo name
  306. minetest.register_alias("stairs:invcorner_" .. subname,
  307. "stairs:stair_inner_" .. subname)
  308. -- if no recipe item provided then skip craft recipes
  309. if not recipeitem then
  310. return
  311. end
  312. -- inside corner stair recipe
  313. minetest.register_craft({
  314. output = "stairs:stair_inner_" .. subname .. " 9",
  315. recipe = {
  316. {recipeitem, recipeitem, ""},
  317. {recipeitem, recipeitem, recipeitem},
  318. {recipeitem, recipeitem, recipeitem},
  319. }
  320. })
  321. -- inside corner stair to original material recipe
  322. minetest.register_craft({
  323. output = recipeitem .. " 3",
  324. recipe = {
  325. {"stairs:stair_inner_" .. subname,
  326. "stairs:stair_inner_" .. subname},
  327. {"stairs:stair_inner_" .. subname,
  328. "stairs:stair_inner_" .. subname}
  329. }
  330. })
  331. set_burn(recipeitem, "stairs:stair_inner_" .. subname, 0.875)
  332. end
  333. -- Node will be called stairs:slope_<subname>
  334. function stairs.register_slope(
  335. subname, recipeitem, groups, images, description, snds, wat)
  336. local stair_images = set_textures(images, wat)
  337. local new_groups = table.copy(groups)
  338. new_groups.stair = 1
  339. minetest.register_node(":stairs:slope_" .. subname, {
  340. description = description,
  341. drawtype = "mesh",
  342. mesh = "stairs_slope.obj",
  343. tiles = stair_images,
  344. paramtype = "light",
  345. paramtype2 = "facedir",
  346. is_ground_content = false,
  347. use_texture_alpha = get_alpha(recipeitem),
  348. light_source = get_light(recipeitem),
  349. groups = new_groups,
  350. sounds = snds,
  351. selection_box = {
  352. type = "fixed",
  353. fixed = {
  354. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  355. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  356. },
  357. },
  358. collision_box = {
  359. type = "fixed",
  360. fixed = {
  361. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  362. {-0.5, 0, 0, 0.5, 0.5, 0.5}
  363. },
  364. },
  365. on_place = function(itemstack, placer, pointed_thing)
  366. return stair_place(itemstack, placer, pointed_thing,
  367. "stairs:slope_" .. subname)
  368. end
  369. })
  370. -- slope recipe
  371. minetest.register_craft({
  372. output = "stairs:slope_" .. subname .. " 6",
  373. recipe = {
  374. {recipeitem, "", ""},
  375. {recipeitem, recipeitem, ""}
  376. }
  377. })
  378. -- slope to original material recipe
  379. minetest.register_craft({
  380. output = recipeitem,
  381. recipe = {
  382. {"stairs:slope_" .. subname, "stairs:slope_" .. subname}
  383. }
  384. })
  385. set_burn(recipeitem, "stairs:slope_" .. subname, 0.5)
  386. end
  387. -- Nodes will be called stairs:{stair,slab}_<subname>
  388. function stairs.register_stair_and_slab(
  389. subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, wat)
  390. stairs.register_stair(
  391. subname, recipeitem, groups, images, desc_stair, sounds, wat)
  392. stairs.register_stair_inner(
  393. subname, recipeitem, groups, images, desc_stair, sounds, wat)
  394. stairs.register_stair_outer(
  395. subname, recipeitem, groups, images, desc_stair, sounds, wat)
  396. stairs.register_slab(
  397. subname, recipeitem, groups, images, desc_slab, sounds, wat)
  398. end
  399. -- Nodes will be called stairs:{stair,slab,corner,invcorner,slope}_<subname>
  400. function stairs.register_all(
  401. subname, recipeitem, groups, images, desc, snds, wat)
  402. stairs.register_stair(
  403. subname, recipeitem, groups, images, desc .. " Stair", snds, wat)
  404. stairs.register_slab(
  405. subname, recipeitem, groups, images, desc .. " Slab", snds, wat)
  406. stairs.register_stair_inner(
  407. subname, recipeitem, groups, images, desc .. " Stair", snds, wat)
  408. stairs.register_stair_outer(
  409. subname, recipeitem, groups, images, desc .. " Stair", snds, wat)
  410. stairs.register_slope(
  411. subname, recipeitem, groups, images, desc .. " Slope", snds, wat)
  412. end
  413. -- compatibility function for previous stairs:invcorner_<subname>
  414. function stairs.register_invcorner(
  415. subname, recipeitem, groups, images, desc, snds, wat)
  416. stairs.register_stair_inner(
  417. subname, recipeitem, groups, images, desc .. " Stair", snds, wat)
  418. end
  419. -- compatibility function for previous stairs:corner_<subname>
  420. function stairs.register_corner(
  421. subname, recipeitem, groups, images, desc, snds, wat)
  422. stairs.register_stair_outer(
  423. subname, recipeitem, groups, images, desc .. " Stair", snds, wat)
  424. end
  425. -- Register stairs
  426. dofile(minetest.get_modpath("stairs") .. "/stairs.lua")
  427. print ("[MOD] Stairs Redo loaded")