1
0
Fork 0
MineClone2/mods/ITEMS/mcl_fire/flint_and_steel.lua

80 lines
2.8 KiB
Lua
Raw Normal View History

local S = minetest.get_translator("mcl_fire")
2017-02-01 15:31:27 +00:00
-- Flint and Steel
minetest.register_tool("mcl_fire:flint_and_steel", {
description = S("Flint and Steel"),
2020-02-19 03:54:17 +00:00
_tt_help = S("Starts fires and ignites blocks"),
_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 15:31:27 +00:00
inventory_image = "mcl_fire_flint_and_steel.png",
liquids_pointable = false,
stack_max = 1,
groups = { tool = 1, },
on_place = function(itemstack, user, pointed_thing)
-- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node(pointed_thing.under)
if user and not user:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
end
end
2019-02-08 22:17:20 +00: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
local idef = itemstack:get_definition()
2017-02-19 21:58:51 +00:00
minetest.sound_play(
"fire_flint_and_steel",
2020-04-06 22:55:45 +00:00
{pos = pointed_thing.above, gain = 0.5, max_hear_distance = 8},
true
2017-02-19 21:58:51 +00:00
)
local used = false
2017-02-01 15:31:27 +00:00
if pointed_thing.type == "node" then
local nodedef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
if nodedef and nodedef._on_ignite then
local overwrite = nodedef._on_ignite(user, pointed_thing)
if not overwrite then
2020-03-24 18:53:08 +00:00
mcl_fire.set_fire(pointed_thing, user, false)
end
2017-02-01 15:31:27 +00:00
else
2020-03-24 18:53:08 +00:00
mcl_fire.set_fire(pointed_thing, user, false)
2017-02-01 15:31:27 +00:00
end
used = true
2017-02-01 15:31:27 +00:00
end
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
2020-04-06 22:55:45 +00:00
minetest.sound_play(idef.sound.breaks, {pos=user:get_pos(), gain=0.5}, true)
end
2020-07-10 14:08:40 +00:00
if (not minetest.is_creative_enabled(user:get_player_name())) and used == true then
itemstack:add_wear(65535/65) -- 65 uses
end
return itemstack
2017-02-01 15:31:27 +00:00
end,
_dispense_into_walkable = true,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
2019-02-08 22:17:20 +00:00
-- Ignite air
if dropnode.name == "air" then
minetest.add_node(droppos, {name="mcl_fire:fire"})
2020-07-10 14:08:40 +00:00
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
2019-02-08 22:17:20 +00:00
-- Ignite TNT
elseif dropnode.name == "mcl_tnt:tnt" then
tnt.ignite(droppos)
2020-07-10 14:08:40 +00:00
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
end
return stack
end,
sound = { breaks = "default_tool_breaks" },
2017-02-01 15:31:27 +00:00
})
minetest.register_craft({
type = 'shapeless',
2017-02-01 15:39:51 +00:00
output = 'mcl_fire:flint_and_steel',
2017-02-11 20:14:40 +00:00
recipe = { 'mcl_core:iron_ingot', 'mcl_core:flint'},
2017-02-01 15:31:27 +00:00
})