mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-10 02:00:27 +01:00
Add a public throwing.make_arrow_def function
This commit is contained in:
parent
1be6638b56
commit
05365af715
22
init.lua
22
init.lua
@ -78,7 +78,7 @@ local function arrow_step(self, dtime)
|
|||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
local logging = function(message, level)
|
local logging = function(message, level)
|
||||||
minetest.log(level or "action", "[throwing] Arrow "..self.node.." throwed by player "..self.player.." "..tostring(self.timer).."s ago "..message)
|
minetest.log(level or "action", "[throwing] Arrow "..self.item or self.name.." throwed by player "..self.player.." "..tostring(self.timer).."s ago "..message)
|
||||||
end
|
end
|
||||||
|
|
||||||
local hit = function(pos, node, obj)
|
local hit = function(pos, node, obj)
|
||||||
@ -96,8 +96,8 @@ local function arrow_step(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function hit_failed()
|
local function hit_failed()
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") and self.item then
|
||||||
player:get_inventory():add_item("main", self.node)
|
player:get_inventory():add_item("main", self.item)
|
||||||
end
|
end
|
||||||
if self.on_hit_fails then
|
if self.on_hit_fails then
|
||||||
self.on_hit_fails(pos, player, self.data, self)
|
self.on_hit_fails(pos, player, self.data, self)
|
||||||
@ -190,6 +190,14 @@ local function arrow_step(self, dtime)
|
|||||||
self.last_pos = pos -- Used by the build arrow
|
self.last_pos = pos -- Used by the build arrow
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function throwing.make_arrow_def(def)
|
||||||
|
def.timer = 0
|
||||||
|
def.player = ""
|
||||||
|
def.on_step = arrow_step
|
||||||
|
def.data = {}
|
||||||
|
return def
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
on_hit(pos, last_pos, node, object, hitter)
|
on_hit(pos, last_pos, node, object, hitter)
|
||||||
Either node or object is nil, depending whether the arrow collided with an object (luaentity or player) or with a node.
|
Either node or object is nil, depending whether the arrow collided with an object (luaentity or player) or with a node.
|
||||||
@ -254,9 +262,8 @@ function throwing.register_arrow(name, def)
|
|||||||
}
|
}
|
||||||
minetest.register_node(name, def)
|
minetest.register_node(name, def)
|
||||||
|
|
||||||
minetest.register_entity(name.."_entity", {
|
minetest.register_entity(name.."_entity", throwing.make_arrow_def{
|
||||||
physical = false,
|
physical = false,
|
||||||
timer = 0,
|
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x = 0.125, y = 0.125},
|
visual_size = {x = 0.125, y = 0.125},
|
||||||
textures = {throwing.modname..":"..name},
|
textures = {throwing.modname..":"..name},
|
||||||
@ -268,10 +275,7 @@ function throwing.register_arrow(name, def)
|
|||||||
allow_protected = def.allow_protected,
|
allow_protected = def.allow_protected,
|
||||||
target = def.target,
|
target = def.target,
|
||||||
on_hit_fails = def.on_hit_fails,
|
on_hit_fails = def.on_hit_fails,
|
||||||
node = throwing.modname..":"..name,
|
item = name,
|
||||||
player = "",
|
|
||||||
on_step = arrow_step,
|
|
||||||
data = {}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if def.itemcraft then
|
if def.itemcraft then
|
||||||
|
Loading…
Reference in New Issue
Block a user