throwing/tools.lua

99 lines
3.2 KiB
Lua
Raw Normal View History

2015-03-31 20:14:46 +02:00
function throwing_register_bow (name, desc, scale, stiffness, reload_time, toughness, is_cross, craft)
minetest.register_tool("throwing:" .. name, {
description = desc,
inventory_image = "throwing_" .. name .. ".png",
wield_scale = scale,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
local pos = user:getpos()
minetest.after(reload_time, throwing_reload, itemstack, user, pos, is_cross, "throwing:" .. name .. "_loaded")
return itemstack
end,
})
minetest.register_tool("throwing:" .. name .. "_loaded", {
description = desc,
inventory_image = "throwing_" .. name .. "_loaded.png",
wield_scale = scale,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
local wear = itemstack:get_wear()
if not minetest.setting_getbool("creative_mode") then
wear = wear + (65535/toughness)
end
local unloaded = "throwing:" .. name
throwing_shoot_arrow(itemstack, user, stiffness, is_cross)
minetest.after(0.01, throwing_unload, itemstack, user, unloaded, wear)
return itemstack
end,
on_drop = function(itemstack, dropper, pointed_thing)
local wear = itemstack:get_wear()
local unloaded = "throwing:" .. name
minetest.after(0.01, throwing_unload, itemstack, dropper, unloaded, wear)
end,
groups = {not_in_creative_inventory=1},
})
minetest.register_craft({
output = 'throwing:' .. name,
recipe = craft
})
minetest.register_craft({
output = 'throwing:' .. name,
recipe = {
{craft[1][3], craft[1][2], craft[1][1]},
{craft[2][3], craft[2][2], craft[2][1]},
{craft[3][3], craft[3][2], craft[3][1]},
}
})
end
if not DISABLE_WOODEN_BOW then
throwing_register_bow ('bow_wood', 'Wooden bow', {x=1, y=1, z=0.5}, 11, 0.8, 50, false, {
{'', 'default:stick', ''},
{'farming:string', '', 'default:stick'},
{'', 'default:stick', ''},
})
end
if not DISABLE_LONGBOW then
throwing_register_bow ('longbow', 'Longbow', {x=1, y=2.5, z=0.5}, 17, 1.8, 100, false, {
{'farming:string', 'group:wood', ''},
{'farming:string', '', 'group:wood'},
{'farming:string', 'group:wood', ''},
})
end
if not DISABLE_COMPOSITE_BOW then
throwing_register_bow ('bow_composite', 'Composite bow', {x=1, y=1.4, z=0.5}, 17, 1, 150, false, {
{'farming:string', 'group:wood', ''},
{'farming:string', '', 'default:steel_ingot'},
{'farming:string', 'group:wood', ''},
})
end
if not DISABLE_STEEL_BOW then
throwing_register_bow ('bow_steel', 'Steel bow', {x=1, y=1.4, z=0.5}, 20, 1.3, 250, false, {
{'farming:string', 'default:steel_ingot', ''},
{'farming:string', '', 'default:steel_ingot'},
{'farming:string', 'default:steel_ingot', ''},
})
end
if not DISABLE_ROYAL_BOW then
throwing_register_bow ('bow_royal', 'Royal bow', {x=1, y=1.5, z=0.5}, 18, 1.4, 750, false, {
{'farming:string', 'group:wood', 'default:diamond'},
{'farming:string', '', 'default:gold_ingot'},
{'farming:string', 'group:wood', 'default:diamond'},
})
end
if not DISABLE_CROSSBOW then
throwing_register_bow ('crossbow', 'Crossbow', {x=1, y=1, z=0.5}, 28, 5, 80, true, {
{'group:wood', 'farming:string', ''},
{'default:steel_ingot', 'farming:string', 'group:wood'},
{'group:wood', 'farming:string', ''},
})
end