1
0
Fork 0

Kinda allow arrow shooting from dispensers

objects
Wuzzy 2017-02-14 22:04:37 +01:00
parent 27e6352704
commit 4d0e1eb2e9
2 changed files with 22 additions and 10 deletions

View File

@ -4,13 +4,13 @@ dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
mcl_throwing = {} mcl_throwing = {}
local arrows = { local arrows = {
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity"}, ["mcl_throwing:arrow"] = "mcl_throwing:arrow_entity",
} }
local GRAVITY = 9.81 local GRAVITY = 9.81
mcl_throwing.shoot_arrow = function(entity_name, pos, dir, yaw, shooter) mcl_throwing.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter)
local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, entity_name) local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, arrows[arrow_item])
obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19}) obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3}) obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
obj:setyaw(yaw+math.pi/2) obj:setyaw(yaw+math.pi/2)
@ -25,16 +25,16 @@ mcl_throwing.shoot_arrow = function(entity_name, pos, dir, yaw, shooter)
end end
local player_shoot_arrow = function(itemstack, player) local player_shoot_arrow = function(itemstack, player)
for _,arrow in ipairs(arrows) do for arrow_item, arrow_entity in pairs(arrows) do
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow_item then
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
player:get_inventory():remove_item("main", arrow[1]) player:get_inventory():remove_item("main", arrow_item)
end end
local playerpos = player:getpos() local playerpos = player:getpos()
local dir = player:get_look_dir() local dir = player:get_look_dir()
local yaw = player:get_look_horizontal() local yaw = player:get_look_horizontal()
mcl_throwing.shoot_arrow(arrow[2], {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player) mcl_throwing.shoot_arrow(arrow_item, {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player)
return true return true
end end
end end

View File

@ -49,12 +49,15 @@ local dispenserdef = {
action_on = function (pos, node) action_on = function (pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local droppos local droppos, dropdir
if node.name == "mcl_dispensers:dispenser" then if node.name == "mcl_dispensers:dispenser" then
droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) dropdir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
droppos = vector.subtract(pos, dropdir)
elseif node.name == "mcl_dispensers:dispenser_up" then elseif node.name == "mcl_dispensers:dispenser_up" then
dropdir = {x=0, y=1, z=0}
droppos = {x=pos.x, y=pos.y+1, z=pos.z} droppos = {x=pos.x, y=pos.y+1, z=pos.z}
elseif node.name == "mcl_dispensers:dispenser_down" then elseif node.name == "mcl_dispensers:dispenser_down" then
dropdir = {x=0, y=-1, z=0}
droppos = {x=pos.x, y=pos.y-1, z=pos.z} droppos = {x=pos.x, y=pos.y-1, z=pos.z}
end end
local dropnode = minetest.get_node(droppos) local dropnode = minetest.get_node(droppos)
@ -79,7 +82,16 @@ local dispenserdef = {
local igroups = minetest.registered_items[iname].groups local igroups = minetest.registered_items[iname].groups
--[===[ Dispense item ]===] --[===[ Dispense item ]===]
if iname == "mcl_fire:flint_and_steel" then if iname == "mcl_throwing:arrow" then
-- Shoot arrow
local shootpos = vector.add(droppos, dropdir)
-- FIXME: Bad yaw of arrow when shootin
mcl_throwing.shoot_arrow(iname, shootpos, dropdir, 0, nil)
stack:take_item()
inv:set_stack("main", stack_id, stack)
elseif iname == "mcl_fire:flint_and_steel" then
-- Ignite air or fire -- Ignite air or fire
if dropnode.name == "air" then if dropnode.name == "air" then
minetest.add_node(droppos, {name="mcl_fire:basic_flame"}) minetest.add_node(droppos, {name="mcl_fire:basic_flame"})