Call allow_shot twice

Once before the delay, and one after it
This commit is contained in:
upsilon 2017-06-25 09:59:35 +02:00
parent 973b3430e8
commit 99e3ce6ed4
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
1 changed files with 11 additions and 3 deletions

View File

@ -311,8 +311,6 @@ end
---------- Bows -----------
local bow_cooldown = {}
function throwing.register_bow(name, def)
if not string.find(name, ":") then
name = throwing.modname..":"..name
@ -341,7 +339,7 @@ function throwing.register_bow(name, def)
local index = (def.throw_itself and user:get_wield_index()) or user:get_wield_index()+1
local res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", index), index)
if not res then
return new_stack or itemstack
return (def.throw_itself and new_stack) or itemstack
end
-- Sound
@ -350,6 +348,16 @@ function throwing.register_bow(name, def)
end
minetest.after(def.delay or 0, function()
-- Re-check that the arrow can be thrown. Overwrite the new_stack
local old_new_stack = new_stack
res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", index), index)
if not new_stack then
new_stack = old_new_stack
end
if not res then
return (def.throw_itself and new_stack) or itemstack
end
-- Shoot arrow
if shoot_arrow(itemstack, user, def.throw_itself, new_stack) then
if not minetest.settings:get_bool("creative_mode") then