mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 09:40:26 +01:00
Add a spawn_arrow_entity field to the register_bow definition table
This commit is contained in:
parent
ba249807f1
commit
d7fae754f9
@ -48,6 +48,7 @@ Definition: definition table, containing:
|
|||||||
If present, allow_shot is ignored.
|
If present, allow_shot is ignored.
|
||||||
Default is false.
|
Default is false.
|
||||||
* cooldown: bow cooldown. Default is setting throwing.bow_cooldown
|
* cooldown: bow cooldown. Default is setting throwing.bow_cooldown
|
||||||
|
* function spawn_arrow_entity(position, arrow, player): defaults to throwing.spawn_arrow_entity
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Example:
|
-- Example:
|
||||||
|
27
init.lua
27
init.lua
@ -18,6 +18,20 @@ function throwing.is_arrow(itemstack)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function throwing.spawn_arrow_entity(pos, arrow, player)
|
||||||
|
if throwing.is_arrow(arrow) then
|
||||||
|
return minetest.add_entity(pos, arrow.."_entity")
|
||||||
|
elseif minetest.registered_items[arrow].throwing_entity then
|
||||||
|
if type(minetest.registered_items[arrow].throwing_entity) == "string" then
|
||||||
|
return minetest.add_entity(pos, minetest.registered_items[arrow].throwing_entity)
|
||||||
|
else -- Type is a function
|
||||||
|
return minetest.registered_items[arrow].throwing_entity(pos, player)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
obj = minetest.add_entity(pos, "__builtin:item", arrow)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function shoot_arrow(itemstack, player, throw_itself)
|
local function shoot_arrow(itemstack, player, throw_itself)
|
||||||
local inventory = player:get_inventory()
|
local inventory = player:get_inventory()
|
||||||
local arrow
|
local arrow
|
||||||
@ -29,18 +43,7 @@ local function shoot_arrow(itemstack, player, throw_itself)
|
|||||||
|
|
||||||
local playerpos = player:getpos()
|
local playerpos = player:getpos()
|
||||||
local pos = {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}
|
local pos = {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}
|
||||||
local obj
|
local obj = (minetest.registered_items[itemstack:get_name()].spawn_arrow_entity or throwing.spawn_arrow_entity)(pos, arrow, player)
|
||||||
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
|
|
||||||
|
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
luaentity.player = player:get_player_name()
|
luaentity.player = player:get_player_name()
|
||||||
|
Loading…
Reference in New Issue
Block a user