init.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. local get_node_or_nil = minetest.get_node_or_nil
  2. local reg_nodes = minetest.registered_nodes
  3. local add_node = minetest.add_node
  4. local sound_play = minetest.sound_play
  5. local S = minetest.get_translator("degradable_walls")
  6. local function place_as_pillar(itemstack, user, pointed_thing)
  7. if pointed_thing.type == "node"
  8. then
  9. local name = itemstack:get_name()
  10. local place_sound = reg_nodes[name].sounds.place
  11. local height = itemstack:get_count()
  12. if height > 5 then height = 5 end
  13. local pos = vector.new(pointed_thing.above)
  14. for i = 1, height
  15. do
  16. local node = get_node_or_nil(pos)
  17. if node and (reg_nodes[node.name] or {}).buildable_to
  18. then
  19. sound_play(place_sound)
  20. add_node(pos, {name = name})
  21. pos.y = pos.y + 1
  22. else
  23. itemstack:take_item(i - 1)
  24. return itemstack
  25. end
  26. end
  27. itemstack:take_item(height)
  28. return itemstack
  29. end
  30. end
  31. minetest.register_node("degradable_walls:wall",
  32. {
  33. description = S("Reinforced Wall"),
  34. tiles = {"degradable_walls_wall.png"},
  35. groups = {cracky = 1, stone = 1},
  36. on_use = place_as_pillar,
  37. sounds = generic_media.node_sound_stone_defaults(),
  38. stack_max = 128,
  39. })
  40. minetest.register_alias("wall", "degradable_walls:wall")
  41. crafting.register_recipe(
  42. {
  43. output = "wall 8",
  44. type = "inv",
  45. items = {"cobble", "mortar"},
  46. always_known = "true",
  47. })
  48. local erosion_order = {"wall"}
  49. local repairable_hashtable = {}
  50. for i = 1, 5
  51. do
  52. local name = "degradable_walls:cracked_wall_" .. i
  53. local description = "Cracked Wall"
  54. for ii = 2, i
  55. do
  56. description = "Very " .. description
  57. end
  58. local crackiness
  59. if i > 3
  60. then
  61. crackiness = 3
  62. else
  63. crackiness = i
  64. end
  65. minetest.register_node(name, {
  66. description = S(description),
  67. tiles = {"degradable_walls_wall.png^[crack:1:" .. i},
  68. is_ground_content = false,
  69. groups = {cracky = crackiness, stone = 1, not_in_creative_inventory = 1},
  70. sounds = generic_media.node_sound_stone_defaults(),
  71. on_use = place_as_pillar,
  72. stack_max = 128,
  73. })
  74. repairable_hashtable[minetest.get_content_id(name)] = true
  75. erosion_order[i + 1] = name
  76. end
  77. minetest.register_node("degradable_walls:debris",
  78. {
  79. description = S("Debris"),
  80. tiles = {"basic_ground_nodes_rubble.png"},
  81. is_ground_content = false,
  82. groups = {crumbly = 3, falling_node = 1},
  83. sounds = generic_media.node_sound_gravel_defaults(),
  84. drop =
  85. {
  86. max_items = 1,
  87. items =
  88. {
  89. {
  90. rarity = 3,
  91. items = {"cobble"}
  92. }
  93. }
  94. }
  95. })
  96. minetest.register_alias("debris", "degradable_walls:debris")
  97. erosion_order[7] = "debris"
  98. erosion_order[8] = "air"
  99. erosion.register_erosion({"cobble", "debris"})
  100. erosion.register_erosion(erosion_order)
  101. give_initial_stuff.add("wall 128")
  102. dofile(minetest.get_modpath("degradable_walls") .. "/mortar.lua")(repairable_hashtable)