2019-03-08 01:00:09 +02:00
local S = minetest.get_translator ( " mcl_fire " )
2017-02-01 17:39:51 +02:00
-- Fire Charge
minetest.register_craftitem ( " mcl_fire:fire_charge " , {
2019-03-08 01:00:09 +02:00
description = S ( " Fire Charge " ) ,
_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 17:39:51 +02:00
inventory_image = " mcl_fire_fire_charge.png " ,
liquids_pointable = false ,
stack_max = 64 ,
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
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-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-08-17 14:53:54 +03:00
-- Ignite/light fire
2017-02-01 17:39:51 +02:00
if pointed_thing.type == " node " then
2017-08-17 14:53:54 +03:00
local nodedef = minetest.registered_nodes [ node.name ]
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
2019-02-11 22:27:17 +02:00
mcl_fire.set_fire ( pointed_thing , user )
2017-09-19 16:45:23 +03:00
end
2017-02-01 17:39:51 +02:00
else
2019-02-11 22:27:17 +02:00
mcl_fire.set_fire ( pointed_thing , user )
2017-08-17 14:53:54 +03:00
end
if not minetest.settings : get_bool ( " creative_mode " ) then
itemstack : take_item ( )
2017-02-01 17:39:51 +02:00
end
end
return itemstack
end ,
2018-02-01 23:45:19 +02:00
_on_dispense = function ( stack , pos , droppos , dropnode , dropdir )
-- Throw fire charge
local shootpos = vector.add ( pos , vector.multiply ( dropdir , 0.51 ) )
local fireball = minetest.add_entity ( shootpos , " mobs_mc:blaze_fireball " )
local ent = fireball : get_luaentity ( )
ent._shot_from_dispenser = true
local v = ent.velocity or 1
2019-03-06 05:38:57 +02:00
fireball : set_velocity ( vector.multiply ( dropdir , v ) )
2018-02-01 23:45:19 +02:00
ent.switch = 1
stack : take_item ( )
end ,
2017-02-01 17:39:51 +02:00
} )
minetest.register_craft ( {
type = ' shapeless ' ,
output = ' mcl_fire:fire_charge 3 ' ,
2017-02-16 22:33:14 +02:00
recipe = { ' mcl_mobitems:blaze_powder ' , ' group:coal ' , ' mcl_mobitems:gunpowder ' } ,
2017-02-01 17:39:51 +02:00
} )