mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
Add some sanity checks to fishing bobber
This commit is contained in:
parent
fd089b2470
commit
f6f259dce0
1 changed files with 20 additions and 5 deletions
|
@ -14,6 +14,7 @@ local bobber_ENTITY={
|
||||||
visual_size = {x=0.5, y=0.5},
|
visual_size = {x=0.5, y=0.5},
|
||||||
collisionbox = {0.45,0.45,0.45,0.45,0.45,0.45},
|
collisionbox = {0.45,0.45,0.45,0.45,0.45,0.45},
|
||||||
pointable = false,
|
pointable = false,
|
||||||
|
static_save = false,
|
||||||
|
|
||||||
_lastpos={},
|
_lastpos={},
|
||||||
_dive = false,
|
_dive = false,
|
||||||
|
@ -158,33 +159,47 @@ local bobber_on_step = function(self, dtime)
|
||||||
local node = minetest.get_node(epos)
|
local node = minetest.get_node(epos)
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
|
||||||
--If we have no player remove self.
|
--If we have no player, remove self.
|
||||||
if self.player == nil then
|
if self.player == nil or self.player == "" then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local player = minetest.get_player_by_name(self.player)
|
||||||
|
if not player then
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--Check if player is nearby
|
--Check if player is nearby
|
||||||
if self._tick % 5 == 0 and self.player ~= nil then
|
if self._tick % 5 == 0 and self.player ~= nil and player ~= nil then
|
||||||
--Destroy bobber if item not wielded.
|
--Destroy bobber if item not wielded.
|
||||||
if (minetest.get_player_by_name(self.player):get_wielded_item():get_name() ~= "mcl_fishing:fishing_rod") then
|
local wield = player:get_wielded_item()
|
||||||
|
if ((not wield) or (wield:get_name() ~= "mcl_fishing:fishing_rod")) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--Destroy bobber if player is too far away.
|
--Destroy bobber if player is too far away.
|
||||||
local objpos = self.object:get_pos()
|
local objpos = self.object:get_pos()
|
||||||
local playerpos = minetest.get_player_by_name(self.player):get_pos()
|
local playerpos = player:get_pos()
|
||||||
if (((playerpos.y - objpos.y) >= 33) or ((playerpos.y - objpos.y) <= -33)) then
|
if (((playerpos.y - objpos.y) >= 33) or ((playerpos.y - objpos.y) <= -33)) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif (((playerpos.x - objpos.x) >= 33) or ((playerpos.x - objpos.x) <= -33)) then
|
elseif (((playerpos.x - objpos.x) >= 33) or ((playerpos.x - objpos.x) <= -33)) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif (((playerpos.z - objpos.z) >= 33) or ((playerpos.z - objpos.z) <= -33)) then
|
elseif (((playerpos.z - objpos.z) >= 33) or ((playerpos.z - objpos.z) <= -33)) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif ((((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) >= 33) or ((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) <= -33) then
|
elseif ((((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) >= 33) or ((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) <= -33) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif ((((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) >= 33) or ((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) <= -33) then
|
elseif ((((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) >= 33) or ((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) <= -33) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif ((((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) >= 33) or ((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) <= -33) then
|
elseif ((((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) >= 33) or ((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) <= -33) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue