e6f7fe7877
Hopefully the last time that this is needed. Please check indentation is correct before submitting patches, please.
49 lines
1.5 KiB
Lua
49 lines
1.5 KiB
Lua
arrows = {
|
|
{"castle:arrow", "castle:arrow_entity"},
|
|
}
|
|
|
|
local castle_shoot_arrow = function(itemstack, player)
|
|
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*19, y=dir.y*19, z=dir.z*19})
|
|
obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3})
|
|
obj:setyaw(player:get_look_yaw()+math.pi)
|
|
minetest.sound_play("castle_sound", {pos=playerpos})
|
|
if obj:get_luaentity().player == "" then
|
|
obj:get_luaentity().player = player
|
|
end
|
|
obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
minetest.register_tool("castle:crossbow", {
|
|
description = "Crossbow",
|
|
inventory_image = "castle_crossbow.png",
|
|
stack_max = 1,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
if castle_shoot_arrow(item, user, pointed_thing) then
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
itemstack:add_wear(65535/200)
|
|
end
|
|
end
|
|
return itemstack
|
|
end,
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = 'castle:crossbow',
|
|
recipe = {
|
|
{'default:steel_ingot', 'default:stick', 'default:steel_ingot'},
|
|
{'farming:string', 'farming:string', 'farming:string'},
|
|
{'', 'default:stick', ''},
|
|
}
|
|
})
|