1
0
Fork 0

Fix insane enderman 64 node radius check for players

formspec-v4
jordan4ibanez 2021-04-06 20:24:46 -04:00
parent 8e2493dd9a
commit 00db03320b
1 changed files with 22 additions and 29 deletions

View File

@ -328,37 +328,30 @@ mobs:register_mob("mobs_mc:enderman", {
--end
end
-- Check to see if people are near by enough to look at us.
local objs = minetest.get_objects_inside_radius(enderpos, 64)
local obj
for n = 1, #objs do
obj = objs[n]
if obj then
if minetest.is_player(obj) then
-- Check if they are looking at us.
local player_pos = obj:get_pos()
local look_dir_not_normalized = obj:get_look_dir()
local look_dir = vector.normalize(look_dir_not_normalized)
local look_pos = vector.new({x = look_dir.x+player_pos.x, y = look_dir.y+player_pos.y + 1.5, z = look_dir.z+player_pos.z}) -- Arbitrary value (1.5) is head level according to player info mod.
-- Cast up to 64 to see if player is looking at enderman.
for n = 1,64,.25 do
local node = minetest.get_node(look_pos)
if node.name ~= "air" then
break
end
if look_pos.x-1<enderpos.x and look_pos.x+1>enderpos.x and look_pos.y-2.89<enderpos.y and look_pos.y-2>enderpos.y and look_pos.z-1<enderpos.z and look_pos.z+1>enderpos.z then
self.provoked = "staring"
self.attack = minetest.get_player_by_name(obj:get_player_name())
break
else
if self.provoked == "staring" then
self.provoked = "broke_contact"
end
end
look_pos.x = look_pos.x + (.25 * look_dir.x)
look_pos.y = look_pos.y + (.25 * look_dir.y)
look_pos.z = look_pos.z + (.25 * look_dir.z)
for _,obj in pairs(minetest.get_connected_players()) do
-- Check if they are looking at us.
local player_pos = obj:get_pos()
local look_dir_not_normalized = obj:get_look_dir()
local look_dir = vector.normalize(look_dir_not_normalized)
local look_pos = vector.new({x = look_dir.x+player_pos.x, y = look_dir.y+player_pos.y + 1.5, z = look_dir.z+player_pos.z}) -- Arbitrary value (1.5) is head level according to player info mod.
-- Cast up to 64 to see if player is looking at enderman.
for n = 1,64,.25 do
local node = minetest.get_node(look_pos)
if node.name ~= "air" then
break
end
if look_pos.x-1<enderpos.x and look_pos.x+1>enderpos.x and look_pos.y-2.89<enderpos.y and look_pos.y-2>enderpos.y and look_pos.z-1<enderpos.z and look_pos.z+1>enderpos.z then
self.provoked = "staring"
self.attack = minetest.get_player_by_name(obj:get_player_name())
break
else
if self.provoked == "staring" then
self.provoked = "broke_contact"
end
end
look_pos.x = look_pos.x + (.25 * look_dir.x)
look_pos.y = look_pos.y + (.25 * look_dir.y)
look_pos.z = look_pos.z + (.25 * look_dir.z)
end
end
-- TAKE AND PLACE STUFF BEHAVIOUR BELOW.