init.lua 7.2 KB

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