From 552b958dba7d27dc3fe8df2e2132acdb1dc5fbdc Mon Sep 17 00:00:00 2001 From: upsilon Date: Tue, 20 Jun 2017 16:39:03 +0200 Subject: [PATCH] Check for the presence of a throwing_entity field in item definition table --- README.md | 4 ++++ init.lua | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index d15f64a..1c3fe5f 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,7 @@ throwing.register_arrow("arrow", { end }) ``` + +If the item to throw is an arrow registered using `minetest.register_arrow`, the entity used will be the registered entity. +Otherwise, if its definition contains a `throwing_entity` field, this field will be used as the entity name if it is a string, otherwise it will be called as a function(pos, player) that has to make the object to spawn and to return the corresponding ObjectRef. +If the item is neither an arrow nor has any `throwing_entity` field, the corresponding `__builtin:item` will be used. diff --git a/init.lua b/init.lua index e43aba7..4c6b731 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,12 @@ local function shoot_arrow(itemstack, player) local obj if throwing.is_arrow(arrow) then obj = minetest.add_entity(pos, arrow.."_entity") + elseif minetest.registered_items[arrow].throwing_entity then + if type(minetest.registered_items[arrow].throwing_entity) == "string" then + obj = minetest.add_entity(pos, minetest.registered_items[arrow].throwing_entity) + else -- Type is a function + obj = minetest.registered_items[arrow].throwing_entity(pos, player) + end else obj = minetest.add_entity(pos, "__builtin:item", arrow) end