init.lua 2.7 KB

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