From 4fb9e69e41a8c2ee91c659acb0b11fc76a6a97fe Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 13:27:17 -0400 Subject: [PATCH] Make enderman become hostile when stared at, freeze when attacking when stared at --- mods/ENTITIES/mcl_mobs/api/api.lua | 2 +- mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua | 11 +++++++++++ .../api/mob_functions/attack_type_instructions.lua | 5 +++++ .../mcl_mobs/api/mob_functions/backup_code_api.lua | 8 +------- .../mcl_mobs/api/mob_functions/environment.lua | 10 ++++++++++ mods/ENTITIES/mobs_mc/enderman.lua | 10 ++++++++-- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index fc153a5fe1..96d479b3ff 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -332,7 +332,7 @@ function mobs:register_mob(name, def) --end j4i stuff -- MCL2 extensions - teleport = teleport, + teleport = mobs.teleport, do_teleport = def.do_teleport, spawn_class = def.spawn_class, ignores_nametag = def.ignores_nametag or false, diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index e883a36702..f9f886edcd 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -667,6 +667,17 @@ mobs.mob_step = function(self, dtime) return end + + --do custom mob instructions + if self.do_custom then + print("doing custom instructions") + -- when false skip going any further + if self.do_custom(self, dtime) == false then + --this overrides internal lua collision detection + return + end + end + local attacking = nil --scan for players within eyesight diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua index e60c46aab1..ac5561adbf 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -134,6 +134,11 @@ mobs.punch_attack_walk = function(self,dtime) end + --auto reset punch_timer + if not self.punch_timer then + self.punch_timer = 0 + end + if self.punch_timer > 0 then self.punch_timer = self.punch_timer - dtime end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua index a6d27040e0..528f2b70e9 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua @@ -309,13 +309,7 @@ local falling = function(self, pos) end end -local teleport = function(self, target) - if self.do_teleport then - if self.do_teleport(self, target) == false then - return - end - end -end + -- find someone to runaway from diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua index 41fc4b248e..f81cba6fc9 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -204,4 +204,14 @@ mobs.node_ok = function(pos, fallback) end return minetest_registered_nodes[fallback] +end + + +--a teleport functoin +mobs.teleport = function(self, target) + if self.do_teleport then + if self.do_teleport(self, target) == false then + return + end + end end \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index 158f05c367..6a47e92961 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -204,6 +204,7 @@ mobs:register_mob("mobs_mc:enderman", { textures = create_enderman_textures(), visual_size = {x=3, y=3}, makes_footstep_sound = true, + eye_height = 2.5, sounds = { -- TODO: Custom war cry sound war_cry = "mobs_sandmonster", @@ -359,11 +360,16 @@ mobs:register_mob("mobs_mc:enderman", { --if looking in general head position, turn hostile if minetest.line_of_sight(ender_eye_pos, look_pos_base) and vector.distance(look_pos, ender_eye_pos) <= 0.4 then self.provoked = "staring" - self.attack = minetest.get_player_by_name(obj:get_player_name()) + self.state = "stand" + self.hostile = false break - else -- I'm not sure what this part does, but I don't want to break anything - jordan4ibanez + --begin attacking the player + else if self.provoked == "staring" then self.provoked = "broke_contact" + self.hostile = true + self.state = "attack" + self.attacking = obj end end