Mod For Minetest
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

546 lines
16KB

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