init.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. local S = minetest.get_translator("fake_fire")
  2. local function fire_particles_on(pos) -- 3 layers of fire
  3. local meta = minetest.get_meta(pos)
  4. local id1 = minetest.add_particlespawner({ -- 1 layer big particles fire
  5. amount = 9,
  6. time = 0,
  7. minpos = {x = pos.x - 0.2, y = pos.y - 0.4, z = pos.z - 0.2},
  8. maxpos = {x = pos.x + 0.2, y = pos.y - 0.1, z = pos.z + 0.2},
  9. minvel = {x= 0, y= 0, z= 0},
  10. maxvel = {x= 0, y= 0.1, z= 0},
  11. minacc = {x= 0, y= 0, z= 0},
  12. maxacc = {x= 0, y= 0.7, z= 0},
  13. minexptime = 0.5,
  14. maxexptime = 0.7,
  15. minsize = 2,
  16. maxsize = 5,
  17. collisiondetection = false,
  18. vertical = true,
  19. texture = "fake_fire_particle_anim_fire.png",
  20. animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.8,},
  21. })
  22. meta:set_int("layer_1", id1)
  23. local id2 = minetest.add_particlespawner({ -- 2 layer smol particles fire
  24. amount = 1,
  25. time = 0,
  26. minpos = {x = pos.x - 0.1, y = pos.y, z = pos.z - 0.1},
  27. maxpos = {x = pos.x + 0.1, y = pos.y + 0.4, z = pos.z + 0.1},
  28. minvel = {x= 0, y= 0, z= 0},
  29. maxvel = {x= 0, y= 0.1, z= 0},
  30. minacc = {x= 0, y= 0, z= 0},
  31. maxacc = {x= 0, y= 1, z= 0},
  32. minexptime = 0.4,
  33. maxexptime = 0.6,
  34. minsize = 0.5,
  35. maxsize = 0.7,
  36. collisiondetection = false,
  37. vertical = true,
  38. texture = "fake_fire_particle_anim_fire.png",
  39. animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.7,},
  40. })
  41. meta:set_int("layer_2", id2)
  42. local id3 = minetest.add_particlespawner({ --3 layer smoke
  43. amount = 1,
  44. time = 0,
  45. minpos = {x = pos.x - 0.1, y = pos.y - 0.2, z = pos.z - 0.1},
  46. maxpos = {x = pos.x + 0.2, y = pos.y + 0.4, z = pos.z + 0.2},
  47. minvel = {x= 0, y= 0, z= 0},
  48. maxvel = {x= 0, y= 0.1, z= 0},
  49. minacc = {x= 0, y= 0, z= 0},
  50. maxacc = {x= 0, y= 1, z= 0},
  51. minexptime = 0.6,
  52. maxexptime = 0.8,
  53. minsize = 2,
  54. maxsize = 4,
  55. collisiondetection = true,
  56. vertical = true,
  57. texture = "fake_fire_particle_anim_smoke.png",
  58. animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.9,},
  59. })
  60. meta:set_int("layer_3", id3)
  61. end
  62. local function fire_particles_off(pos)
  63. local meta = minetest.get_meta(pos)
  64. local id_1 = meta:get_int("layer_1");
  65. local id_2 = meta:get_int("layer_2");
  66. local id_3 = meta:get_int("layer_3");
  67. minetest.delete_particlespawner(id_1)
  68. minetest.delete_particlespawner(id_2)
  69. minetest.delete_particlespawner(id_3)
  70. end
  71. local function start_fire_effects(pos, node, clicker, chimney)
  72. local this_spawner_meta = minetest.get_meta(pos)
  73. local id = this_spawner_meta:get_int("smoky")
  74. local s_handle = this_spawner_meta:get_int("sound")
  75. local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
  76. if id ~= 0 then
  77. if s_handle then
  78. minetest.after(0, function(handle)
  79. minetest.sound_stop(handle)
  80. end, s_handle)
  81. end
  82. minetest.delete_particlespawner(id)
  83. this_spawner_meta:set_int("smoky", 0)
  84. this_spawner_meta:set_int("sound", 0)
  85. return
  86. end
  87. if above == "air" and (not id or id == 0) then
  88. id = minetest.add_particlespawner({
  89. amount = 4, time = 0, collisiondetection = true,
  90. minpos = {x=pos.x-0.25, y=pos.y+0.4, z=pos.z-0.25},
  91. maxpos = {x=pos.x+0.25, y=pos.y+5, z=pos.z+0.25},
  92. minvel = {x=-0.2, y=0.3, z=-0.2}, maxvel = {x=0.2, y=1, z=0.2},
  93. minacc = {x=0,y=0,z=0}, maxacc = {x=0,y=0.5,z=0},
  94. minexptime = 1, maxexptime = 3,
  95. minsize = 4, maxsize = 8,
  96. texture = "smoke_particle.png",
  97. })
  98. if chimney == 1 then
  99. this_spawner_meta:set_int("smoky", id)
  100. this_spawner_meta:set_int("sound", 0)
  101. else
  102. s_handle = minetest.sound_play("fire_small", {
  103. pos = pos,
  104. max_hear_distance = 5,
  105. loop = true
  106. })
  107. fire_particles_on(pos)
  108. this_spawner_meta:set_int("sound", s_handle)
  109. end
  110. end
  111. end
  112. local function stop_smoke(pos)
  113. local this_spawner_meta = minetest.get_meta(pos)
  114. local id = this_spawner_meta:get_int("smoky")
  115. local s_handle = this_spawner_meta:get_int("sound")
  116. if id ~= 0 then
  117. minetest.delete_particlespawner(id)
  118. end
  119. if s_handle then
  120. minetest.after(0, function(handle)
  121. minetest.sound_stop(handle)
  122. end, s_handle)
  123. end
  124. this_spawner_meta:set_int("smoky", 0)
  125. this_spawner_meta:set_int("sound", 0)
  126. end
  127. minetest.register_node("fake_fire:ice_fire", {
  128. inventory_image = "ice_fire_inv.png",
  129. description = S("Ice fire"),
  130. drawtype = "plantlike",
  131. paramtype = "light",
  132. paramtype2 = "facedir",
  133. groups = {dig_immediate=3, not_in_creative_inventory=1},
  134. sunlight_propagates = true,
  135. buildable_to = true,
  136. walkable = false,
  137. light_source = 14,
  138. waving = 1,
  139. tiles = {
  140. {name="ice_fire_animated.png", animation={type="vertical_frames",
  141. aspect_w=16, aspect_h=16, length=1.5}},
  142. },
  143. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  144. start_fire_effects(pos, node, clicker)
  145. return itemstack
  146. end,
  147. on_destruct = function (pos)
  148. stop_smoke(pos)
  149. minetest.sound_play("fire_extinguish", {
  150. pos = pos, max_hear_distance = 5
  151. })
  152. end,
  153. drop = ""
  154. })
  155. minetest.register_alias("fake_fire:fake_fire", "fire:permanent_flame")
  156. local sbox = {
  157. type = 'fixed',
  158. fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16},
  159. }
  160. minetest.register_node("fake_fire:fancy_fire", {
  161. inventory_image = "fancy_fire_inv.png",
  162. description = S("Fancy Fire"),
  163. drawtype = "mesh",
  164. mesh = "fancy_fire.obj",
  165. paramtype = "light",
  166. paramtype2 = "facedir",
  167. groups = {oddly_breakable_by_hand=3, flammable=0},
  168. sunlight_propagates = true,
  169. light_source = 13,
  170. walkable = false,
  171. buildable_to = false,
  172. damage_per_second = 3,
  173. selection_box = sbox,
  174. tiles = {
  175. "basic_materials_concrete_block.png",
  176. "default_junglewood.png",
  177. "fake_fire_empty_tile.png"
  178. },
  179. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  180. fire_particles_on(pos)
  181. return itemstack
  182. end,
  183. on_construct = function(pos)
  184. fire_particles_on(pos)
  185. end,
  186. on_destruct = function(pos, oldnode, oldmetadata, digger)
  187. fire_particles_off(pos)
  188. minetest.sound_play("fire_extinguish", {
  189. pos = pos, max_hear_distance = 5
  190. })
  191. end,
  192. drop = {
  193. max_items = 3,
  194. items = {
  195. {
  196. items = { "default:torch", "default:torch", "building_blocks:sticks" },
  197. rarity = 1,
  198. }
  199. }
  200. }
  201. })
  202. -- EMBERS
  203. minetest.register_node("fake_fire:embers", {
  204. description = S("Glowing Embers"),
  205. tiles = {
  206. {name="embers_animated.png", animation={type="vertical_frames",
  207. aspect_w=16, aspect_h=16, length=2}},
  208. },
  209. light_source = 9,
  210. groups = {crumbly=3},
  211. paramtype = "light",
  212. sounds = default.node_sound_dirt_defaults(),
  213. })
  214. -- CHIMNEYS
  215. local materials = {
  216. { "stone", S("Stone chimney top") },
  217. { "sandstone", S("Sandstone chimney top") },
  218. }
  219. for _, mat in ipairs(materials) do
  220. local name, desc = unpack(mat)
  221. minetest.register_node("fake_fire:chimney_top_"..name, {
  222. description = desc,
  223. tiles = {"default_"..name..".png^chimney_top.png", "default_"..name..".png"},
  224. groups = {snappy=3},
  225. paramtype = "light",
  226. sounds = default.node_sound_stone_defaults(),
  227. drawtype = "nodebox",
  228. node_box = {
  229. type = "fixed",
  230. fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  231. },
  232. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  233. local chimney = 1
  234. start_fire_effects(pos, node, clicker, chimney)
  235. return itemstack
  236. end,
  237. on_destruct = function (pos)
  238. stop_smoke(pos)
  239. end
  240. })
  241. minetest.register_craft({
  242. type = "shapeless",
  243. output = 'fake_fire:chimney_top_'..name,
  244. recipe = {"default:torch", "stairs:slab_"..name}
  245. })
  246. end
  247. minetest.register_alias("fake_fire:flint_and_steel", "fire:flint_and_steel")
  248. minetest.override_item("default:ice", {
  249. on_ignite = function(pos, igniter)
  250. local flame_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
  251. if minetest.get_node(flame_pos).name == "air" then
  252. minetest.set_node(flame_pos, {name = "fake_fire:ice_fire"})
  253. end
  254. end
  255. })
  256. -- CRAFTS
  257. minetest.register_craft({
  258. type = "shapeless",
  259. output = 'fake_fire:embers',
  260. recipe = {"default:torch", "group:wood", "default:torch"}
  261. })
  262. minetest.register_craft({
  263. type = "shapeless",
  264. output = 'fake_fire:fancy_fire',
  265. recipe = {"default:torch", "building_blocks:sticks", "default:torch" }
  266. })
  267. -- ALIASES
  268. minetest.register_alias("fake_fire:smokeless_fire", "fake_fire:fake_fire")
  269. minetest.register_alias("fake_fire:smokeless_ice_fire", "fake_fire:ice_fire")
  270. minetest.register_alias("fake_fire:smokeless_chimney_top_stone", "fake_fire:chimney_top_stone")
  271. minetest.register_alias("fake_fire:smokeless_chimney_top_sandstone", "fake_fire:chimney_top_sandstone")
  272. minetest.register_alias("fake_fire:flint", "fake_fire:flint_and_steel")
  273. -- OTHER
  274. minetest.register_lbm({
  275. name = "fake_fire:reload_particles",
  276. label = "restart fire particles on reload",
  277. nodenames = {"fake_fire:fancy_fire"},
  278. run_at_every_load = true,
  279. action = function(pos, node)
  280. fire_particles_off(pos)
  281. fire_particles_on(pos)
  282. end
  283. })