init.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. -- Minetest 0.4 mod: stairs
  2. -- See README.txt for licensing and other information.
  3. -- Localize for performance.
  4. local math_floor = math.floor
  5. local math_random = math.random
  6. -- Global namespace for functions
  7. local S = function(str) return str end
  8. stairs = {}
  9. circular_saw = circular_saw or {}
  10. circular_saw.known_nodes = circular_saw.known_nodes or {}
  11. -- Also used by walls.
  12. function stairs.setup_nodedef_callbacks(subname, def)
  13. if string.find(subname, "ice") or string.find(subname, "snow") then
  14. assert(not def.on_construct)
  15. def.on_construct = function(pos)
  16. if rc.ice_melts_at_pos(pos) then
  17. minetest.get_node_timer(pos):start(math_random(ice.minmax_time()))
  18. end
  19. end
  20. assert(not def.on_timer)
  21. def.on_timer = function(pos, elapsed)
  22. if rc.ice_melts_at_pos(pos) then
  23. minetest.add_node(pos, {name="default:water_flowing"})
  24. end
  25. end
  26. end
  27. end
  28. function stairs.rotate_and_place(itemstack, placer, pt)
  29. if pt.type == "node" then
  30. local node = minetest.get_node(pt.under)
  31. if node.name == itemstack:get_name() then
  32. local param2 = node.param2
  33. return minetest.item_place(itemstack, placer, pt, param2)
  34. end
  35. end
  36. return minetest.rotate_node(itemstack, placer, pt)
  37. end
  38. dofile(minetest.get_modpath("stairs") .. "/slopes.lua")
  39. local slabs_defs = {
  40. ["_quarter"] = {num=4, light=0.25, is_flat=true},
  41. ["_three_quarter"] = {num=12, light=0.75, is_flat=true},
  42. ["_1"] = {num=1, light=1/16, is_flat=true},
  43. ["_2"] = {num=2, light=2/16, is_flat=true},
  44. ["_14"] = {num=14, light=14/16, is_flat=true},
  45. ["_15"] = {num=15, light=15/16, is_flat=true},
  46. ["_two_sides"] = {
  47. nodebox = {
  48. { -0.5, -0.5, -0.5, 0.5, -7/16, 7/16 },
  49. { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
  50. }
  51. },
  52. ["_three_sides"] = {
  53. nodebox = {
  54. { -7/16, -0.5, -0.5, 0.5, -7/16, 7/16 },
  55. { -7/16, -0.5, 7/16, 0.5, 0.5, 0.5 },
  56. { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
  57. }
  58. },
  59. ["_three_sides_u"] = {
  60. nodebox = {
  61. { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
  62. { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
  63. { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
  64. }
  65. },
  66. ["_four_sides"] = {
  67. nodebox = {
  68. { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
  69. { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
  70. { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
  71. { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
  72. }
  73. },
  74. ["_hole"] = {
  75. nodebox = {
  76. {-0.5, -0.5, -0.5, 0.5, 0.5, -7/16},
  77. {-0.5, -0.5, 0.5, 0.5, 0.5, 7/16},
  78. {-0.5, -0.5, -7/16, -7/16, 0.5, 7/16},
  79. {0.5, -0.5, -7/16, 7/16, 0.5, 7/16},
  80. }
  81. },
  82. ["_two_opposite"] = {
  83. nodebox = {
  84. {-0.5, -0.5, -0.5, 0.5, 0.5, -7/16},
  85. {-0.5, -0.5, 0.5, 0.5, 0.5, 7/16},
  86. }
  87. },
  88. ["_pit"] = {
  89. nodebox = {
  90. { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
  91. { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
  92. { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
  93. { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
  94. { -7/16, 0.5, -7/16, 0.5, 7/16, 7/16 },
  95. }
  96. },
  97. ["_pit_half"] = {
  98. nodebox = {
  99. { -0.5, -0.5, -0.5, 0.0, 0.5, -7/16 },
  100. { -0.5, -0.5, -7/16, 0.0, -7/16, 7/16 },
  101. { -0.5, -0.5, 7/16, 0.0, 0.5, 0.5 },
  102. { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
  103. { -7/16, 0.5, -7/16, 0.0, 7/16, 7/16 },
  104. }
  105. },
  106. ["_hole_half"] = {
  107. nodebox = {
  108. {-0.5, -0.5, -0.5, 0.5, 0, -7/16},
  109. {-0.5, -0.5, 0.5, 0.5, 0, 7/16},
  110. {-0.5, -0.5, -7/16, -7/16, 0, 7/16},
  111. {0.5, -0.5, -7/16, 7/16, 0, 7/16},
  112. }
  113. },
  114. }
  115. function stairs.register_extra_slabs(subname, recipeitem, groups, images, description, sounds)
  116. local stair_images = {}
  117. for i, image in ipairs(images) do
  118. if type(image) == "string" then
  119. stair_images[i] = {
  120. name = image,
  121. backface_culling = true,
  122. }
  123. elseif image.backface_culling == nil then -- override using any other value
  124. stair_images[i] = table.copy(image)
  125. stair_images[i].backface_culling = true
  126. end
  127. end
  128. local defs = table.copy(slabs_defs)
  129. -- Do not modify function argument.
  130. local groups = table.copy(groups)
  131. groups.not_in_craft_guide = 1
  132. groups.stairs_slab = 1
  133. groups.stairs_node = 1
  134. local ndef = minetest.registered_items[recipeitem]
  135. assert(ndef)
  136. for alternate, num in pairs(defs) do
  137. local def
  138. if num.num then
  139. def = {
  140. node_box = {
  141. type = "fixed",
  142. fixed = {-0.5, -0.5, -0.5, 0.5, (num.num/16)-0.5, 0.5},
  143. }
  144. }
  145. elseif num.nodebox then
  146. def = {
  147. node_box = {
  148. type = "fixed",
  149. fixed = num.nodebox,
  150. }
  151. }
  152. end
  153. def.drawtype = "nodebox"
  154. def.paramtype = "light"
  155. def.paramtype2 = "facedir"
  156. def.on_place = function(...) return stairs.rotate_and_place(...) end
  157. def.groups = groups
  158. def.sounds = sounds
  159. def.description = description
  160. def.tiles = stair_images
  161. def.light_source = math.ceil(ndef.light_source*(num.light or 0))
  162. -- Only for flat slabs.
  163. if num.is_flat then
  164. def.movement_speed_depends = recipeitem
  165. end
  166. stairs.setup_nodedef_callbacks(subname, def)
  167. minetest.register_node(":stairs:slab_" .. subname .. alternate, def)
  168. end
  169. if recipeitem then
  170. circular_saw.known_nodes[recipeitem] = {"stairs", subname}
  171. end
  172. end
  173. local stairs_defs = {
  174. ["_half"] = {
  175. node_box = {
  176. type = "fixed",
  177. fixed = {
  178. {-0.5, -0.5, -0.5, 0, 0, 0.5},
  179. {-0.5, 0, 0, 0, 0.5, 0.5},
  180. },
  181. },
  182. light=3/8,
  183. },
  184. ["_right_half" ]= {
  185. node_box = {
  186. type = "fixed",
  187. fixed = {
  188. {0, -0.5, -0.5, 0.5, 0, 0.5},
  189. {0, 0, 0, 0.5, 0.5, 0.5},
  190. },
  191. },
  192. light=3/8,
  193. },
  194. ["_half_1"] = {
  195. node_box = {
  196. type = "fixed",
  197. fixed = {
  198. {-0.5, -0.5, -0.5, -7/16, 0, 0.5},
  199. {-0.5, 0, 0, -7/16, 0.5, 0.5},
  200. },
  201. },
  202. light=1/8,
  203. },
  204. ["_right_half_1" ]= {
  205. node_box = {
  206. type = "fixed",
  207. fixed = {
  208. {7/16, -0.5, -0.5, 0.5, 0, 0.5},
  209. {7/16, 0, 0, 0.5, 0.5, 0.5},
  210. },
  211. },
  212. light=1/8,
  213. },
  214. ["_inner"] = {
  215. node_box = {
  216. type = "fixed",
  217. fixed = {
  218. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  219. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  220. {-0.5, 0, -0.5, 0, 0.5, 0},
  221. },
  222. },
  223. light=7/8,
  224. },
  225. ["_outer"] = {
  226. node_box = {
  227. type = "fixed",
  228. fixed = {
  229. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  230. {-0.5, 0, 0, 0, 0.5, 0.5},
  231. },
  232. },
  233. light=5/8,
  234. },
  235. ["_alt"] = {
  236. node_box = {
  237. type = "fixed",
  238. fixed = {
  239. {-0.5, -0.5, -0.5, 0.5, 0, 0},
  240. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  241. },
  242. },
  243. light=1/2,
  244. },
  245. ["_alt_1"] = {
  246. node_box = {
  247. type = "fixed",
  248. fixed = {
  249. {-0.5, -0.0625, -0.5, 0.5, 0, 0},
  250. {-0.5, 0.4375, 0, 0.5, 0.5, 0.5},
  251. },
  252. },
  253. light=1/16,
  254. },
  255. ["_alt_5"] = {
  256. node_box = {
  257. type = "fixed",
  258. fixed = {
  259. {-0.5, -0.0625, 0.0, 0.5, 0, 0.5},
  260. {-0.5, 0.4375, 0, 0.5, 0.5, 0.5},
  261. },
  262. },
  263. light=1/16,
  264. },
  265. ["_alt_6"] = {
  266. node_box = {
  267. type = "fixed",
  268. fixed = {
  269. {-0.5, -0.0625, -0.5, 0.5, 0, 0.5},
  270. {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
  271. },
  272. },
  273. light=1/16,
  274. },
  275. ["_alt_2"] = {
  276. node_box = {
  277. type = "fixed",
  278. fixed = {
  279. {-0.5, -0.125, -0.5, 0.5, 0, 0},
  280. {-0.5, 0.375, 0, 0.5, 0.5, 0.5},
  281. },
  282. },
  283. light=2/16,
  284. },
  285. ["_alt_4"] = {
  286. node_box = {
  287. type = "fixed",
  288. fixed = {
  289. {-0.5, -0.25, -0.5, 0.5, 0, 0},
  290. {-0.5, 0.25, 0, 0.5, 0.5, 0.5},
  291. },
  292. },
  293. light=4/16,
  294. },
  295. }
  296. function stairs.register_extra_stairs(subname, recipeitem, groups, images, description, sounds)
  297. local stair_images = {}
  298. for i, image in ipairs(images) do
  299. if type(image) == "string" then
  300. stair_images[i] = {
  301. name = image,
  302. backface_culling = true,
  303. }
  304. elseif image.backface_culling == nil then -- override using any other value
  305. stair_images[i] = table.copy(image)
  306. stair_images[i].backface_culling = true
  307. end
  308. end
  309. local defs = table.copy(stairs_defs)
  310. -- Do not modify function argument.
  311. local groups = table.copy(groups)
  312. groups.not_in_craft_guide = 1
  313. groups.stairs_stair = 1
  314. groups.stairs_node = 1
  315. local ndef = minetest.registered_items[recipeitem]
  316. assert(ndef)
  317. for alternate, def in pairs(defs) do
  318. def.drawtype = "nodebox"
  319. def.paramtype = "light"
  320. def.paramtype2 = "facedir"
  321. def.on_place = function(...) return stairs.rotate_and_place(...) end
  322. def.groups = groups
  323. def.sounds = sounds
  324. def.description = description
  325. def.tiles = stair_images
  326. def.light_source = math.ceil(ndef.light_source*def.light)
  327. def.light = nil
  328. stairs.setup_nodedef_callbacks(subname, def)
  329. minetest.register_node(":stairs:stair_" ..subname..alternate, def)
  330. if recipeitem then
  331. if alternate == "_inner" then
  332. minetest.register_craft({
  333. type = "shapeless",
  334. output = recipeitem .. ' 7',
  335. recipe = {
  336. "stairs:stair_" .. subname .. alternate,
  337. "stairs:stair_" .. subname .. alternate,
  338. "stairs:stair_" .. subname .. alternate,
  339. "stairs:stair_" .. subname .. alternate,
  340. "stairs:stair_" .. subname .. alternate,
  341. "stairs:stair_" .. subname .. alternate,
  342. "stairs:stair_" .. subname .. alternate,
  343. "stairs:stair_" .. subname .. alternate,
  344. },
  345. })
  346. minetest.register_craft({
  347. output = "stairs:stair_" .. subname .. alternate .. ' 8',
  348. recipe = {
  349. {recipeitem, recipeitem, recipeitem},
  350. {recipeitem, recipeitem, ''},
  351. {recipeitem, '', recipeitem},
  352. },
  353. })
  354. elseif alternate == "_outer" then
  355. minetest.register_craft({
  356. type = "shapeless",
  357. output = recipeitem .. ' 5',
  358. recipe = {
  359. "stairs:stair_" .. subname .. alternate,
  360. "stairs:stair_" .. subname .. alternate,
  361. "stairs:stair_" .. subname .. alternate,
  362. "stairs:stair_" .. subname .. alternate,
  363. "stairs:stair_" .. subname .. alternate,
  364. "stairs:stair_" .. subname .. alternate,
  365. "stairs:stair_" .. subname .. alternate,
  366. "stairs:stair_" .. subname .. alternate,
  367. },
  368. })
  369. minetest.register_craft({
  370. output = "stairs:stair_" .. subname .. alternate .. ' 8',
  371. recipe = {
  372. {recipeitem, recipeitem, recipeitem},
  373. {recipeitem, '', ''},
  374. {recipeitem, '', ''},
  375. },
  376. })
  377. end
  378. end
  379. end
  380. minetest.register_alias("stairs:stair_" ..subname.. "_bottom", "stairs:stair_" ..subname)
  381. if recipeitem then
  382. circular_saw.known_nodes[recipeitem] = {"stairs", subname}
  383. end
  384. end
  385. local panels_defs = {
  386. [""] = {
  387. node_box = {
  388. type = "fixed",
  389. fixed = {-0.5, -0.5, 0, 0.5, 0, 0.5},
  390. },
  391. light=1/4,
  392. },
  393. ["_1"] = {
  394. node_box = {
  395. type = "fixed",
  396. fixed = {-0.5, -0.5, 0, 0.5, -0.4375, 0.5},
  397. },
  398. light=1/32,
  399. },
  400. ["_2"] = {
  401. node_box = {
  402. type = "fixed",
  403. fixed = {-0.5, -0.5, 0, 0.5, -0.375, 0.5},
  404. },
  405. light=2/32,
  406. },
  407. ["_4"] = {
  408. node_box = {
  409. type = "fixed",
  410. fixed = {-0.5, -0.5, 0, 0.5, -0.25, 0.5},
  411. },
  412. light=4/32,
  413. },
  414. ["_12"] = {
  415. node_box = {
  416. type = "fixed",
  417. fixed = {-0.5, -0.5, 0, 0.5, 0.25, 0.5},
  418. },
  419. light=12/32,
  420. },
  421. ["_14"] = {
  422. node_box = {
  423. type = "fixed",
  424. fixed = {-0.5, -0.5, 0, 0.5, 0.375, 0.5},
  425. },
  426. light=14/32,
  427. },
  428. ["_15"] = {
  429. node_box = {
  430. type = "fixed",
  431. fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
  432. },
  433. light=15/32,
  434. },
  435. ["_16"] = {
  436. node_box = {
  437. type = "fixed",
  438. fixed = {-0.5, -0.5, 0, 0.5, 0.5, 0.5},
  439. },
  440. light=16/32,
  441. }
  442. }
  443. function stairs.register_panel(subname, recipeitem, groups, images, description, sounds)
  444. local stair_images = {}
  445. for i, image in ipairs(images) do
  446. if type(image) == "string" then
  447. stair_images[i] = {
  448. name = image,
  449. backface_culling = true,
  450. }
  451. elseif image.backface_culling == nil then -- override using any other value
  452. stair_images[i] = table.copy(image)
  453. stair_images[i].backface_culling = true
  454. end
  455. end
  456. local defs = table.copy(panels_defs)
  457. -- Do not modify function argument.
  458. local groups = table.copy(groups)
  459. groups.not_in_craft_guide = 1
  460. groups.stairs_panel = 1
  461. groups.stairs_node = 1
  462. local ndef = minetest.registered_items[recipeitem]
  463. assert(ndef)
  464. for alternate, def in pairs(defs) do
  465. def.drawtype = "nodebox"
  466. def.paramtype = "light"
  467. def.paramtype2 = "facedir"
  468. def.on_place = function(...) return stairs.rotate_and_place(...) end
  469. def.groups = groups
  470. def.sounds = sounds
  471. def.description = description
  472. def.tiles = stair_images
  473. def.light_source = math.ceil(ndef.light_source*def.light)
  474. def.light = nil
  475. stairs.setup_nodedef_callbacks(subname, def)
  476. minetest.register_node(":stairs:panel_" ..subname..alternate, def)
  477. end
  478. minetest.register_alias("stairs:panel_" ..subname.. "_bottom", "stairs:panel_" ..subname)
  479. if recipeitem then
  480. circular_saw.known_nodes[recipeitem] = {"stairs", subname}
  481. end
  482. end
  483. local microblocks_defs = {
  484. [""] = {
  485. node_box = {
  486. type = "fixed",
  487. fixed = {-0.5, -0.5, 0, 0, 0, 0.5},
  488. },
  489. light=8/64,
  490. },
  491. ["_c"] = {
  492. node_box = {
  493. type = "fixed",
  494. fixed = {-0.25, -0.5, -0.25, 0.25, 0, 0.25},
  495. },
  496. light=8/64,
  497. },
  498. ["_1c"] = {
  499. node_box = {
  500. type = "fixed",
  501. fixed = {-0.25, -0.5, -0.25, 0.25, -0.4375, 0.25},
  502. },
  503. light=1/64,
  504. },
  505. ["_1"] = {
  506. node_box = {
  507. type = "fixed",
  508. fixed = {-0.5, -0.5, 0, 0, -0.4375, 0.5},
  509. },
  510. light=1/64,
  511. },
  512. ["_2"] = {
  513. node_box = {
  514. type = "fixed",
  515. fixed = {-0.5, -0.5, 0, 0, -0.375, 0.5},
  516. },
  517. light=2/64,
  518. },
  519. ["_4"] = {
  520. node_box = {
  521. type = "fixed",
  522. fixed = {-0.5, -0.5, 0, 0, -0.25, 0.5},
  523. },
  524. light=4/64,
  525. },
  526. ["_12"] = {
  527. node_box = {
  528. type = "fixed",
  529. fixed = {-0.5, -0.5, 0, 0, 0.25, 0.5},
  530. },
  531. light=12/64,
  532. },
  533. ["_14"] = {
  534. node_box = {
  535. type = "fixed",
  536. fixed = {-0.5, -0.5, 0, 0, 0.375, 0.5},
  537. },
  538. light=14/64,
  539. },
  540. ["_15"] = {
  541. node_box = {
  542. type = "fixed",
  543. fixed = {-0.5, -0.5, 0, 0, 0.4375, 0.5},
  544. },
  545. light=15/64,
  546. },
  547. ["_16"] = {
  548. node_box = {
  549. type = "fixed",
  550. fixed = {-0.5, -0.5, 0, 0, 0.5, 0.5},
  551. },
  552. light=16/64,
  553. },
  554. ["_1s"] = {
  555. node_box = {
  556. type = "fixed",
  557. fixed = {
  558. {-0.5, -0.5, -0.5, 0, -0.4375, 0},
  559. {0, -0.5, 0, 0.5, -0.4375, 0.5},
  560. },
  561. },
  562. light=2/64,
  563. },
  564. ["_16s"] = {
  565. node_box = {
  566. type = "fixed",
  567. fixed = {
  568. {-0.5, -0.5, -0.5, 0, 0, 0},
  569. {0, -0.5, 0, 0.5, 0, 0.5},
  570. },
  571. },
  572. light=16/64,
  573. }
  574. }
  575. function stairs.register_micro(subname, recipeitem, groups, images, description, sounds)
  576. local stair_images = {}
  577. for i, image in ipairs(images) do
  578. if type(image) == "string" then
  579. stair_images[i] = {
  580. name = image,
  581. backface_culling = true,
  582. }
  583. elseif image.backface_culling == nil then -- override using any other value
  584. stair_images[i] = table.copy(image)
  585. stair_images[i].backface_culling = true
  586. end
  587. end
  588. local defs = table.copy(microblocks_defs)
  589. -- Do not modify function argument.
  590. local groups = table.copy(groups)
  591. groups.not_in_craft_guide = 1
  592. groups.stairs_microblock = 1
  593. groups.stairs_node = 1
  594. local ndef = minetest.registered_items[recipeitem]
  595. assert(ndef)
  596. for alternate, def in pairs(defs) do
  597. def.drawtype = "nodebox"
  598. def.paramtype = "light"
  599. def.paramtype2 = "facedir"
  600. def.on_place = function(...) return stairs.rotate_and_place(...) end
  601. def.groups = groups
  602. def.sounds = sounds
  603. def.description = description
  604. def.tiles = stair_images
  605. def.light_source = math.ceil(ndef.light_source*def.light)
  606. def.light = nil
  607. stairs.setup_nodedef_callbacks(subname, def)
  608. minetest.register_node(":stairs:micro_" .. subname .. alternate, def)
  609. end
  610. minetest.register_alias("stairs:micro_" ..subname.. "_bottom", "stairs:micro_" ..subname)
  611. if recipeitem then
  612. circular_saw.known_nodes[recipeitem] = {"stairs", subname}
  613. end
  614. end
  615. -- Register aliases for new pine node names
  616. minetest.register_alias("stairs:stair_pinewood", "stairs:stair_pine_wood")
  617. minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
  618. -- Register stairs.
  619. -- Node will be called stairs:stair_<subname>
  620. function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
  621. local stair_images = {}
  622. for i, image in ipairs(images) do
  623. if type(image) == "string" then
  624. stair_images[i] = {
  625. name = image,
  626. backface_culling = true,
  627. }
  628. elseif image.backface_culling == nil then -- override using any other value
  629. stair_images[i] = table.copy(image)
  630. stair_images[i].backface_culling = true
  631. end
  632. end
  633. -- Do not modify function argument.
  634. groups = table.copy(groups)
  635. groups.stair = 1
  636. groups.stairs_stair = 1
  637. groups.not_in_craft_guide = 1
  638. groups.stairs_node = 1
  639. local ndef = minetest.registered_items[recipeitem]
  640. assert(ndef)
  641. local stair_def = {
  642. description = description,
  643. drawtype = "mesh",
  644. mesh = "stairs_stair.obj",
  645. tiles = stair_images,
  646. paramtype = "light",
  647. paramtype2 = "facedir",
  648. is_ground_content = false,
  649. groups = groups,
  650. sounds = sounds,
  651. move_speed_stair = recipeitem,
  652. light_source = math.ceil(ndef.light_source*0.75),
  653. selection_box = {
  654. type = "fixed",
  655. fixed = {
  656. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  657. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  658. },
  659. },
  660. collision_box = {
  661. type = "fixed",
  662. fixed = {
  663. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  664. {-0.5, 0, 0, 0.5, 0.5, 0.5},
  665. },
  666. },
  667. on_place = function(itemstack, placer, pointed_thing)
  668. if pointed_thing.type ~= "node" then
  669. return itemstack
  670. end
  671. local p0 = pointed_thing.under
  672. local p1 = pointed_thing.above
  673. local param2 = 0
  674. local placer_pos = placer:get_pos()
  675. if placer_pos then
  676. local dir = {
  677. x = p1.x - placer_pos.x,
  678. y = p1.y - placer_pos.y,
  679. z = p1.z - placer_pos.z
  680. }
  681. param2 = minetest.dir_to_facedir(dir)
  682. end
  683. if p0.y - 1 == p1.y then
  684. param2 = param2 + 20
  685. if param2 == 21 then
  686. param2 = 23
  687. elseif param2 == 23 then
  688. param2 = 21
  689. end
  690. end
  691. return minetest.item_place(itemstack, placer, pointed_thing, param2)
  692. end,
  693. }
  694. stairs.setup_nodedef_callbacks(subname, stair_def)
  695. minetest.register_node(":stairs:stair_" .. subname, stair_def)
  696. if recipeitem then
  697. assert(type(recipeitem) == "string")
  698. circular_saw.known_nodes[recipeitem] = {"stairs", subname}
  699. -- Use stairs to craft full blocks again (1:1)
  700. minetest.register_craft({
  701. output = recipeitem .. ' 3',
  702. recipe = {
  703. {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
  704. {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
  705. },
  706. })
  707. -- Recipe matches appearence in inventory
  708. minetest.register_craft({
  709. output = 'stairs:stair_' .. subname .. ' 8',
  710. recipe = {
  711. {"", "", recipeitem},
  712. {"", recipeitem, recipeitem},
  713. {recipeitem, recipeitem, recipeitem},
  714. },
  715. })
  716. end
  717. end
  718. -- Slab facedir to placement 6d matching table
  719. local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
  720. -- Slab facedir when placing initial slab against other surface
  721. local slab_trans_dir_place = {[0] = 0, 20, 12, 16, 4, 8}
  722. -- Register slabs.
  723. -- Node will be called stairs:slab_<subname>
  724. function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
  725. -- Do not modify function argument.
  726. groups = table.copy(groups)
  727. groups.slab = 1
  728. groups.stairs_slab = 1
  729. groups.not_in_craft_guide = 1
  730. groups.stairs_node = 1
  731. local ndef = minetest.registered_items[recipeitem]
  732. assert(ndef)
  733. local slab_def = {
  734. description = description,
  735. drawtype = "nodebox",
  736. tiles = images,
  737. paramtype = "light",
  738. paramtype2 = "facedir",
  739. is_ground_content = false,
  740. groups = groups,
  741. sounds = sounds,
  742. movement_speed_depends = recipeitem,
  743. light_source = math.ceil(ndef.light_source*0.5),
  744. node_box = {
  745. type = "fixed",
  746. fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  747. },
  748. on_place = function(itemstack, placer, pointed_thing)
  749. local under = minetest.get_node(pointed_thing.under)
  750. local wield_item = itemstack:get_name()
  751. if under and wield_item == under.name then
  752. -- place slab using under node orientation
  753. local dir = minetest.dir_to_facedir(vector.subtract(
  754. pointed_thing.above, pointed_thing.under), true)
  755. local p2 = under.param2
  756. -- combine two slabs if possible
  757. if slab_trans_dir[math_floor(p2 / 4)] == dir then
  758. if not recipeitem then
  759. return itemstack
  760. end
  761. local player_name = placer:get_player_name()
  762. if minetest.is_protected(pointed_thing.under, player_name) and not
  763. minetest.check_player_privs(placer, "protection_bypass") then
  764. minetest.record_protection_violation(pointed_thing.under,
  765. player_name)
  766. return
  767. end
  768. minetest.add_node(pointed_thing.under, {name = recipeitem, param2 = p2})
  769. if not minetest.setting_getbool("creative_mode") then
  770. itemstack:take_item()
  771. end
  772. return itemstack
  773. end
  774. -- Placing a slab on an upside down slab should make it right-side up.
  775. if p2 >= 20 and dir == 8 then
  776. p2 = p2 - 20
  777. -- same for the opposite case: slab below normal slab
  778. elseif p2 <= 3 and dir == 4 then
  779. p2 = p2 + 20
  780. end
  781. -- else attempt to place node with proper param2
  782. minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
  783. if not minetest.setting_getbool("creative_mode") then
  784. itemstack:take_item()
  785. end
  786. return itemstack
  787. else
  788. -- place slab using look direction of player
  789. local dir = minetest.dir_to_wallmounted(vector.subtract(
  790. pointed_thing.above, pointed_thing.under), true)
  791. local rot = slab_trans_dir_place[dir]
  792. if rot == 0 or rot == 20 then
  793. rot = rot + minetest.dir_to_facedir(placer:get_look_dir())
  794. end
  795. return minetest.item_place(itemstack, placer, pointed_thing, rot)
  796. end
  797. end,
  798. }
  799. stairs.setup_nodedef_callbacks(subname, slab_def)
  800. minetest.register_node(":stairs:slab_" .. subname, slab_def)
  801. if recipeitem then
  802. -- Use 2 slabs to craft a full block again (1:1)
  803. minetest.register_craft({
  804. output = recipeitem,
  805. recipe = {
  806. {'stairs:slab_' .. subname},
  807. {'stairs:slab_' .. subname},
  808. },
  809. })
  810. minetest.register_craft({
  811. output = 'stairs:slab_' .. subname .. ' 6',
  812. recipe = {
  813. {recipeitem, recipeitem, recipeitem},
  814. },
  815. })
  816. end
  817. end
  818. -- Stair/slab registration function.
  819. -- Now includes all extra blocks.
  820. function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc, sounds)
  821. stairs.register_micro(subname, recipeitem, groups, images, desc .. " Microblock", sounds)
  822. stairs.register_panel(subname, recipeitem, groups, images, desc .. " Panel", sounds)
  823. stairs.register_stair(subname, recipeitem, groups, images, desc .. " Stair", sounds)
  824. stairs.register_extra_stairs(subname, recipeitem, groups, images, desc .. " Stair", sounds)
  825. stairs.register_slab(subname, recipeitem, groups, images, desc .. " Slab", sounds)
  826. stairs.register_extra_slabs(subname, recipeitem, groups, images, desc .. " Slab", sounds)
  827. stairs.register_slopes(subname, recipeitem, groups, images, desc .. " Slope", sounds)
  828. end