misc.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --Code written by foot_on_teh_hill, with some slight changes.
  2. --https://github.com/foot-on-teh-hill/cavetools/blob/master/rope.lua
  3. local creative = minetest.setting_getbool("creative_mode")
  4. local function place_rope(pos, itemstack)
  5. if itemstack == nil and itemstack:get_count() <= 1 then
  6. return
  7. else
  8. local max_nodes = itemstack:get_count()
  9. if creative then
  10. max_nodes = 200
  11. end
  12. local set_nodes = 0
  13. for i = 2, max_nodes do
  14. pos.y = pos.y - 1
  15. local node_below = minetest.get_node(pos)
  16. if node_below ~= nil then
  17. if node_below.name == "air" then
  18. minetest.set_node(pos, {name = "lottblocks:elven_rope"})
  19. set_nodes = set_nodes + 1
  20. else
  21. break
  22. end
  23. end
  24. end
  25. if not creative then
  26. itemstack:set_count(max_nodes - set_nodes)
  27. end
  28. end
  29. end
  30. local function dig_rope(pos, digger)
  31. if digger == nil and not digger:is_player() then
  32. return
  33. end
  34. local dug_nodes = 0
  35. local max_nodes = 200
  36. local y = pos.y
  37. for i = 1, max_nodes do
  38. pos.y = y + i
  39. local node = minetest.get_node(pos)
  40. if node ~= nil then
  41. if node.name == "lottblocks:elven_rope" then
  42. if not minetest.is_protected(pos, digger:get_player_name()) then
  43. minetest.remove_node(pos)
  44. dug_nodes = dug_nodes + 1
  45. else
  46. break
  47. end
  48. else
  49. break
  50. end
  51. end
  52. end
  53. for i = -1, -max_nodes, -1 do
  54. pos.y = y + i
  55. local node = minetest.get_node(pos)
  56. if node ~= nil then
  57. if node.name == "lottblocks:elven_rope" then
  58. if not minetest.is_protected(pos, digger:get_player_name()) then
  59. minetest.remove_node(pos)
  60. dug_nodes = dug_nodes + 1
  61. else
  62. break
  63. end
  64. else
  65. break
  66. end
  67. end
  68. end
  69. local inventory = digger:get_inventory()
  70. if inventory == nil then
  71. return
  72. end
  73. if not creative then
  74. inventory:add_item("main", "lottblocks:elven_rope " .. dug_nodes)
  75. end
  76. end
  77. minetest.register_node("lottblocks:elven_rope", {
  78. tiles = {"lottblocks_elven_rope.png"}, --Made by foot_on_teh_hill
  79. --https://github.com/foot-on-teh-hill/cavetools/blob/master/textures/cavetools_rope.png
  80. inventory_image = "lottblocks_elven_rope.png",
  81. wield_image = "lottblocks_elven_rope.png",
  82. description = "Elven Rope",
  83. drawtype = "plantlike",
  84. paramtype = "light",
  85. light_source = 1,
  86. climbable = true,
  87. walkable = false,
  88. stack_max = 200,
  89. after_place_node = function(pos, placer, itemstack, pointed_thing)
  90. place_rope(pos, itemstack)
  91. return false
  92. end,
  93. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  94. dig_rope(pos, digger)
  95. end,
  96. groups = {oddly_breakable_by_hand = 3}
  97. })
  98. minetest.register_craft({
  99. output = "lottblocks:elven_rope 8",
  100. recipe = {
  101. {"group:wool"},
  102. {"lottplants:mallornwood"},
  103. {"group:wool"}
  104. }
  105. })
  106. minetest.register_node("lottblocks:thrundir", {
  107. description = "Thrundir",
  108. tiles = {"lottblocks_thrundir.png"},
  109. is_ground_content = false,
  110. sounds = default.node_sound_stone_defaults(),
  111. groups = {cracky=1,level=2, no_darkball=1, puts_out_fire=1},
  112. })
  113. doors:register_door("lottblocks:thrundir_door", {
  114. description = "Thrundir Door",
  115. inventory_image = "lottblocks_thrundir_door.png",
  116. groups = {snappy=1,bendy=2,cracky=1,level=2,door=1,no_darkball=1,puts_out_fire=1},
  117. tiles_bottom = {"lottblocks_thrundir_door_b.png", "lottblocks_door_black.png"},
  118. tiles_top = {"lottblocks_thrundir_door_a.png", "lottblocks_door_black.png"},
  119. only_placer_can_open = true,
  120. races = {GAMEdwarf = true}
  121. })
  122. minetest.register_craft({
  123. type = "shapeless",
  124. output = "lottblocks:thrundir",
  125. recipe = {"default:steel_ingot", "lottother:dwarf_ring", "default:stone"},
  126. replacements = {{ "lottother:dwarf_ring", "lottother:dwarf_ring"}},
  127. })
  128. minetest.register_craft({
  129. output = "lottblocks:thrundir_door",
  130. recipe = {
  131. {"lottblocks:thrundir", "lottblocks:thrundir"},
  132. {"lottblocks:thrundir", "lottblocks:thrundir"},
  133. {"lottblocks:thrundir", "lottblocks:thrundir"},
  134. }
  135. })