I think this addresses the crash and also makes enderman more passive during the day.

This commit is contained in:
Rootyjr 2020-06-13 14:51:27 -05:00
parent a7b9107d31
commit d19bedc6d2
No known key found for this signature in database
GPG key ID: 9298653061C12F5B

View file

@ -3,7 +3,7 @@
--made for MC like Survival game --made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes --License for code WTFPL and otherwise stated in readmes
-- ENDERMAN BEHAVIOUR: -- ENDERMAN BEHAVIOUR (OLD):
-- In this game, endermen attack the player on sight, like other monsters do. -- In this game, endermen attack the player on sight, like other monsters do.
-- However, they have a reduced viewing range to make them less dangerous. -- However, they have a reduced viewing range to make them less dangerous.
-- This differs from MC, in which endermen only become hostile when provoked, -- This differs from MC, in which endermen only become hostile when provoked,
@ -262,18 +262,31 @@ mobs:register_mob("mobs_mc:enderman", {
end end
-- AGRESSIVELY WARP/CHASE PLAYER BEHAVIOUR HERE. -- AGRESSIVELY WARP/CHASE PLAYER BEHAVIOUR HERE.
if self.state == "attack" then if self.state == "attack" then
if (minetest.get_timeofday() * 24000) > 5001 and (minetest.get_timeofday() * 24000) < 19000 then
self:teleport(nil)
self.state = ""
else
if self.attack then
target = self.attack target = self.attack
if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then
self:teleport(target) self:teleport(target)
end end
end end
-- ARROW AVOIDANCE BEHAVIOUR HERE. end
-- Check for arrows nearby. end
-- ARROW / DAYTIME PEOPLE AVOIDANCE BEHAVIOUR HERE.
-- Check for arrows and people nearby.
local enderpos = self.object:get_pos() local enderpos = self.object:get_pos()
local objs = minetest.get_objects_inside_radius(enderpos, 4) local objs = minetest.get_objects_inside_radius(enderpos, 4)
for n = 1, #objs do for n = 1, #objs do
obj = objs[n] obj = objs[n]
if obj then if obj then
if minetest.is_player(obj) then
-- Warp from players during day.
if (minetest.get_timeofday() * 24000) > 5001 and (minetest.get_timeofday() * 24000) < 19000 then
self:teleport(nil)
end
else
lua = obj:get_luaentity() lua = obj:get_luaentity()
if lua then if lua then
if lua.name == "mcl_bows:arrow_entity" then if lua.name == "mcl_bows:arrow_entity" then
@ -282,12 +295,20 @@ mobs:register_mob("mobs_mc:enderman", {
end end
end end
end end
end
-- PROVOKED BEHAVIOUR HERE. -- PROVOKED BEHAVIOUR HERE.
local enderpos = self.object:get_pos() local enderpos = self.object:get_pos()
if self.provoked == "broke_contact" then if self.provoked == "broke_contact" then
self.provoked = "false" self.provoked = "false"
if (minetest.get_timeofday() * 24000) > 5001 and (minetest.get_timeofday() * 24000) < 19000 then
self:teleport(nil)
self.state = ""
else
if self.attack ~= nil then
self.state = 'attack' self.state = 'attack'
end end
end
end
-- Check to see if people are near by enough to look at us. -- Check to see if people are near by enough to look at us.
local objs = minetest.get_objects_inside_radius(enderpos, 64) local objs = minetest.get_objects_inside_radius(enderpos, 64)
for n = 1, #objs do for n = 1, #objs do
@ -477,10 +498,14 @@ mobs:register_mob("mobs_mc:enderman", {
end, end,
do_punch = function(self, hitter, tflp, tool_caps, dir) do_punch = function(self, hitter, tflp, tool_caps, dir)
-- damage from rain caused by itself so we don't want it to attack itself. -- damage from rain caused by itself so we don't want it to attack itself.
if hitter ~= self.object then if hitter ~= self.object and hitter ~= nil then
if (minetest.get_timeofday() * 24000) > 5001 and (minetest.get_timeofday() * 24000) < 19000 then
self:teleport(nil)
else
self:teleport(hitter) self:teleport(hitter)
self.state="attack"
self.attack=hitter self.attack=hitter
self.state="attack"
end
end end
end, end,
water_damage = 8, water_damage = 8,