2017-02-14 23:18:23 +01:00
|
|
|
mcl_throwing = {}
|
|
|
|
|
2017-01-16 23:11:04 +01:00
|
|
|
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
|
|
|
|
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
|
2015-06-29 19:55:56 +02:00
|
|
|
|
2017-01-24 02:31:49 +01:00
|
|
|
local arrows = {
|
2017-02-14 22:04:37 +01:00
|
|
|
["mcl_throwing:arrow"] = "mcl_throwing:arrow_entity",
|
2015-06-29 19:55:56 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 23:11:04 +01:00
|
|
|
local GRAVITY = 9.81
|
|
|
|
|
2017-02-14 22:04:37 +01:00
|
|
|
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}, arrows[arrow_item])
|
2017-02-14 21:29:28 +01:00
|
|
|
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})
|
2017-02-21 22:31:39 +01:00
|
|
|
obj:setyaw(yaw-math.pi/2)
|
2017-02-14 21:29:28 +01:00
|
|
|
minetest.sound_play("mcl_throwing_bow_shoot", {pos=pos})
|
|
|
|
if shooter ~= nil then
|
|
|
|
if obj:get_luaentity().player == "" then
|
|
|
|
obj:get_luaentity().player = shooter
|
|
|
|
end
|
|
|
|
obj:get_luaentity().node = shooter:get_inventory():get_stack("main", 1):get_name()
|
|
|
|
end
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
2017-02-21 22:18:27 +01:00
|
|
|
local get_arrow = function(player)
|
2017-02-21 21:59:45 +01:00
|
|
|
local inv = player:get_inventory()
|
2017-02-21 22:18:27 +01:00
|
|
|
local arrow_stack, arrow_stack_id
|
2017-02-21 21:59:45 +01:00
|
|
|
for i=1, inv:get_size("main") do
|
|
|
|
local it = inv:get_stack("main", i)
|
|
|
|
if not it:is_empty() and minetest.get_item_group(it:get_name(), "ammo_bow") ~= 0 then
|
|
|
|
arrow_stack = it
|
|
|
|
arrow_stack_id = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2017-02-21 22:18:27 +01:00
|
|
|
return arrow_stack, arrow_stack_id
|
|
|
|
end
|
|
|
|
|
|
|
|
local player_shoot_arrow = function(itemstack, player)
|
|
|
|
local arrow_stack, arrow_stack_id = get_arrow(player)
|
|
|
|
local arrow_itemstring
|
2017-02-21 21:59:45 +01:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
if not arrow_stack then
|
|
|
|
return false
|
2015-06-29 19:55:56 +02:00
|
|
|
end
|
2017-02-21 22:18:27 +01:00
|
|
|
arrow_itemstring = arrow_stack:get_name()
|
2017-02-21 21:59:45 +01:00
|
|
|
arrow_stack:take_item()
|
2017-02-21 22:18:27 +01:00
|
|
|
local inv = player:get_inventory()
|
2017-02-21 21:59:45 +01:00
|
|
|
inv:set_stack("main", arrow_stack_id, arrow_stack)
|
|
|
|
end
|
|
|
|
local playerpos = player:getpos()
|
|
|
|
local dir = player:get_look_dir()
|
|
|
|
local yaw = player:get_look_horizontal()
|
|
|
|
|
|
|
|
if not arrow_itemstring then
|
|
|
|
arrow_itemstring = "mcl_throwing:arrow"
|
2015-06-29 19:55:56 +02:00
|
|
|
end
|
2017-02-21 21:59:45 +01:00
|
|
|
mcl_throwing.shoot_arrow(arrow_itemstring, {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player)
|
|
|
|
return true
|
2015-06-29 19:55:56 +02:00
|
|
|
end
|
|
|
|
|
2017-02-14 22:09:00 +01:00
|
|
|
local powerup_function = function(nextbow)
|
|
|
|
return function(itemstack, placer, pointed_thing)
|
2017-02-21 22:18:27 +01:00
|
|
|
if get_arrow(placer) ~= nil then
|
|
|
|
local wear = itemstack:get_wear()
|
|
|
|
itemstack:replace(nextbow)
|
|
|
|
itemstack:set_wear(wear)
|
|
|
|
end
|
2015-06-29 19:55:56 +02:00
|
|
|
return itemstack
|
2017-02-14 22:09:00 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("mcl_throwing:bow", {
|
|
|
|
description = "Bow",
|
|
|
|
inventory_image = "mcl_throwing_bow.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_place = powerup_function("mcl_throwing:bow_0"),
|
|
|
|
on_secondary_use = powerup_function("mcl_throwing:bow_0"),
|
2017-01-20 04:54:09 +01:00
|
|
|
groups = {weapon=1,weapon_ranged=1},
|
2015-06-29 19:55:56 +02:00
|
|
|
})
|
|
|
|
|
2017-01-16 23:11:04 +01:00
|
|
|
minetest.register_tool("mcl_throwing:bow_0", {
|
2015-06-29 19:55:56 +02:00
|
|
|
description = "Bow",
|
2017-01-16 23:11:04 +01:00
|
|
|
inventory_image = "mcl_throwing_bow_0.png",
|
2017-02-14 22:09:00 +01:00
|
|
|
stack_max = 1,
|
2017-02-14 16:35:25 +01:00
|
|
|
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
|
2017-02-14 22:09:00 +01:00
|
|
|
on_place = powerup_function("mcl_throwing:bow_1"),
|
|
|
|
on_secondary_use = powerup_function("mcl_throwing:bow_1"),
|
2015-06-29 19:55:56 +02:00
|
|
|
})
|
|
|
|
|
2017-01-16 23:11:04 +01:00
|
|
|
minetest.register_tool("mcl_throwing:bow_1", {
|
2015-06-29 19:55:56 +02:00
|
|
|
description = "Bow",
|
2017-01-16 23:11:04 +01:00
|
|
|
inventory_image = "mcl_throwing_bow_1.png",
|
2017-02-14 22:09:00 +01:00
|
|
|
stack_max = 1,
|
2017-02-14 16:35:25 +01:00
|
|
|
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
|
2017-02-14 22:09:00 +01:00
|
|
|
on_place = powerup_function("mcl_throwing:bow_2"),
|
|
|
|
on_secondary_use = powerup_function("mcl_throwing:bow_2"),
|
2015-06-29 19:55:56 +02:00
|
|
|
})
|
|
|
|
|
2017-01-16 23:11:04 +01:00
|
|
|
minetest.register_tool("mcl_throwing:bow_2", {
|
2015-06-29 19:55:56 +02:00
|
|
|
description = "Bow",
|
2017-01-16 23:11:04 +01:00
|
|
|
inventory_image = "mcl_throwing_bow_2.png",
|
2017-02-14 22:09:00 +01:00
|
|
|
stack_max = 1,
|
2017-02-14 16:35:25 +01:00
|
|
|
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
|
2015-06-29 19:55:56 +02:00
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2017-01-24 02:31:49 +01:00
|
|
|
local wear = itemstack:get_wear()
|
2017-01-16 23:11:04 +01:00
|
|
|
itemstack:replace("mcl_throwing:bow")
|
2017-02-21 22:18:27 +01:00
|
|
|
itemstack:set_wear(wear)
|
2017-02-14 21:29:28 +01:00
|
|
|
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
2015-06-29 19:55:56 +02:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:add_wear(65535/385)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2017-01-16 23:11:04 +01:00
|
|
|
output = 'mcl_throwing:bow',
|
2015-06-29 19:55:56 +02:00
|
|
|
recipe = {
|
2017-02-01 17:59:15 +01:00
|
|
|
{'', 'mcl_core:stick', 'mcl_mobitems:string'},
|
|
|
|
{'mcl_core:stick', '', 'mcl_mobitems:string'},
|
|
|
|
{'', 'mcl_core:stick', 'mcl_mobitems:string'},
|
2015-06-29 19:55:56 +02:00
|
|
|
}
|
|
|
|
})
|
2017-01-10 01:59:21 +01:00
|
|
|
minetest.register_craft({
|
2017-01-16 23:11:04 +01:00
|
|
|
output = 'mcl_throwing:bow',
|
2017-01-10 01:59:21 +01:00
|
|
|
recipe = {
|
2017-02-01 17:59:15 +01:00
|
|
|
{'mcl_mobitems:string', 'mcl_core:stick', ''},
|
|
|
|
{'mcl_mobitems:string', '', 'mcl_core:stick'},
|
|
|
|
{'mcl_mobitems:string', 'mcl_core:stick', ''},
|
2017-01-10 01:59:21 +01:00
|
|
|
}
|
|
|
|
})
|
2015-06-29 19:55:56 +02:00
|
|
|
|
2017-01-10 06:43:07 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
type = "fuel",
|
2017-01-16 23:11:04 +01:00
|
|
|
recipe = "mcl_throwing:bow",
|
2017-01-10 06:43:07 +01:00
|
|
|
burntime = 15,
|
|
|
|
})
|