init.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. -- minetest/fire/init.lua
  2. -- Global namespace for functions
  3. fire = {}
  4. -- Register flame nodes
  5. minetest.register_node("fire:basic_flame", {
  6. drawtype = "firelike",
  7. tiles = {
  8. {
  9. name = "fire_basic_flame_animated.png",
  10. animation = {
  11. type = "vertical_frames",
  12. aspect_w = 16,
  13. aspect_h = 16,
  14. length = 1
  15. },
  16. },
  17. },
  18. inventory_image = "fire_basic_flame.png",
  19. paramtype = "light",
  20. light_source = 13,
  21. walkable = false,
  22. buildable_to = false, -- Player must remove fire before building.
  23. not_buildable_against = true,
  24. sunlight_propagates = true,
  25. damage_per_second = 4,
  26. drop = "",
  27. groups = utility.dig_groups("bigitem", {
  28. igniter = 2,
  29. not_in_creative_inventory = 1,
  30. melt_around = 3,
  31. flame = 1,
  32. flame_sound = 1,
  33. notify_construct = 1,
  34. fire = 1,
  35. }),
  36. on_timer = function(pos)
  37. local f = minetest.find_node_near(pos, 1, {"group:flammable"})
  38. if f then
  39. if minetest.test_protection(f, "") then
  40. minetest.remove_node(pos)
  41. return
  42. end
  43. end
  44. if not f then
  45. minetest.remove_node(pos)
  46. return
  47. end
  48. -- restart timer
  49. local time = math.random(30, 60)
  50. minetest.get_node_timer(pos):start(time)
  51. --ambiance.fire_particles(pos, time)
  52. end,
  53. on_construct = function(pos)
  54. fireambiance.on_flame_addremove(pos)
  55. particles.add_flame_spawner(pos)
  56. local time = math.random(30, 60)
  57. minetest.get_node_timer(pos):start(time)
  58. --ambiance.fire_particles(pos, time)
  59. torchmelt.start_melting(pos)
  60. end,
  61. after_destruct = function(pos)
  62. particles.del_flame_spawner(pos)
  63. fireambiance.on_flame_addremove(pos)
  64. end,
  65. on_dig = function(pos, node, player)
  66. local pname = player and player:get_player_name() or ""
  67. if not heatdamage.is_immune(pname) then
  68. minetest.after(0, function()
  69. local player = minetest.get_player_by_name(pname)
  70. if player and player:get_hp() > 0 then
  71. player:set_hp(player:get_hp() - 1)
  72. end
  73. end)
  74. end
  75. return minetest.node_dig(pos, node, player)
  76. end,
  77. --on_blast = function()
  78. --end, -- unaffected by explosions
  79. })
  80. minetest.register_node("fire:permanent_flame", {
  81. description = "Permanent Flame",
  82. drawtype = "firelike",
  83. tiles = {
  84. {
  85. name = "fire_basic_flame_animated.png",
  86. animation = {
  87. type = "vertical_frames",
  88. aspect_w = 16,
  89. aspect_h = 16,
  90. length = 1
  91. },
  92. },
  93. },
  94. inventory_image = "fire_basic_flame.png",
  95. paramtype = "light",
  96. light_source = 13,
  97. walkable = false,
  98. buildable_to = false, -- Player must remove fire before building.
  99. not_buildable_against = true,
  100. sunlight_propagates = true,
  101. damage_per_second = 4,
  102. groups = {igniter = 2, dig_immediate = 2, melt_around = 3, flame = 1, flame_sound = 1, fire = 1, notify_construct = 1},
  103. drop = "",
  104. on_construct = function(pos)
  105. fireambiance.on_flame_addremove(pos)
  106. particles.add_flame_spawner(pos)
  107. torchmelt.start_melting(pos)
  108. end,
  109. after_destruct = function(pos)
  110. fireambiance.on_flame_addremove(pos)
  111. particles.del_flame_spawner(pos)
  112. end,
  113. on_dig = function(pos, node, player)
  114. local pname = player and player:get_player_name() or ""
  115. if not heatdamage.is_immune(pname) then
  116. minetest.after(0, function()
  117. local player = minetest.get_player_by_name(pname)
  118. if player and player:get_hp() > 0 then
  119. player:set_hp(player:get_hp() - 1)
  120. end
  121. end)
  122. end
  123. return minetest.node_dig(pos, node, player)
  124. end,
  125. --on_blast = function()
  126. --end,
  127. })
  128. minetest.register_node("fire:nether_flame", {
  129. description = "Nether Flame",
  130. drawtype = "firelike",
  131. tiles = {
  132. {
  133. name = "fire_nether_flame_animated.png",
  134. animation = {
  135. type = "vertical_frames",
  136. aspect_w = 16,
  137. aspect_h = 16,
  138. length = 1
  139. },
  140. },
  141. },
  142. inventory_image = "fire_basic_flame.png",
  143. paramtype = "light",
  144. light_source = 14,
  145. walkable = false,
  146. buildable_to = false,
  147. not_buildable_against = true,
  148. sunlight_propagates = true,
  149. damage_per_second = 4,
  150. groups = utility.dig_groups("bigitem", {igniter = 2, melt_around = 3, flame = 1, fire = 1, flame_sound = 1, notify_construct = 1}),
  151. drop = "",
  152. on_construct = function(pos)
  153. fireambiance.on_flame_addremove(pos)
  154. particles.add_flame_spawner(pos)
  155. torchmelt.start_melting(pos)
  156. end,
  157. -- The fireportal takes care of this.
  158. --after_destruct = function(pos) fireambiance.on_flame_addremove(pos) end,
  159. on_dig = function(pos, node, player)
  160. local pname = player and player:get_player_name() or ""
  161. if not heatdamage.is_immune(pname) then
  162. minetest.after(0, function()
  163. local player = minetest.get_player_by_name(pname)
  164. if player and player:get_hp() > 0 then
  165. player:set_hp(player:get_hp() - 1)
  166. end
  167. end)
  168. end
  169. return minetest.node_dig(pos, node, player)
  170. end,
  171. --on_blast = function()
  172. --end,
  173. })
  174. -- Override coalblock to enable permanent flame above
  175. minetest.override_item("default:coalblock", {
  176. after_destruct = function(pos, oldnode)
  177. pos.y = pos.y + 1
  178. if minetest.get_node(pos).name == "fire:permanent_flame" then
  179. minetest.remove_node(pos)
  180. end
  181. end,
  182. })
  183. -- Extinguish all flames quickly with water, snow, ice
  184. minetest.register_abm({
  185. label = "Extinguish flame",
  186. nodenames = {"group:flame"},
  187. neighbors = {"group:puts_out_fire"},
  188. interval = 3 * default.ABM_TIMER_MULTIPLIER,
  189. chance = 1 * default.ABM_CHANCE_MULTIPLIER,
  190. catch_up = false,
  191. action = function(pos, node, active_object_count, active_object_count_wider)
  192. minetest.remove_node(pos)
  193. minetest.sound_play("fire_extinguish_flame",
  194. {pos = pos, max_hear_distance = 16, gain = 0.25})
  195. end,
  196. })
  197. -- Enable the following ABMs according to 'enable fire' setting
  198. minetest.register_abm({
  199. label = "Ignite flame",
  200. nodenames = {"group:flammable"},
  201. neighbors = {"group:igniter"},
  202. interval = 3 * default.ABM_TIMER_MULTIPLIER,--7/2,
  203. chance = 6 * default.ABM_CHANCE_MULTIPLIER,--12/2,
  204. catch_up = false,
  205. action = function(pos, node, active_object_count, active_object_count_wider)
  206. -- If there is water or stuff like that around node, don't ignite
  207. if minetest.find_node_near(pos, 1, {"group:puts_out_fire"}) then
  208. return
  209. end
  210. local p
  211. local def = minetest.reg_ns_nodes[node.name]
  212. or minetest.registered_nodes[node.name]
  213. if def and def.buildable_to then
  214. -- Flame replaces flammable node itself if node is buildable to.
  215. p = pos
  216. else
  217. p = minetest.find_node_near(pos, 1, {"air"})
  218. end
  219. if p then
  220. if minetest.test_protection(p, "") then
  221. return
  222. end
  223. minetest.add_node(p, {name = "fire:basic_flame"})
  224. end
  225. end,
  226. })
  227. -- Remove flammable nodes
  228. minetest.register_abm({
  229. label = "Remove flammable nodes",
  230. nodenames = {"fire:basic_flame", "fire:nether_flame"},
  231. neighbors = "group:flammable",
  232. interval = 3 * default.ABM_TIMER_MULTIPLIER,
  233. chance = 10 * default.ABM_CHANCE_MULTIPLIER,
  234. catch_up = false,
  235. action = function(pos, node, active_object_count, active_object_count_wider)
  236. local p = minetest.find_node_near(pos, 1, {"group:flammable"})
  237. if p then
  238. if minetest.test_protection(p, "") then
  239. return
  240. end
  241. -- remove flammable nodes around flame
  242. local flammable_node = minetest.get_node(p)
  243. local def = minetest.reg_ns_nodes[flammable_node.name]
  244. or minetest.registered_nodes[flammable_node.name]
  245. if def.on_burn then
  246. def.on_burn(p)
  247. else
  248. minetest.remove_node(p)
  249. minetest.check_for_falling(p)
  250. end
  251. end
  252. end,
  253. })