Attempt to fix more crash errors.

This commit is contained in:
Rootyjr 2020-06-16 23:59:16 -05:00
parent d19bedc6d2
commit 7b9a79658d
No known key found for this signature in database
GPG Key ID: 9298653061C12F5B

View File

@ -268,8 +268,11 @@ mobs:register_mob("mobs_mc:enderman", {
else else
if self.attack then if self.attack then
target = self.attack target = self.attack
if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then pos = target:get_pos()
self:teleport(target) if pos ~= nil then
if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then
self:teleport(target)
end
end end
end end
end end
@ -438,27 +441,29 @@ mobs:register_mob("mobs_mc:enderman", {
-- Find all solid nodes below air in a 10×10×10 cuboid centered on the target -- Find all solid nodes below air in a 10×10×10 cuboid centered on the target
local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(target_pos, 5), vector.add(target_pos, 5), {"group:solid", "group:cracky", "group:crumbly"}) local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(target_pos, 5), vector.add(target_pos, 5), {"group:solid", "group:cracky", "group:crumbly"})
local telepos local telepos
if #nodes > 0 then if nodes ~= nil then
-- Up to 64 attempts to teleport if #nodes > 0 then
for n=1, math.min(64, #nodes) do -- Up to 64 attempts to teleport
local r = pr:next(1, #nodes) for n=1, math.min(64, #nodes) do
local nodepos = nodes[r] local r = pr:next(1, #nodes)
local node_ok = true local nodepos = nodes[r]
-- Selected node needs to have 3 nodes of free space above local node_ok = true
for u=1, 3 do -- Selected node needs to have 3 nodes of free space above
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z}) for u=1, 3 do
if minetest.registered_nodes[node.name].walkable then local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
node_ok = false if minetest.registered_nodes[node.name].walkable then
break node_ok = false
break
end
end
if node_ok then
telepos = {x=nodepos.x, y=nodepos.y+1, z=nodepos.z}
end end
end end
if node_ok then if telepos then
telepos = {x=nodepos.x, y=nodepos.y+1, z=nodepos.z} self.object:set_pos(telepos)
end end
end end
if telepos then
self.object:set_pos(telepos)
end
end end
else else
-- Attempt to randomly teleport enderman -- Attempt to randomly teleport enderman
@ -466,27 +471,29 @@ mobs:register_mob("mobs_mc:enderman", {
-- Find all solid nodes below air in a 65×65×65 cuboid centered on the enderman -- Find all solid nodes below air in a 65×65×65 cuboid centered on the enderman
local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(pos, 32), vector.add(pos, 32), {"group:solid", "group:cracky", "group:crumbly"}) local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(pos, 32), vector.add(pos, 32), {"group:solid", "group:cracky", "group:crumbly"})
local telepos local telepos
if #nodes > 0 then if nodes ~= nil then
-- Up to 64 attempts to teleport if #nodes > 0 then
for n=1, math.min(64, #nodes) do -- Up to 64 attempts to teleport
local r = pr:next(1, #nodes) for n=1, math.min(64, #nodes) do
local nodepos = nodes[r] local r = pr:next(1, #nodes)
local node_ok = true local nodepos = nodes[r]
-- Selected node needs to have 3 nodes of free space above local node_ok = true
for u=1, 3 do -- Selected node needs to have 3 nodes of free space above
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z}) for u=1, 3 do
if minetest.registered_nodes[node.name].walkable then local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
node_ok = false if minetest.registered_nodes[node.name].walkable then
break node_ok = false
break
end
end
if node_ok then
telepos = {x=nodepos.x, y=nodepos.y+1, z=nodepos.z}
end end
end end
if node_ok then if telepos then
telepos = {x=nodepos.x, y=nodepos.y+1, z=nodepos.z} self.object:set_pos(telepos)
end end
end end
if telepos then
self.object:set_pos(telepos)
end
end end
end end
end, end,