rocks.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 random_pos(pos, dist)
  8. local p = {
  9. x=pos.x + math.random(-dist, dist),
  10. y=pos.y + dist,
  11. z=pos.z + math.random(-dist, dist),
  12. }
  13. while p.y > pos.y - dist do
  14. local n = minetest.get_node(p)
  15. if n.name ~= "air" and n.name ~= "ignore" then
  16. return p
  17. end
  18. p.y = p.y - 1
  19. end
  20. return nil
  21. end
  22. local function spawn_rock(pos, nodes)
  23. if pos == nil then
  24. return
  25. end
  26. pos.y = pos.y + 2
  27. local ns = {}
  28. for name,chance in pairs(nodes) do
  29. for i = 1,chance do
  30. table.insert(ns, name)
  31. end
  32. end
  33. local r = math.random() * 1.1 + .3
  34. local stry = math.random(6) + 1
  35. local strx = math.random() * .5 + .5
  36. local strz = math.random() * .5 + .5
  37. local lx = math.random() * 1.6 - .8
  38. local lz = math.random() * 1.6 - .8
  39. local r2 = math.ceil(r+1)
  40. for x = -r2,r2,1 do
  41. for y = -r2*stry,r2*stry,1 do
  42. for z = -r2,r2,1 do
  43. local p = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
  44. local p_squash = {
  45. x = pos.x + (x/strx) + lx*y,
  46. y = pos.y + (y/stry),
  47. z = pos.z + (z/strz) + lz*y
  48. }
  49. local d = dist3(p_squash, pos)
  50. d = d + math.random() * .5
  51. local dd = d - r
  52. if dd <= 1 then
  53. minetest.set_node(p, {name=ns[math.random(#ns)]})
  54. else
  55. -- minetest.set_node(p, {name = "default:stone"})
  56. end
  57. end
  58. end
  59. end
  60. end
  61. local seed_biomes = {
  62. ["default:sand"] = {
  63. {
  64. ["default:desert_stone"] = 7,
  65. ["potions:sphalerite_ore"] = 1,
  66. },
  67. },
  68. ["default:desert_sand"] = {
  69. {
  70. ["default:sandstone"] = 7,
  71. ["potions:cinnabar_ore"] = 1,
  72. },
  73. {
  74. ["default:sandstone"] = 5,
  75. ["potions:cinnabar_ore"] = 1,
  76. },
  77. },
  78. ["default:silver_sand"] = {
  79. {
  80. ["default:stone"] = 7,
  81. ["potions:galena"] = 1,
  82. },
  83. },
  84. }
  85. minetest.register_node("potions:rock_seed", {
  86. description = "Rock Seed",
  87. tiles = {"default_sandstone.png^default_tool_bronzepick.png"},
  88. groups = {cracky = 3},
  89. sounds = default.node_sound_stone_defaults(),
  90. on_construct = function(pos)
  91. minetest.get_node_timer(pos):start(1)
  92. end,
  93. on_timer = function(pos)
  94. minetest.set_node(pos, {name="air"})
  95. -- if 1 ~= math.random(10) then
  96. -- return
  97. -- end
  98. print("rock seed")
  99. local p = minetest.find_node_near(pos, 4, {"default:sand", "default:desert_sand", "default:silver_sand"})
  100. local n = minetest.get_node(p)
  101. print(dump(n.name))
  102. local b = seed_biomes[n.name]
  103. if not b then return end
  104. print("b")
  105. for i = 1,(math.random(1) + 0) do
  106. spawn_rock(random_pos(pos, math.random(20) + 20), b[1])
  107. end
  108. end,
  109. })
  110. minetest.register_abm({
  111. nodenames = "potions:rock_seed",
  112. chance = 1,
  113. interval = 5,
  114. action = function(pos, node)
  115. minetest.get_node_timer(pos):start(2)
  116. end
  117. })
  118. minetest.register_decoration({
  119. name = "potions:rock_seed",
  120. deco_type = "simple",
  121. place_on = {"default:desert_sand", "default:silver_sand", "default:sand",},
  122. place_offset_y = 1,
  123. sidelen = 16,
  124. noise_params = {
  125. offset = -0.0105,
  126. scale = 0.01,
  127. spread = {x = 200, y = 200, z = 200},
  128. seed = 29724537,
  129. octaves = 3,
  130. persist = 0.7,
  131. },
  132. biomes = {"desert", "cold_desert", "sandstone_desert"},
  133. y_max = 1000,
  134. y_min = 5,
  135. place_offset_y = 1,
  136. decoration = "potions:rock_seed",
  137. flags = "force_placement",
  138. })