init.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. local buildPlatform = function(node, pos, itemstack)
  2. -- code for the building platforms
  3. posZ = {'1', '0', '-1', '-1', '0', '0', '1', '1' };
  4. posX = {'0', '-1', '0', '0', '1', '1', '0', '0' };
  5. for nameCount = 1, 8 do
  6. pos.z = pos.z + posZ[nameCount];
  7. pos.x = pos.x + posX[nameCount];
  8. local current_node = minetest.get_node(pos);
  9. if current_node.name == "air" then
  10. minetest.set_node(pos, {name = node} )
  11. itemstack:take_item(1); --//and remove one if its the correct one
  12. break;
  13. end
  14. end
  15. -- end of function
  16. end
  17. local buildScaffolding = function(node, pos, itemstack, player)
  18. -- many thanks to addi for improveing (rewriteing) my crappy code --
  19. -- code for the building scaffolding
  20. height = 0;
  21. depth = 0; -- !!Note!! depth is not needed at the moment
  22. --[[ debug stuff ]]
  23. -- set pos at bottom of scafolding tower.
  24. repeat
  25. pos.y = pos.y - 1; --every run get one node up
  26. depth = depth - 1
  27. local current_node = minetest.get_node(pos); --get the node of the new position
  28. until current_node.name ~= node -- will repeat untill it dose not find a scaffolding node
  29. -- check height of scaffolding tower --
  30. repeat
  31. pos.y = pos.y + 1; --every run get one node up
  32. height = height + 1
  33. local current_node = minetest.get_node(pos); --get the node of the new position
  34. if current_node.name == "air" then
  35. minetest.set_node(pos, {name = node } )
  36. itemstack:take_item(1); --//and remove one if its the correct one
  37. player:set_wielded_item(itemstack);--//update inventory of the player
  38. end
  39. until current_node.name ~= node or height >= 32 --we repeat until we find something else then "scaffolding:scaffolding"
  40. --maybe there should be also another limit, because its currently possible to build infinite towers
  41. end
  42. print("scaffolding: Loading 'functions.lua'")
  43. dofile(minetest.get_modpath("scaffolding").."/functions.lua")
  44. minetest.register_craftitem("scaffolding:scaffolding_wrench", {
  45. description = "Scaffolding Wrench",
  46. inventory_image = "scaffolding_wrench.png",
  47. })
  48. minetest.register_node("scaffolding:scaffolding", {
  49. description = "Wooden Scaffolding",
  50. drawtype = "nodebox",
  51. tiles = {"scaffolding_wooden_scaffolding_top.png", "scaffolding_wooden_scaffolding_top.png", "scaffolding_wooden_scaffolding.png",
  52. "scaffolding_wooden_scaffolding.png", "scaffolding_wooden_scaffolding.png", "scaffolding_wooden_scaffolding.png"},
  53. use_texture_alpha = 'clip',
  54. paramtype = "light",
  55. paramtype2 = "facedir",
  56. climbable = true,
  57. walkable = false,
  58. is_ground_content = true,
  59. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
  60. sounds = default.node_sound_wood_defaults(),
  61. on_punch = function(pos, node, puncher)
  62. local tool = puncher:get_wielded_item():get_name()
  63. if tool and tool == "scaffolding:scaffolding_wrench" then
  64. node.name = "scaffolding:reinforced_scaffolding"
  65. minetest.env:set_node(pos, node)
  66. puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
  67. end
  68. end,
  69. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  70. -- if user hits scaffolding with platform Wooden scaffolding then --
  71. if itemstack:get_name() == "scaffolding:platform" then
  72. node = "scaffolding:platform";
  73. buildPlatform(node, pos, itemstack)
  74. end
  75. -- if user hits scaffolding with platform Iron scaffolding then --
  76. if itemstack:get_name() == "scaffolding:iron_platform" then
  77. node = "scaffolding:iron_platform";
  78. buildPlatform(node, pos, itemstack)
  79. end
  80. -- if user hits scaffolding with scaffolding then --
  81. if itemstack:get_name() == "scaffolding:scaffolding" then
  82. node = "scaffolding:scaffolding";
  83. local name = minetest.get_node(pos).name -- get loacation of node
  84. buildScaffolding(node, pos, itemstack, player)
  85. end
  86. end,
  87. node_box = {
  88. type = "fixed",
  89. fixed = {
  90. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  91. },
  92. },
  93. selection_box = {
  94. type = "fixed",
  95. fixed = {
  96. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  97. },
  98. },
  99. after_dig_node = function(pos, node, metadata, digger)
  100. default.dig_up(pos, node, digger)
  101. end,
  102. })
  103. minetest.register_node("scaffolding:reinforced_scaffolding", {
  104. description = "Wooden Scaffolding",
  105. drawtype = "nodebox",
  106. tiles = {"scaffolding_wooden_scaffolding.png^scaffolding_reinforced.png", "scaffolding_wooden_scaffolding.png^scaffolding_reinforced.png",
  107. "scaffolding_wooden_scaffolding.png^scaffolding_reinforced.png"},
  108. use_texture_alpha = 'clip',
  109. drop = "scaffolding:scaffolding",
  110. paramtype = "light",
  111. light_source = 14,
  112. paramtype2 = "facedir",
  113. climbable = true,
  114. walkable = false,
  115. is_ground_content = true,
  116. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
  117. sounds = default.node_sound_wood_defaults(),
  118. on_punch = function(pos, node, puncher)
  119. local tool = puncher:get_wielded_item():get_name()
  120. if tool and tool == "scaffolding:scaffolding_wrench" then
  121. node.name = "scaffolding:scaffolding"
  122. minetest.env:set_node(pos, node)
  123. puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
  124. end
  125. end,
  126. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  127. -- if user hits scaffolding with platform Wooden scaffolding then --
  128. if itemstack:get_name() == "scaffolding:platform" then
  129. node = "scaffolding:platform";
  130. buildPlatform(node, pos, itemstack)
  131. end
  132. -- if user hits scaffolding with platform Iron scaffolding then --
  133. if itemstack:get_name() == "scaffolding:iron_platform" then
  134. node = "scaffolding:iron_platform";
  135. buildPlatform(node, pos, itemstack)
  136. end
  137. end,
  138. node_box = {
  139. type = "fixed",
  140. fixed = {
  141. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  142. },
  143. },
  144. selection_box = {
  145. type = "fixed",
  146. fixed = {
  147. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  148. },
  149. },
  150. })
  151. minetest.register_node("scaffolding:platform", {
  152. description = "Wooden Platform",
  153. drawtype = "nodebox",
  154. tiles = {"scaffolding_wooden_scaffolding_top.png", "scaffolding_wooden_scaffolding_top.png", "scaffolding_wooden_scaffolding.png^scaffolding_platform.png"},
  155. use_texture_alpha = 'clip',
  156. paramtype = "light",
  157. paramtype2 = "facedir",
  158. climbable = false,
  159. walkable = true,
  160. is_ground_content = true,
  161. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
  162. sounds = default.node_sound_wood_defaults(),
  163. on_punch = function(pos, node, puncher)
  164. local tool = puncher:get_wielded_item():get_name()
  165. if tool and tool == "scaffolding:scaffolding_wrench" then
  166. node.name = "scaffolding:reinforced_platform"
  167. minetest.env:set_node(pos, node)
  168. end
  169. end,
  170. node_box = {
  171. type = "fixed",
  172. fixed = {
  173. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  174. },
  175. },
  176. selection_box = {
  177. type = "fixed",
  178. fixed = {
  179. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  180. },
  181. },
  182. after_dig_node = function(pos, node, metadata, digger)
  183. default.dig_horx(pos, node, digger)
  184. default.dig_horx2(pos, node, digger)
  185. default.dig_horz(pos, node, digger)
  186. default.dig_horz2(pos, node, digger)
  187. end,
  188. })
  189. minetest.register_node("scaffolding:reinforced_platform", {
  190. description = "Wooden Platform",
  191. drawtype = "nodebox",
  192. light_source = 14,
  193. tiles = {"scaffolding_wooden_scaffolding.png^scaffolding_reinforced.png", "scaffolding_wooden_scaffolding.png^scaffolding_reinforced.png", "scaffolding_wooden_scaffolding.png^scaffolding_platform.png"},
  194. use_texture_alpha = 'clip',
  195. drop = "scaffolding:platform",
  196. paramtype = "light",
  197. paramtype2 = "facedir",
  198. climbable = false,
  199. walkable = true,
  200. is_ground_content = true,
  201. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
  202. sounds = default.node_sound_wood_defaults(),
  203. on_punch = function(pos, node, puncher)
  204. local tool = puncher:get_wielded_item():get_name()
  205. if tool and tool == "scaffolding:scaffolding_wrench" then
  206. node.name = "scaffolding:platform"
  207. minetest.env:set_node(pos, node)
  208. end
  209. end,
  210. node_box = {
  211. type = "fixed",
  212. fixed = {
  213. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  214. },
  215. },
  216. selection_box = {
  217. type = "fixed",
  218. fixed = {
  219. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  220. },
  221. },
  222. })
  223. minetest.register_node("scaffolding:iron_scaffolding", {
  224. description = "Iron Scaffolding",
  225. drawtype = "nodebox",
  226. tiles = {"scaffolding_iron_scaffolding_top.png", "scaffolding_iron_scaffolding_top.png", "scaffolding_iron_scaffolding.png",
  227. "scaffolding_iron_scaffolding.png", "scaffolding_iron_scaffolding.png", "scaffolding_iron_scaffolding.png"},
  228. use_texture_alpha = 'clip',
  229. paramtype = "light",
  230. paramtype2 = "facedir",
  231. climbable = true,
  232. walkable = false,
  233. is_ground_content = true,
  234. groups = {snappy=2,cracky=3},
  235. sounds = default.node_sound_wood_defaults(),
  236. node_box = {
  237. type = "fixed",
  238. fixed = {
  239. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  240. },
  241. },
  242. selection_box = {
  243. type = "fixed",
  244. fixed = {
  245. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  246. },
  247. },
  248. on_punch = function(pos, node, puncher)
  249. local tool = puncher:get_wielded_item():get_name()
  250. if tool and tool == "scaffolding:scaffolding_wrench" then
  251. node.name = "scaffolding:reinforced_iron_scaffolding"
  252. minetest.env:set_node(pos, node)
  253. puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
  254. end
  255. end,
  256. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  257. -- if user hits scaffolding with platform Iron scaffolding then --
  258. if itemstack:get_name() == "scaffolding:iron_platform" then
  259. node = "scaffolding:iron_platform";
  260. buildPlatform(node, pos, itemstack)
  261. end
  262. -- if user hits scaffolding with platform Wooden scaffolding then --
  263. if itemstack:get_name() == "scaffolding:platform" then
  264. node = "scaffolding:platform";
  265. buildPlatform(node, pos, itemstack)
  266. end
  267. -- if user hits scaffolding with scaffolding then --
  268. if itemstack:get_name() == "scaffolding:iron_scaffolding" then
  269. node = "scaffolding:iron_scaffolding";
  270. local name = minetest.get_node(pos).name -- get loacation of node
  271. buildScaffolding(node, pos, itemstack, player)
  272. end
  273. end,
  274. after_dig_node = function(pos, node, metadata, digger)
  275. default.dig_up(pos, node, digger)
  276. end,
  277. })
  278. minetest.register_node("scaffolding:reinforced_iron_scaffolding", {
  279. description = "Iron Scaffolding",
  280. drawtype = "nodebox",
  281. tiles = {"scaffolding_iron_scaffolding.png^scaffolding_reinforced.png", "scaffolding_iron_scaffolding.png^scaffolding_reinforced.png",
  282. "scaffolding_iron_scaffolding.png^scaffolding_reinforced.png"},
  283. use_texture_alpha = 'clip',
  284. drop = "scaffolding:iron_scaffolding",
  285. paramtype = "light",
  286. paramtype2 = "facedir",
  287. climbable = true,
  288. walkable = false,
  289. light_source = 14,
  290. is_ground_content = true,
  291. groups = {snappy=2,cracky=3},
  292. sounds = default.node_sound_wood_defaults(),
  293. on_punch = function(pos, node, puncher)
  294. local tool = puncher:get_wielded_item():get_name()
  295. if tool and tool == "scaffolding:scaffolding_wrench" then
  296. node.name = "scaffolding:iron_scaffolding"
  297. minetest.env:set_node(pos, node)
  298. puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
  299. end
  300. end,
  301. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  302. -- if user hits scaffolding with platform Iron scaffolding then --
  303. if itemstack:get_name() == "scaffolding:iron_platform" then
  304. node = "scaffolding:iron_platform";
  305. buildPlatform(node, pos, itemstack)
  306. end
  307. -- if user hits scaffolding with platform Wooden scaffolding then --
  308. if itemstack:get_name() == "scaffolding:platform" then
  309. node = "scaffolding:platform";
  310. buildPlatform(node, pos, itemstack)
  311. end
  312. end,
  313. node_box = {
  314. type = "fixed",
  315. fixed = {
  316. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  317. },
  318. },
  319. selection_box = {
  320. type = "fixed",
  321. fixed = {
  322. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  323. },
  324. },
  325. })
  326. minetest.register_node("scaffolding:iron_platform", {
  327. description = "Iron Platform",
  328. drawtype = "nodebox",
  329. tiles = {"scaffolding_iron_scaffolding_top.png", "scaffolding_iron_scaffolding_top.png", "scaffolding_iron_scaffolding.png^scaffolding_platform.png"},
  330. use_texture_alpha = 'clip',
  331. paramtype = "light",
  332. paramtype2 = "facedir",
  333. climbable = false,
  334. walkable = true,
  335. is_ground_content = true,
  336. groups = {snappy=2,cracky=3},
  337. sounds = default.node_sound_wood_defaults(),
  338. on_punch = function(pos, node, puncher)
  339. local tool = puncher:get_wielded_item():get_name()
  340. if tool and tool == "scaffolding:scaffolding_wrench" then
  341. node.name = "scaffolding:reinforced_iron_platform"
  342. minetest.env:set_node(pos, node)
  343. end
  344. end,
  345. node_box = {
  346. type = "fixed",
  347. fixed = {
  348. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  349. },
  350. },
  351. selection_box = {
  352. type = "fixed",
  353. fixed = {
  354. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  355. },
  356. },
  357. after_dig_node = function(pos, node, metadata, digger)
  358. default.dig_horx(pos, node, digger)
  359. default.dig_horx2(pos, node, digger)
  360. default.dig_horz(pos, node, digger)
  361. default.dig_horz2(pos, node, digger)
  362. end,
  363. })
  364. minetest.register_node("scaffolding:reinforced_iron_platform", {
  365. description = "Iron Platform",
  366. drawtype = "nodebox",
  367. tiles = {"scaffolding_iron_scaffolding.png^scaffolding_reinforced.png", "scaffolding_iron_scaffolding.png^scaffolding_reinforced.png", "scaffolding_iron_scaffolding.png^scaffolding_platform.png"},
  368. use_texture_alpha = 'clip',
  369. drop = "scaffolding:iron_platform",
  370. paramtype = "light",
  371. paramtype2 = "facedir",
  372. climbable = false,
  373. walkable = true,
  374. light_source = 14,
  375. is_ground_content = true,
  376. groups = {snappy=2,cracky=3},
  377. sounds = default.node_sound_wood_defaults(),
  378. on_punch = function(pos, node, puncher)
  379. local tool = puncher:get_wielded_item():get_name()
  380. if tool and tool == "scaffolding:scaffolding_wrench" then
  381. node.name = "scaffolding:iron_platform"
  382. minetest.env:set_node(pos, node)
  383. end
  384. end,
  385. node_box = {
  386. type = "fixed",
  387. fixed = {
  388. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  389. },
  390. },
  391. selection_box = {
  392. type = "fixed",
  393. fixed = {
  394. {-0.5, -0.3, -0.5, 0.5, 0.1, 0.5},
  395. },
  396. },
  397. })
  398. ----------------------
  399. -- wood scaffolding --
  400. ----------------------
  401. minetest.register_craft({
  402. output = 'scaffolding:scaffolding 12',
  403. recipe = {
  404. {'default:wood', 'default:wood', 'default:wood'},
  405. {'default:stick', '', 'default:stick'},
  406. {'default:wood', 'default:wood', 'default:wood'},
  407. }
  408. })
  409. minetest.register_craft({
  410. output = 'scaffolding:scaffolding 4',
  411. recipe = {
  412. {'default:wood'},
  413. {'default:stick'},
  414. {'default:wood'},
  415. }
  416. })
  417. -- back to scaffolding --
  418. minetest.register_craft({
  419. output = 'scaffolding:scaffolding',
  420. recipe = {
  421. {'scaffolding:platform'},
  422. {'scaffolding:platform'},
  423. }
  424. })
  425. -- wood platforms --
  426. minetest.register_craft({
  427. output = 'scaffolding:platform 2',
  428. recipe = {
  429. {'scaffolding:scaffolding'},
  430. }
  431. })
  432. minetest.register_craft({
  433. output = 'scaffolding:platform 6',
  434. recipe = {
  435. {'scaffolding:scaffolding', 'scaffolding:scaffolding', 'scaffolding:scaffolding'},
  436. }
  437. })
  438. -- get wood back --
  439. minetest.register_craft({
  440. output = 'default:wood',
  441. recipe = {
  442. {'scaffolding:scaffolding', 'scaffolding:scaffolding'},
  443. }
  444. })
  445. ----------------------
  446. -- iron scaffolding --
  447. ----------------------
  448. minetest.register_craft({
  449. output = 'scaffolding:iron_scaffolding 12',
  450. recipe = {
  451. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  452. {'default:stick', '', 'default:stick'},
  453. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  454. }
  455. })
  456. minetest.register_craft({
  457. output = 'scaffolding:iron_scaffolding 4',
  458. recipe = {
  459. {'default:steel_ingot'},
  460. {'default:stick'},
  461. {'default:steel_ingot'},
  462. }
  463. })
  464. -- back to scaffolding --
  465. minetest.register_craft({
  466. output = 'scaffolding:iron_scaffolding',
  467. recipe = {
  468. {'scaffolding:iron_platform'},
  469. {'scaffolding:iron_platform'},
  470. }
  471. })
  472. -- iron platforms --
  473. minetest.register_craft({
  474. output = 'scaffolding:iron_platform 2',
  475. recipe = {
  476. {'scaffolding:iron_scaffolding'},
  477. }
  478. })
  479. minetest.register_craft({
  480. output = 'scaffolding:iron_platform 6',
  481. recipe = {
  482. {'scaffolding:iron_scaffolding', 'scaffolding:iron_scaffolding', 'scaffolding:iron_scaffolding'},
  483. }
  484. })
  485. -- get iron back --
  486. minetest.register_craft({
  487. output = 'default:steel_ingot',
  488. recipe = {
  489. {'scaffolding:iron_scaffolding', 'scaffolding:iron_scaffolding'},
  490. }
  491. })