2021-05-29 17:12:33 +03:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2021-03-15 02:10:33 +02:00
local get_node = minetest.get_node
local add_node = minetest.add_node
2019-03-08 01:00:09 +02:00
2017-02-01 17:31:27 +02:00
-- Flint and Steel
minetest.register_tool ( " mcl_fire:flint_and_steel " , {
2019-03-08 01:00:09 +02:00
description = S ( " Flint and Steel " ) ,
2021-04-16 00:41:34 +03:00
_tt_help = S ( " Starts fires and ignites blocks " ) ,
2019-03-08 01:00:09 +02:00
_doc_items_longdesc = S ( " Flint and steel is a tool to start fires and ignite blocks. " ) ,
_doc_items_usagehelp = S ( " Rightclick the surface of a block to attempt to light a fire in front of it or ignite the block. A few blocks have an unique reaction when ignited. " ) ,
2017-02-01 17:31:27 +02:00
inventory_image = " mcl_fire_flint_and_steel.png " ,
liquids_pointable = false ,
stack_max = 1 ,
2020-12-19 17:18:54 +02:00
groups = { tool = 1 , } ,
2017-03-11 03:51:31 +02:00
on_place = function ( itemstack , user , pointed_thing )
2017-07-24 20:57:37 +03:00
-- Use pointed node's on_rightclick function first, if present
2021-05-29 17:12:33 +03:00
local new_stack = mcl_util.call_on_rightclick ( itemstack , user , pointed_thing )
if new_stack then
return new_stack
2017-07-24 20:57:37 +03:00
end
2019-02-09 00:17:20 +02:00
-- Check protection
local protname = user : get_player_name ( )
if minetest.is_protected ( pointed_thing.under , protname ) then
minetest.record_protection_violation ( pointed_thing.under , protname )
return itemstack
end
2017-07-24 20:57:37 +03:00
2017-02-19 21:23:33 +02:00
local idef = itemstack : get_definition ( )
2017-02-19 23:58:51 +02:00
minetest.sound_play (
" fire_flint_and_steel " ,
2020-04-07 01:55:45 +03:00
{ pos = pointed_thing.above , gain = 0.5 , max_hear_distance = 8 } ,
true
2017-02-19 23:58:51 +02:00
)
2017-05-09 18:49:38 +03:00
local used = false
2017-02-01 17:31:27 +02:00
if pointed_thing.type == " node " then
2021-03-15 02:10:33 +02:00
local nodedef = minetest.registered_nodes [ get_node ( pointed_thing.under ) . name ]
2017-06-29 14:02:53 +03:00
if nodedef and nodedef._on_ignite then
2017-09-19 16:45:23 +03:00
local overwrite = nodedef._on_ignite ( user , pointed_thing )
if not overwrite then
2020-03-24 20:53:08 +02:00
mcl_fire.set_fire ( pointed_thing , user , false )
2017-09-19 16:45:23 +03:00
end
2017-02-01 17:31:27 +02:00
else
2020-03-24 20:53:08 +02:00
mcl_fire.set_fire ( pointed_thing , user , false )
2017-02-01 17:31:27 +02:00
end
2017-05-09 18:49:38 +03:00
used = true
2017-02-01 17:31:27 +02:00
end
2017-02-19 21:23:33 +02:00
if itemstack : get_count ( ) == 0 and idef.sound and idef.sound . breaks then
2020-04-07 01:55:45 +03:00
minetest.sound_play ( idef.sound . breaks , { pos = user : get_pos ( ) , gain = 0.5 } , true )
2017-02-19 21:23:33 +02:00
end
2020-07-10 17:08:40 +03:00
if ( not minetest.is_creative_enabled ( user : get_player_name ( ) ) ) and used == true then
2017-05-09 18:49:38 +03:00
itemstack : add_wear ( 65535 / 65 ) -- 65 uses
end
2017-02-01 17:45:49 +02:00
return itemstack
2017-02-01 17:31:27 +02:00
end ,
2018-02-01 23:45:19 +02:00
_dispense_into_walkable = true ,
_on_dispense = function ( stack , pos , droppos , dropnode , dropdir )
2019-02-09 00:17:20 +02:00
-- Ignite air
2018-02-01 23:45:19 +02:00
if dropnode.name == " air " then
2021-03-15 02:10:33 +02:00
add_node ( droppos , { name = " mcl_fire:fire " } )
2020-07-10 17:08:40 +03:00
if not minetest.is_creative_enabled ( " " ) then
2018-02-01 23:45:19 +02:00
stack : add_wear ( 65535 / 65 ) -- 65 uses
end
2019-02-09 00:17:20 +02:00
-- Ignite TNT
2018-02-01 23:45:19 +02:00
elseif dropnode.name == " mcl_tnt:tnt " then
tnt.ignite ( droppos )
2020-07-10 17:08:40 +03:00
if not minetest.is_creative_enabled ( " " ) then
2018-02-01 23:45:19 +02:00
stack : add_wear ( 65535 / 65 ) -- 65 uses
end
end
return stack
end ,
2017-02-19 21:23:33 +02:00
sound = { breaks = " default_tool_breaks " } ,
2020-12-21 16:12:24 +02:00
_mcl_uses = 65 ,
2017-02-01 17:31:27 +02:00
} )
minetest.register_craft ( {
2021-05-29 17:12:33 +03:00
type = " shapeless " ,
output = " mcl_fire:flint_and_steel " ,
recipe = { " mcl_core:iron_ingot " , " mcl_core:flint " } ,
2017-02-01 17:31:27 +02:00
} )