init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. -- minetest/fire/init.lua
  2. fire = {}
  3. minetest.register_privilege("fire", {
  4. description = "Player can set fire.",
  5. give_to_singleplayer = true
  6. })
  7. minetest.register_alias("flint:tinder", "fire:tinder")
  8. minetest.register_alias("flint:firestriker", "fire:flint_and_steel")
  9. minetest.register_alias("nodetest:rock", "default:gravel")
  10. minetest.register_alias("flint:silex_ore", "default:gravel")
  11. minetest.register_alias("flint:silex", "default:cobble")
  12. minetest.register_alias("fire", "fire:basic_flame")
  13. function fire.node_should_burn(pos)
  14. local p0 = {x=pos.x-1, y=pos.y-1, z=pos.z-1}
  15. local p1 = {x=pos.x+1, y=pos.y+1, z=pos.z+1}
  16. local ps = minetest.find_nodes_in_area(p0, p1, {"group:igniter"})
  17. return (#ps >= 2)
  18. end
  19. dofile(minetest.get_modpath("fire").."/flintandsteel.lua")
  20. minetest.register_node("fire:basic_flame", {
  21. description = "Fire",
  22. drawtype = "firelike",
  23. tiles = {{
  24. name="fire_basic_flame_animated.png",
  25. animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=1},
  26. }},
  27. inventory_image = "fire_basic_flame.png",
  28. paramtype = "light",
  29. light_source = 13,
  30. waving = 1,
  31. groups = {igniter=2, dig_immediate=3},
  32. drop = "",
  33. walkable = false,
  34. buildable_to = true,
  35. floodable = true,
  36. sunlight_propagates = true,
  37. damage_per_second = 4,
  38. on_timer = function(pos)
  39. -- If there are no flammable nodes around flame, remove flame
  40. local p = minetest.find_node_near(pos, 1, {"group:flammable"})
  41. if not p then
  42. minetest.remove_node(pos)
  43. return false
  44. end
  45. return true
  46. end,
  47. on_construct = function(pos)
  48. minetest.get_node_timer(pos):start(math.random(5, 10))
  49. end,
  50. })
  51. if not minetest.settings:get_bool("disable_fire") then
  52. -- Ignite neighboring nodes
  53. minetest.register_abm({
  54. nodenames = {"group:flammable"},
  55. neighbors = {"group:igniter"},
  56. interval = 1,
  57. chance = 8,
  58. catch_up = false,
  59. action = function(pos, node, _, _)
  60. if minetest.find_node_near(pos, 1, {"air"}) or
  61. fire.node_should_burn(pos) then
  62. minetest.set_node(pos, {name="fire:basic_flame"})
  63. end
  64. end,
  65. })
  66. minetest.register_lbm({
  67. name = "fire:convert_fire_to_node_timer",
  68. nodenames = {"fire:basic_flame"},
  69. action = function(pos)
  70. minetest.get_node_timer(pos):start(math.random(5, 10))
  71. end
  72. })
  73. end