init.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. if not minetest.global_exists("lava_extras") then lava_extras = {} end
  2. lava_extras.modpath = minetest.get_modpath("lava_extras")
  3. -- Register mod as reloadable.
  4. if minetest.get_modpath("reload") then
  5. local c = "lava_extras:core"
  6. local f = lava_extras.modpath .. "/init.lua"
  7. if not reload.file_registered(c) then
  8. reload.register_file(c, f, false)
  9. end
  10. end
  11. -- Particle def table is reused every time particles are spawned.
  12. local particles = {
  13. amount = 1,
  14. time = 3,
  15. minpos = {x=0, y=0, z=0},
  16. maxpos = {x=0, y=0, z=0},
  17. minvel = {x=-1.5, y=2, z=-1.5},
  18. maxvel = {x=1.5, y=4, z=1.5},
  19. minacc = {x=-0.5, y=-3, z=-0.5},
  20. maxacc = {x=0.5, y=-9, z=0.5},
  21. minexptime = 0.5,
  22. maxexptime = 3,
  23. minsize = 1,
  24. maxsize = 2,
  25. collisiondetection = false,
  26. collision_removal = false,
  27. vertical = false,
  28. texture = "default_lava.png",
  29. }
  30. -- Localize for speed.
  31. local random = math.random
  32. local vadd = vector.add
  33. local sfind = string.find
  34. local addspawner = minetest.add_particlespawner
  35. local fnn = minetest.find_node_near
  36. local after = minetest.after
  37. local rm = minetest.remove_node
  38. local setn = minetest.add_node
  39. local getn = minetest.get_node
  40. local function do_spawn_particles(pos, node)
  41. -- Calculate particle parameters.
  42. particles.amount = random(2, 6)
  43. particles.minpos = vadd(pos, {x=-0.5, y=0.5, z=-0.5})
  44. particles.maxpos = vadd(pos, {x=0.5, y=0.5, z=0.5})
  45. if random(1, 100) > 95 then
  46. particles.minvel.y = 4
  47. particles.maxvel.y = 8
  48. particles.minsize = 2
  49. particles.maxsize = 4
  50. else
  51. particles.minvel.y = 3
  52. particles.maxvel.y = 5
  53. particles.minsize = 1
  54. particles.maxsize = 2
  55. end
  56. -- Choose particle texture.
  57. if sfind(node.name, "^default:") then
  58. particles.texture = "default_lava.png"
  59. else
  60. particles.texture = "lbrim_lava.png"
  61. end
  62. addspawner(particles)
  63. -- Occasionally spawn a real fire node.
  64. if random(1, 100) > 70 then
  65. local f = fnn(pos, 1, "air")
  66. if f then
  67. setn(f, {name="fire:basic_flame"})
  68. after(random(0.5, 5), function()
  69. local n2 = getn(f)
  70. if n2.name == "fire:basic_flame" then
  71. rm(f)
  72. end
  73. end)
  74. end
  75. end
  76. end
  77. lava_extras.spawn_particles = do_spawn_particles
  78. if not lava_extras.registered then
  79. -- Spawn fire/particles around lava.
  80. minetest.register_abm({
  81. nodenames = {"group:lava"},
  82. neighbors = {"air"},
  83. interval = 5,
  84. chance = 1024,
  85. catch_up = false,
  86. action = do_spawn_particles,
  87. })
  88. lava_extras.registered = true
  89. end