Fix Enderman's teleport by getting less nodes to pass PseudoRandom:next
This commit is contained in:
parent
7b9a79658d
commit
80fcffcd38
@ -468,32 +468,36 @@ mobs:register_mob("mobs_mc:enderman", {
|
|||||||
else
|
else
|
||||||
-- Attempt to randomly teleport enderman
|
-- Attempt to randomly teleport enderman
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
-- Find all solid nodes below air in a 65×65×65 cuboid centered on the enderman
|
-- Up to 8 top-level attempts to teleport
|
||||||
local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(pos, 32), vector.add(pos, 32), {"group:solid", "group:cracky", "group:crumbly"})
|
for n=1, 8 do
|
||||||
local telepos
|
local node_ok = false
|
||||||
if nodes ~= nil then
|
-- We need to add (or subtract) different random numbers to each vector component, so it couldn't be done with a nice single vector.add() or .subtract():
|
||||||
if #nodes > 0 then
|
local randomCube = vector.new( pos.x + 8*(pr:next(0,16)-8), pos.y + 8*(pr:next(0,16)-8), pos.z + 8*(pr:next(0,16)-8) )
|
||||||
-- Up to 64 attempts to teleport
|
local nodes = minetest.find_nodes_in_area_under_air(vector.subtract(randomCube, 4), vector.add(randomCube, 4), {"group:solid", "group:cracky", "group:crumbly"})
|
||||||
for n=1, math.min(64, #nodes) do
|
if nodes ~= nil then
|
||||||
local r = pr:next(1, #nodes)
|
if #nodes > 0 then
|
||||||
local nodepos = nodes[r]
|
-- Up to 8 low-level (in total up to 8*8 = 64) attempts to teleport
|
||||||
local node_ok = true
|
for n=1, math.min(8, #nodes) do
|
||||||
-- Selected node needs to have 3 nodes of free space above
|
local r = pr:next(1, #nodes)
|
||||||
for u=1, 3 do
|
local nodepos = nodes[r]
|
||||||
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
|
node_ok = true
|
||||||
if minetest.registered_nodes[node.name].walkable then
|
for u=1, 3 do
|
||||||
node_ok = false
|
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
|
||||||
|
if minetest.registered_nodes[node.name].walkable then
|
||||||
|
node_ok = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if node_ok then
|
||||||
|
self.object:set_pos({x=nodepos.x, y=nodepos.y+1, z=nodepos.z})
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if node_ok then
|
|
||||||
telepos = {x=nodepos.x, y=nodepos.y+1, z=nodepos.z}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if telepos then
|
|
||||||
self.object:set_pos(telepos)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if node_ok then
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
Loading…
Reference in New Issue
Block a user