island.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. local function dist3(a, b)
  2. local x = a.x - b.x
  3. local y = a.y - b.y
  4. local z = a.z - b.z
  5. return math.sqrt(x*x + y*y + z*z)
  6. end
  7. local function dist2(a, b)
  8. local x = a.x - b.x
  9. local z = a.z - b.z
  10. return math.sqrt(x*x + z*z)
  11. end
  12. local function make_island(pos, size)
  13. -- dir.y = 0
  14. pos.y = pos.y - 3
  15. local r = size
  16. local r2 = math.ceil(r+1)
  17. local top_nodes = {}
  18. -- foundation
  19. for x = pos.x-r2,pos.x+r2,1 do
  20. for y = -r2,0,1 do
  21. for z = pos.z-r2,pos.z+r2,1 do
  22. local p = {x=x, y=pos.y+y, z=z}
  23. local p_squash = {x=x, y=pos.y + (y*2), z=z}
  24. local d = dist3(p_squash, pos)
  25. d = d + math.random() * .5
  26. local dd = d - r
  27. if dd < 1 then
  28. if y == 0 then
  29. table.insert(top_nodes, p)
  30. end
  31. local n = minetest.get_node(p)
  32. if n.name == "default:water_source" or n.name == "default:water_flowing" then
  33. minetest.set_node(p, {name = "default:coral_skeleton"})
  34. end
  35. elseif dd < 1.8 and math.random(8) == 1 then
  36. if math.random(2) == 1 then
  37. minetest.set_node(p, {name = "default:coral_brown"})
  38. else
  39. minetest.set_node(p, {name = "default:coral_orange"})
  40. end
  41. end
  42. end
  43. end
  44. end
  45. -- sand
  46. for _,p in ipairs(top_nodes) do
  47. p.y = p.y + 1
  48. minetest.set_node(p, {name="default:sand"})
  49. local d = dist2(pos, p) + math.random() * .9
  50. if d / r < .5 then
  51. p.y = p.y + 1
  52. minetest.set_node(p, {name="default:dirt_with_grass"})
  53. if math.random(5) == 1 then
  54. p.y = p.y + 1
  55. minetest.set_node(p, {name="default:grass_1"})
  56. end
  57. elseif math.random(8) == 1 then
  58. p.y = p.y + 1
  59. minetest.set_node(p, {name="default:marram_grass_1"})
  60. end
  61. end
  62. -- add a tree
  63. if size > 15 then
  64. default.grow_new_emergent_jungle_tree({x=pos.x, y=pos.y+2, z=pos.z})
  65. elseif size > 10 then
  66. default.grow_new_jungle_tree({x=pos.x, y=pos.y+2, z=pos.z})
  67. elseif size > 7 then
  68. default.grow_new_aspen_tree({x=pos.x, y=pos.y+2, z=pos.z})
  69. elseif size > 3 then
  70. default.grow_new_apple_tree({x=pos.x, y=pos.y+2, z=pos.z})
  71. end
  72. end
  73. minetest.register_craftitem("potions:island_seed", {
  74. description = "Island Seed",
  75. inventory_image = "default_brick.png",
  76. groups = {cracky=3,},
  77. liquids_pointable=true,
  78. on_use = function(itemstack, player, pointed_thing)
  79. local pos = pointed_thing.above
  80. if not pos then
  81. return
  82. end
  83. pos.y = pos.y + 1
  84. -- local below = {x=pos.x, y=pos.y-1, z=pos.z}
  85. -- local n = minetest.get_node(below)
  86. -- if n.name == "air" or n.name == "ignore" then
  87. -- return
  88. -- end
  89. -- local newname = get_temp_node(n.name)
  90. potions.use_manna(player, 20)
  91. make_island(pos, 4)
  92. -- get player yaw, calc direction
  93. -- itemstack:take_item()
  94. return itemstack
  95. end,
  96. })