2015-03-09 18:52:56 +01:00
|
|
|
local stiffness=0
|
|
|
|
local bow_idle=false
|
|
|
|
local reload=0
|
|
|
|
|
|
|
|
local throwing_shoot_arrow = function(itemstack, player)
|
|
|
|
if not bow_idle then
|
|
|
|
bow_idle=true
|
|
|
|
for _,arrow in ipairs(arrows) do
|
|
|
|
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
player:get_inventory():remove_item("main", arrow[1])
|
|
|
|
end
|
|
|
|
local playerpos = player:getpos()
|
|
|
|
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
|
|
|
|
local dir = player:get_look_dir()
|
|
|
|
obj:setvelocity({x=dir.x*stiffness, y=dir.y*stiffness, z=dir.z*stiffness})
|
|
|
|
obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3})
|
|
|
|
obj:setyaw(player:get_look_yaw()+math.pi)
|
|
|
|
minetest.sound_play("throwing_sound", {pos=playerpos})
|
|
|
|
if obj:get_luaentity().player == "" then
|
|
|
|
obj:get_luaentity().player = player
|
|
|
|
end
|
|
|
|
obj:get_luaentity().stack = player:get_inventory():get_stack("main", player:get_wield_index()+2)
|
|
|
|
obj:get_luaentity().inventory = player:get_inventory()
|
2015-03-10 16:40:18 +01:00
|
|
|
obj:get_luaentity().breaks = math.random()
|
2015-03-09 18:52:56 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function reloading ()
|
|
|
|
minetest.after(reload, function()
|
|
|
|
bow_idle=false
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("throwing:bow_wood", {
|
|
|
|
description = "Wood Bow",
|
|
|
|
inventory_image = "throwing_bow_wood.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
stiffness = 15
|
|
|
|
reload = 1.1
|
|
|
|
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
|
|
|
|
reloading()
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:add_wear(65535/100)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'throwing:bow_wood',
|
|
|
|
recipe = {
|
|
|
|
{'farming:string', 'group:wood', ''},
|
|
|
|
{'farming:string', '', 'group:wood'},
|
|
|
|
{'farming:string', 'group:wood', ''},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_tool("throwing:bow_steel", {
|
|
|
|
description = "Steel Bow",
|
|
|
|
inventory_image = "throwing_bow_steel.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
stiffness = 20
|
2015-03-10 16:40:18 +01:00
|
|
|
reload = 1.5
|
2015-03-09 18:52:56 +01:00
|
|
|
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
|
|
|
|
reloading()
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:add_wear(65535/200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'throwing:bow_steel',
|
|
|
|
recipe = {
|
|
|
|
{'farming:string', 'default:steel_ingot', ''},
|
|
|
|
{'farming:string', '', 'default:steel_ingot'},
|
|
|
|
{'farming:string', 'default:steel_ingot', ''},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_tool("throwing:bow_composite", {
|
|
|
|
description = "Composite Bow",
|
|
|
|
inventory_image = "throwing_bow_composite.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
stiffness = 25
|
|
|
|
reload = 1.3
|
|
|
|
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
|
|
|
|
reloading()
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
2015-03-10 16:40:18 +01:00
|
|
|
itemstack:add_wear(65535/250)
|
2015-03-09 18:52:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'throwing:bow_composite',
|
|
|
|
recipe = {
|
|
|
|
{'farming:string', 'default:steel_ingot', 'group:wood'},
|
2015-03-10 16:40:18 +01:00
|
|
|
{'farming:string', 'group:wood', 'default:bronze_ingot'},
|
2015-03-09 18:52:56 +01:00
|
|
|
{'farming:string', 'default:steel_ingot', 'group:wood'},
|
|
|
|
}
|
|
|
|
})
|
2015-03-10 16:40:18 +01:00
|
|
|
|
|
|
|
minetest.register_tool("throwing:bow_gold", {
|
|
|
|
description = "Golden Bow",
|
|
|
|
inventory_image = "throwing_bow_gold.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
stiffness = 20
|
|
|
|
reload = 1.5
|
|
|
|
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
|
|
|
|
reloading()
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:add_wear(65535/1000)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'throwing:bow_composite',
|
|
|
|
recipe = {
|
|
|
|
{'farming:string', 'default:gold_ingot', ''},
|
|
|
|
{'farming:string', 'group:wood', 'default:gold_ingot'},
|
|
|
|
{'farming:string', 'default:steel_ingot', ''},
|
|
|
|
}
|
|
|
|
})
|