init.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. -- Localize for performance.
  2. local math_floor = math.floor
  3. minetest.register_node("sulfur:ore", {
  4. description = "Sulfur Ore",
  5. tiles = {"default_stone.png^technic_sulfur_mineral.png"},
  6. groups = utility.dig_groups("mineral"),
  7. drop = "sulfur:lump",
  8. sounds = default.node_sound_stone_defaults(),
  9. silverpick_drop = true,
  10. })
  11. minetest.register_craftitem("sulfur:lump", {
  12. description = "Sulfur Lump",
  13. inventory_image = "technic_sulfur_lump.png",
  14. })
  15. minetest.register_craftitem("sulfur:dust", {
  16. description = "Powdered Sulfur",
  17. inventory_image = "technic_sulfur_dust.png"
  18. })
  19. minetest.register_craft({
  20. type = "grinding",
  21. output = 'sulfur:dust 4',
  22. recipe = 'sulfur:lump',
  23. })
  24. minetest.register_craft({
  25. type = "anvil",
  26. output = 'sulfur:dust 2',
  27. recipe = 'sulfur:lump',
  28. })
  29. minetest.register_craft({
  30. type = "crushing",
  31. output = 'sulfur:dust 6',
  32. recipe = 'sulfur:lump',
  33. time = 60*1.5,
  34. })
  35. local c_lava = minetest.get_content_id("default:lava_source")
  36. local c_lava_flowing = minetest.get_content_id("default:lava_flowing")
  37. local c_stone = minetest.get_content_id("default:stone")
  38. local c_sulfur = minetest.get_content_id("sulfur:ore")
  39. -- Sulfur
  40. local sulfur_buf = {}
  41. local sulfur_noise= nil
  42. local generate = function(minp, maxp, seed)
  43. -- Keep mapgen within bounds. Not in nether, not in shallow caves.
  44. if minp.y < -24000 or maxp.y > -256 then return end
  45. --minetest.chat_send_all("searching for lava")
  46. local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  47. local a = VoxelArea:new{
  48. MinEdge = {x = emin.x, y = emin.y, z = emin.z},
  49. MaxEdge = {x = emax.x, y = emax.y, z = emax.z},
  50. }
  51. local data = vm:get_data(sulfur_buf)
  52. local pr = PseudoRandom(17 * minp.x + 42 * minp.y + 101 * minp.z)
  53. sulfur_noise = sulfur_noise or minetest.get_perlin(9876, 3, 0.5, 100)
  54. local max = math.max
  55. local min = math.min
  56. local grid_size = 5
  57. for x = minp.x + math_floor(grid_size / 2), maxp.x, grid_size do
  58. for y = minp.y + math_floor(grid_size / 2), maxp.y, grid_size do
  59. for z = minp.z + math_floor(grid_size / 2), maxp.z, grid_size do
  60. local c = data[a:index(x, y, z)]
  61. if (c == c_lava or c == c_lava_flowing) and sulfur_noise:get3d({x = x, y = z, z = z}) >= 0.2 then
  62. --minetest.chat_send_all("found lava")
  63. for xx = max(minp.x, x - grid_size), min(maxp.x, x + grid_size) do
  64. for yy = max(minp.y, y - grid_size), min(maxp.y, y + grid_size) do
  65. for zz = max(minp.z, z - grid_size), min(maxp.z, z + grid_size) do
  66. local i = a:index(xx, yy, zz)
  67. if data[i] == c_stone and pr:next(1, 10) <= 7 then
  68. data[i] = c_sulfur
  69. end
  70. end
  71. end
  72. end
  73. end
  74. end
  75. end
  76. end
  77. vm:set_data(data)
  78. vm:write_to_map()
  79. end
  80. minetest.register_on_generated(function(...) generate(...) end)