2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-08 00:00:09 +01:00
2021-03-15 01:10:33 +01:00
local get_node = minetest.get_node
local add_entity = minetest.add_entity
2017-02-01 16:39:51 +01:00
-- Fire Charge
minetest.register_craftitem ( " mcl_fire:fire_charge " , {
2019-03-08 00:00:09 +01:00
description = S ( " Fire Charge " ) ,
2021-04-15 23:41:34 +02:00
_tt_help = S ( " Dispenser projectile " ) .. " \n " .. S ( " Starts fires and ignites blocks " ) ,
2019-03-08 00:00:09 +01:00
_doc_items_longdesc = S ( " Fire charges are primarily projectiles which can be launched from dispensers, they will fly in a straight line and burst into a fire on impact. Alternatively, they can be used to ignite fires directly. " ) ,
_doc_items_usagehelp = S ( " Put the fire charge into a dispenser and supply it with redstone power to launch it. To ignite a fire directly, simply place the fire charge on the ground, which uses it up. " ) ,
2017-02-01 16:39:51 +01:00
inventory_image = " mcl_fire_fire_charge.png " ,
liquids_pointable = false ,
stack_max = 64 ,
2017-03-11 02:51:31 +01:00
on_place = function ( itemstack , user , pointed_thing )
2017-07-24 19:57:37 +02:00
-- Use pointed node's on_rightclick function first, if present
2021-05-29 16:12:33 +02:00
local new_stack = mcl_util.call_on_rightclick ( itemstack , user , pointed_thing )
if new_stack then
return new_stack
2017-07-24 19:57:37 +02:00
end
2019-02-08 23:17:20 +01: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-08-17 13:53:54 +02:00
-- Ignite/light fire
2021-05-29 16:12:33 +02:00
local node = get_node ( pointed_thing.under )
2017-02-01 16:39:51 +01:00
if pointed_thing.type == " node " then
2017-08-17 13:53:54 +02:00
local nodedef = minetest.registered_nodes [ node.name ]
if nodedef and nodedef._on_ignite then
2017-09-19 15:45:23 +02:00
local overwrite = nodedef._on_ignite ( user , pointed_thing )
if not overwrite then
2020-03-24 19:53:08 +01:00
mcl_fire.set_fire ( pointed_thing , user , false )
2017-09-19 15:45:23 +02:00
end
2017-02-01 16:39:51 +01:00
else
2020-03-24 19:53:08 +01:00
mcl_fire.set_fire ( pointed_thing , user , false )
2017-08-17 13:53:54 +02:00
end
2020-07-10 16:08:40 +02:00
if not minetest.is_creative_enabled ( user : get_player_name ( ) ) then
2017-08-17 13:53:54 +02:00
itemstack : take_item ( )
2017-02-01 16:39:51 +01:00
end
end
return itemstack
end ,
2018-02-01 22:45:19 +01:00
_on_dispense = function ( stack , pos , droppos , dropnode , dropdir )
-- Throw fire charge
local shootpos = vector.add ( pos , vector.multiply ( dropdir , 0.51 ) )
2022-02-16 03:13:39 +01:00
local fireball = add_entity ( shootpos , " mobs_mc:blaze_fireball_entity " )
2018-02-01 22:45:19 +01:00
local ent = fireball : get_luaentity ( )
2021-06-25 01:57:01 +02:00
if ent then
ent._shot_from_dispenser = true
local v = ent.velocity or 1
fireball : set_velocity ( vector.multiply ( dropdir , v ) )
ent.switch = 1
stack : take_item ( )
end
2018-02-01 22:45:19 +01:00
end ,
2017-02-01 16:39:51 +01:00
} )
minetest.register_craft ( {
2021-05-29 16:12:33 +02:00
type = " shapeless " ,
output = " mcl_fire:fire_charge 3 " ,
recipe = { " mcl_mobitems:blaze_powder " , " group:coal " , " mcl_mobitems:gunpowder " } ,
2017-02-01 16:39:51 +01:00
} )