diff --git a/README.md b/README.md index b50e71b..9a253ca 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,12 @@ Definition: definition table, containing: * texture (essential): texture of the bow, shown in inventory. * groups (optional): groups of the item. * uses: number of uses of the bow (default is 50). - * allow_shot (optional): function(player, itemstack, index): + * allow_shot (optional): function(player, itemstack, index, last_run): - player: the player using the bow - itemstack: the itemstack of the bow + - index: index of the arrow in the inventory + - last_run: whether this is the last time this function is called before actually calling `spawn_arrow_entity`. + Currently, `allow_shot` is actually run twice (once before the delay, and once after). - should return true if the shot can be made, and false otherwise - the default function checks that the arrow to be thrown is a registered arrow - it can return a second return value, which is the new itemstack diff --git a/init.lua b/init.lua index 5418edc..2aa271e 100644 --- a/init.lua +++ b/init.lua @@ -338,7 +338,7 @@ function throwing.register_bow(name, def) local bow_index = user:get_wield_index() local arrow_index = (def.throw_itself and bow_index) or bow_index+1 - local res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", arrow_index), arrow_index) + local res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", arrow_index), arrow_index, false) if not res then return (def.throw_itself and new_stack) or itemstack end @@ -352,7 +352,7 @@ function throwing.register_bow(name, def) 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", arrow_index), arrow_index) + res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", arrow_index), arrow_index, true) if not new_stack then new_stack = old_new_stack end