init.lua 3.7 KB

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