fireextinguisher.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. function epic.spray_foam(pos)
  2. for z = -4,4 do
  3. for y = -4,4 do
  4. for x = -4,4 do
  5. local p = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
  6. local nn = minetest.get_node(p).name
  7. if nn == 'fire:basic_flame' then
  8. minetest.set_node(p, {name='air'})
  9. minetest.sound_play('fire_extinguish_flame',{pos = p, max_hear_distance = 16, gain = 0.15})
  10. minetest.check_for_falling(p)
  11. end
  12. end
  13. end
  14. end
  15. end
  16. local function throw_anti_fire_bomb(item, player)
  17. local playerpos = player:get_pos()
  18. local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.625,z=playerpos.z}, 'epic:anti_fire_entity')
  19. local dir = player:get_look_dir()
  20. obj:set_velocity({x=dir.x*30, y=dir.y*30, z=dir.z*30})
  21. obj:set_acceleration({x=dir.x*-3, y=-dir.y^8*80-10, z=dir.z*-3})
  22. item:take_item()
  23. return item
  24. end
  25. minetest.register_craftitem('epic:anti_fire_bomb', {
  26. description = 'Anti fire bomb',
  27. inventory_image = 'epic_anti_fire.png',
  28. on_use = throw_anti_fire_bomb
  29. })
  30. minetest.register_node('epic:fire_extinguishing_powder', {
  31. description = 'Anti fire powder',
  32. drawtype = 'signlike',
  33. tiles = {'epic_anti_fire_powder.png'},
  34. inventory_image = 'epic_anti_fire_powder.png',
  35. wield_image = 'epic_anti_fire_powder.png',
  36. paramtype = 'light',
  37. paramtype2 = 'wallmounted',
  38. sunlight_propagates = true,
  39. selection_box = {
  40. type = 'fixed',
  41. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  42. },
  43. collision_box = {
  44. type = 'fixed',
  45. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  46. },
  47. groups = {dig_immediate = 3, attached_node = 1, flammable = 1},
  48. on_burn = function(pos)
  49. epic.spray_foam(pos)
  50. minetest.remove_node(pos)
  51. end,
  52. on_ignite = function(pos)
  53. epic.spray_foam(pos)
  54. minetest.remove_node(pos)
  55. end,
  56. })
  57. minetest.register_craft({
  58. output = 'epic:anti_fire_bomb',
  59. recipe = {
  60. {'', 'epic:fire_extinguishing_powder', '',},
  61. {'epic:fire_extinguishing_powder', 'tnt:tnt_stick', 'epic:fire_extinguishing_powder',},
  62. {'', 'epic:fire_extinguishing_powder', '',}
  63. }
  64. })
  65. minetest.register_entity('epic:anti_fire_entity', {
  66. timer=0,
  67. collisionbox = {0,0,0,0,0,0},
  68. physical = false,
  69. textures = {'epic_anti_fire.png'},
  70. lastpos={},
  71. on_step = function(self, dtime)
  72. self.timer = self.timer + dtime
  73. local pos = self.object:get_pos()
  74. local node = minetest.get_node(pos)
  75. if self.lastpos.x~=nil then
  76. if node.name ~= 'air' then
  77. self.object:remove()
  78. epic.spray_foam(self.lastpos)
  79. minetest.sound_play('tnt_explode', {pos = pos, max_hear_distance = 24, gain = 0.5})
  80. end
  81. end
  82. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  83. end
  84. })