mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 09:40:26 +01:00
Crashfix: avoid last_pos to be nil when calling the on_hit function
should fix https://github.com/Mynetest/Mynetest-server/issues/64
This commit is contained in:
parent
8a27df9c24
commit
ad966cf06d
26
init.lua
26
init.lua
@ -50,14 +50,27 @@ local function arrow_step(self, dtime)
|
||||
|
||||
self.object:remove()
|
||||
|
||||
if node and minetest.is_protected(pos, self.player) then -- Forbid hitting nodes in protected areas
|
||||
return
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(self.player)
|
||||
if not player then -- Possible if the player disconnected
|
||||
return
|
||||
end
|
||||
|
||||
local function put_arrow_back()
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
player:get_inventory():add_item("main", self.node)
|
||||
end
|
||||
end
|
||||
|
||||
if not self.last_pos then
|
||||
logging(" hitted a node during its first call to the step function", "warning")
|
||||
put_arrow_back()
|
||||
return
|
||||
end
|
||||
|
||||
if node and minetest.is_protected(pos, self.player) then -- Forbid hitting nodes in protected areas
|
||||
return
|
||||
end
|
||||
|
||||
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player)
|
||||
if ret == false then
|
||||
if reason then
|
||||
@ -66,9 +79,8 @@ local function arrow_step(self, dtime)
|
||||
logging(": on_hit function failed", "warning")
|
||||
end
|
||||
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
player:get_inventory():add_item("main", self.node)
|
||||
end
|
||||
put_arrow_back()
|
||||
return
|
||||
end
|
||||
|
||||
if self.on_hit_sound then
|
||||
|
Loading…
Reference in New Issue
Block a user