init.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --[[
  2. - Sponge mod for Minetest
  3. - water removal for survival
  4. made by Benjie/Fiftysix - 27/8/18
  5. soggy sponges can be found quite rare, deep in the sea where it is dark
  6. these can be cooked into dry sponges, and then placed near a liquid to remove an area of it
  7. they will hold the water away until they are removed.
  8. to use them again, they have to be cooked.
  9. sponges create a 9x9 area of air-like nodes that water can't flow through (checks for protection)
  10. if sponges have cleared more than 3 nodes of liquid, they become soggy sponges
  11. removing a sponge or soggy sponge will turn a 9x9 area of air-like nodes back into air
  12. (air-like nodes can be removed in protection by removing a sponge outside the protection, they are not meant to be permanent)
  13. ]]--
  14. local area = 4
  15. local destruct = function(pos) -- removing the air-like nodes
  16. for x = pos.x-area, pos.x+area do
  17. for y = pos.y-area, pos.y+area do
  18. for z = pos.z-area, pos.z+area do
  19. local n = minetest.get_node({x=x, y=y, z=z}).name
  20. if n == "sponge:liquid_stop" then
  21. minetest.remove_node({x=x, y=y, z=z})
  22. end
  23. end
  24. end
  25. end
  26. end
  27. minetest.register_node("sponge:liquid_stop", { -- air-like node
  28. description = "liquid blocker for sponges",
  29. drawtype = "airlike",
  30. drop = {max_items=0, items={}},
  31. groups = {not_in_creative_inventory=1},
  32. pointable = false,
  33. walkable = false,
  34. sunlight_propagates = true,
  35. paramtype = "light",
  36. buildable_to = true,
  37. })
  38. minetest.register_node("sponge:sponge", { -- dry sponge
  39. description = "Sponge",
  40. tiles = {"sponge_sponge.png"},
  41. groups = {crumbly=3},
  42. sounds = default.node_sound_dirt_defaults(),
  43. after_place_node = function(pos, placer, itemstack, pointed_thing)
  44. local name = placer:get_player_name()
  45. if not minetest.is_protected(pos, name) then
  46. local count = 0
  47. for x = pos.x-area, pos.x+area do
  48. for y = pos.y-area, pos.y+area do
  49. for z = pos.z-area, pos.z+area do
  50. local n = minetest.get_node({x=x, y=y, z=z}).name
  51. local d = minetest.registered_nodes[n]
  52. if d ~= nil and (n == "air" or d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then
  53. local p = {x=x, y=y, z=z}
  54. if not minetest.is_protected(p, name) then
  55. if n ~= "air" then
  56. count = count + 1 -- counting liquids
  57. end
  58. minetest.set_node(p, {name="sponge:liquid_stop"})
  59. end
  60. end
  61. end
  62. end
  63. end
  64. if count > 3 then -- turns soggy if it removed more than 3 nodes
  65. minetest.set_node(pos, {name="sponge:soggy_sponge"})
  66. end
  67. end
  68. end,
  69. after_dig_node = destruct
  70. })
  71. minetest.register_node("sponge:soggy_sponge", { -- soggy sponge
  72. description = "Soggy sponge",
  73. tiles = {"sponge_soggy_sponge.png"},
  74. groups = {crumbly=3},
  75. sounds = default.node_sound_dirt_defaults(),
  76. on_destruct = destruct
  77. })
  78. minetest.register_craft({ -- cooking soggy sponge back into dry sponge
  79. type = "cooking",
  80. recipe = "sponge:soggy_sponge",
  81. output = "sponge:sponge",
  82. cooktime = 2,
  83. })
  84. minetest.register_decoration({ -- sponges are found deep in the sea
  85. name = "sponge:sponges",
  86. deco_type = "simple",
  87. place_on = {"default:sand"},
  88. spawn_by = "default:water_source",
  89. num_spawn_by = 3,
  90. fill_ratio = 0.0003,
  91. y_max = -12,
  92. flags = "force_placement",
  93. decoration = "sponge:soggy_sponge",
  94. })