init.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. -- Flint & Steel
  2. flint_and_steel = flint_and_steel or {}
  3. flint_and_steel.modpath = minetest.get_modpath("flint_and_steel")
  4. -- Flint & steel on-use callback.
  5. function flint_and_steel.on_use(itemstack, user, pointed_thing)
  6. if not user or not user:is_player() then return end
  7. local pname = user:get_player_name()
  8. local pt = pointed_thing
  9. if pt.type ~= "node" then return end
  10. -- What are we pointing at?
  11. local nn = minetest.get_node(pt.under).name
  12. -- If node has 'on_ignite' defined, use that instead.
  13. -- Assume the 'on_ignite' callback handles protection checks and stuff.
  14. local ndef = minetest.reg_ns_nodes[nn]
  15. if ndef and ndef.on_ignite then
  16. ndef.on_ignite(pt.under)
  17. else
  18. -- Does not have 'on_ignite' defined!
  19. local is_coalblock = (nn == "default:coalblock")
  20. local is_netherack = (nn == "rackstone:redrack" or nn == "rackstone:mg_redrack")
  21. local is_tnt = (nn == "tnt:tnt")
  22. local is_gunpowder = (nn == "tnt:gunpowder")
  23. local is_flammable = (minetest.get_item_group(nn, "flammable") ~= 0)
  24. -- Allow stairs, slabs, dark obsidian, etc. to be struck by firestriker.
  25. -- This comes before protection check so that players can use others' portals.
  26. if string.find(nn, "obsidian") then
  27. flameportal.try_teleport_on_flint_use(user)
  28. end
  29. if string.find(nn, "obsidian") or string.find(nn, "grieferstone") then
  30. obsidian_gateway.attempt_activation(pt.under, user)
  31. end
  32. if nn == "default:obsidian" then
  33. local result, pos = flameportal.find_gateway(pt.under)
  34. if result == true and pos then
  35. flameportal.activate_gateway(pos)
  36. end
  37. end
  38. if is_flammable or is_coalblock or is_tnt or is_gunpowder or is_netherack then
  39. -- Check if fires can be started at this location.
  40. -- Don't let user start a fire if location is protected.
  41. if not minetest.test_protection(pt.under, pname) then
  42. local flame_pos = pt.above
  43. if is_coalblock or is_netherack then
  44. flame_pos = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
  45. elseif is_tnt or is_gunpowder then
  46. flame_pos = pt.under
  47. end
  48. if minetest.get_node(flame_pos).name == "air" or is_tnt or is_gunpowder then
  49. if is_coalblock then
  50. minetest.add_node(flame_pos, {name = "fire:permanent_flame"})
  51. elseif is_netherack then
  52. minetest.add_node(flame_pos, {name = "fire:nether_flame"})
  53. elseif is_tnt then
  54. minetest.add_node(flame_pos, {name = "tnt:tnt_burning"})
  55. elseif is_gunpowder then
  56. minetest.add_node(flame_pos, {name = "tnt:gunpowder_burning"})
  57. else
  58. minetest.add_node(flame_pos, {name = "fire:basic_flame"})
  59. end
  60. end
  61. end
  62. end
  63. end
  64. -- Trigger gas explosions sometimes.
  65. breath.ignite_nearby_gas(pt.under)
  66. -- Wear tool.
  67. itemstack:add_wear(1000)
  68. -- Tool break sound.
  69. if itemstack:get_count() == 0 then
  70. ambiance.sound_play("default_tool_breaks", pt.above, 0.7, 20)
  71. end
  72. -- Play sound.
  73. ambiance.sound_play("fire_flint_and_steel", pt.above, 0.7, 20)
  74. return itemstack
  75. end
  76. -- One-time registrations.
  77. if not flint_and_steel.run_once then
  78. minetest.register_tool("flint_and_steel:flint_and_steel", {
  79. description = "Flint & Steel",
  80. inventory_image = "fire_flint_steel.png",
  81. sound = {breaks = "default_tool_breaks"},
  82. groups = {not_repaired_by_anvil = 1},
  83. on_use = function(...)
  84. return flint_and_steel.on_use(...)
  85. end
  86. })
  87. minetest.register_craft({
  88. output = "flint_and_steel:flint_and_steel",
  89. recipe = {
  90. {"default:flint", "default:steel_ingot"},
  91. }
  92. })
  93. minetest.register_alias("fire:flint_and_steel", "flint_and_steel:flint_and_steel")
  94. local c = "flint_and_steel:core"
  95. local f = flint_and_steel.modpath .. "/init.lua"
  96. reload.register_file(c, f, false)
  97. flint_and_steel.run_once = true
  98. end