mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-10 02:00:27 +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()
|
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)
|
local player = minetest.get_player_by_name(self.player)
|
||||||
if not player then -- Possible if the player disconnected
|
if not player then -- Possible if the player disconnected
|
||||||
return
|
return
|
||||||
end
|
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)
|
local ret, reason = self.on_hit(pos, self.last_pos, node, obj, player)
|
||||||
if ret == false then
|
if ret == false then
|
||||||
if reason then
|
if reason then
|
||||||
@ -66,9 +79,8 @@ local function arrow_step(self, dtime)
|
|||||||
logging(": on_hit function failed", "warning")
|
logging(": on_hit function failed", "warning")
|
||||||
end
|
end
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
put_arrow_back()
|
||||||
player:get_inventory():add_item("main", self.node)
|
return
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.on_hit_sound then
|
if self.on_hit_sound then
|
||||||
|
Loading…
Reference in New Issue
Block a user