Fix bow charging without arrows
This commit is contained in:
parent
d25feb2990
commit
3fc496c0e1
|
@ -24,23 +24,30 @@ mcl_throwing.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter)
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_shoot_arrow = function(itemstack, player)
|
local get_arrow = function(player)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local arrow_stack, arrow_itemstring, arrow_stack_id
|
local arrow_stack, arrow_stack_id
|
||||||
for i=1, inv:get_size("main") do
|
for i=1, inv:get_size("main") do
|
||||||
local it = inv:get_stack("main", i)
|
local it = inv:get_stack("main", i)
|
||||||
if not it:is_empty() and minetest.get_item_group(it:get_name(), "ammo_bow") ~= 0 then
|
if not it:is_empty() and minetest.get_item_group(it:get_name(), "ammo_bow") ~= 0 then
|
||||||
arrow_stack = it
|
arrow_stack = it
|
||||||
arrow_itemstring = it:get_name()
|
|
||||||
arrow_stack_id = i
|
arrow_stack_id = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
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
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
if not arrow_stack then
|
if not arrow_stack then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
arrow_itemstring = arrow_stack:get_name()
|
||||||
arrow_stack:take_item()
|
arrow_stack:take_item()
|
||||||
|
local inv = player:get_inventory()
|
||||||
inv:set_stack("main", arrow_stack_id, arrow_stack)
|
inv:set_stack("main", arrow_stack_id, arrow_stack)
|
||||||
end
|
end
|
||||||
local playerpos = player:getpos()
|
local playerpos = player:getpos()
|
||||||
|
@ -56,9 +63,11 @@ end
|
||||||
|
|
||||||
local powerup_function = function(nextbow)
|
local powerup_function = function(nextbow)
|
||||||
return function(itemstack, placer, pointed_thing)
|
return function(itemstack, placer, pointed_thing)
|
||||||
local wear = itemstack:get_wear()
|
if get_arrow(placer) ~= nil then
|
||||||
itemstack:replace(nextbow)
|
local wear = itemstack:get_wear()
|
||||||
itemstack:add_wear(wear)
|
itemstack:replace(nextbow)
|
||||||
|
itemstack:set_wear(wear)
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -70,16 +79,6 @@ minetest.register_tool("mcl_throwing:bow", {
|
||||||
on_place = powerup_function("mcl_throwing:bow_0"),
|
on_place = powerup_function("mcl_throwing:bow_0"),
|
||||||
on_secondary_use = powerup_function("mcl_throwing:bow_0"),
|
on_secondary_use = powerup_function("mcl_throwing:bow_0"),
|
||||||
groups = {weapon=1,weapon_ranged=1},
|
groups = {weapon=1,weapon_ranged=1},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
local wear = itemstack:get_wear()
|
|
||||||
itemstack:add_wear(wear)
|
|
||||||
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
itemstack:add_wear(65535/385)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return itemstack
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("mcl_throwing:bow_0", {
|
minetest.register_tool("mcl_throwing:bow_0", {
|
||||||
|
@ -92,10 +91,10 @@ minetest.register_tool("mcl_throwing:bow_0", {
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local wear = itemstack:get_wear()
|
local wear = itemstack:get_wear()
|
||||||
itemstack:replace("mcl_throwing:bow")
|
itemstack:replace("mcl_throwing:bow")
|
||||||
itemstack:add_wear(wear)
|
itemstack:set_wear(wear)
|
||||||
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535/385)
|
itemstack:add_wear(65535/1600)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
|
@ -112,10 +111,10 @@ minetest.register_tool("mcl_throwing:bow_1", {
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local wear = itemstack:get_wear()
|
local wear = itemstack:get_wear()
|
||||||
itemstack:replace("mcl_throwing:bow")
|
itemstack:replace("mcl_throwing:bow")
|
||||||
itemstack:add_wear(wear)
|
itemstack:set_wear(wear)
|
||||||
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535/385)
|
itemstack:add_wear(65535/800)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
|
@ -130,7 +129,7 @@ minetest.register_tool("mcl_throwing:bow_2", {
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local wear = itemstack:get_wear()
|
local wear = itemstack:get_wear()
|
||||||
itemstack:replace("mcl_throwing:bow")
|
itemstack:replace("mcl_throwing:bow")
|
||||||
itemstack:add_wear(wear)
|
itemstack:set_wear(wear)
|
||||||
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
if player_shoot_arrow(itemstack, user, pointed_thing) then
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535/385)
|
itemstack:add_wear(65535/385)
|
||||||
|
|
Loading…
Reference in New Issue