diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index eedb038fb..71cedf0b8 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -61,6 +61,13 @@ if minetest.settings:get_bool("only_peaceful_mobs", false) then end) end + +local function dir_to_pitch(dir) + --local dir2 = vector.normalize(dir) + local xz = math.abs(dir.x) + math.abs(dir.z) + return -math.atan2(-dir.y, xz) +end + -- pathfinding settings local enable_pathfinding = true local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching @@ -3706,6 +3713,60 @@ local mob_step = function(self, dtime) -- end rotation + if self.head_swivel and type(self.head_swivel) == "string" then + local oldp,oldr = self.object:get_bone_position(self.head_swivel) + + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 10)) do + if obj:is_player() and not self.attack then + if not self._locked_object then + if math.random(50/self.curiosity) == 1 then + self._locked_object = obj + end + else + if math.random(200*self.curiosity) == 1 then + self._locked_object = nil + end + end + end + end + + if self.attack then + self._locked_object = self.attack + end + + if self._locked_object and (self._locked_object:is_player() or self._locked_object:get_luaentity()) and self._locked_object:get_hp() > 0 then + local _locked_object_eye_height = 1.5 + if self._locked_object:is_player() then + _locked_object_eye_height = self._locked_object:get_properties().eye_height + end + local self_rot = self.object:get_rotation() + local player_pos = self._locked_object:get_pos() + local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0))) + local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))--+self.head_yaw_offset + local mob_pitch = math.deg(-dir_to_pitch(direction_player)) + if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.type == "monster") then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9)) + elseif self.attack and self.type == "monster" then + if self.head_yaw == "y" then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, mob_yaw, 0)) + elseif self.head_yaw == "z" then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, 0, -mob_yaw)) + end + else + if self.head_yaw == "y" then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0)) + elseif self.head_yaw == "z" then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3)) + end + end + elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9)) + else + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(0,0,0)) + end + + end + -- run custom function (defined in mob lua file) if self.do_custom then @@ -3946,6 +4007,13 @@ end minetest.register_entity(name, { use_texture_alpha = def.use_texture_alpha, + head_swivel = def.head_swivel or nil, -- bool to activate this function + head_yaw_offset = def.head_yaw_offset or 0, -- for wonkey model bones + bone_eye_height = def.bone_eye_height or 1.4, -- head bone offset + head_eye_height = def.head_eye_height or def.bone_eye_height or 0, -- how hight aproximatly the mobs head is fromm the ground to tell the mob how high to look up at the player + curiosity = def.curiosity or 1, -- how often mob will look at player on idle + head_yaw = def.head_yaw or "y", -- axis to rotate head on + horrizonatal_head_height = def.horrizonatal_head_height or 0, stepheight = def.stepheight or 0.6, name = name, description = def.description, diff --git a/mods/ENTITIES/mobs_mc/chicken.lua b/mods/ENTITIES/mobs_mc/chicken.lua index 17d34f11d..a75f2b12a 100644 --- a/mods/ENTITIES/mobs_mc/chicken.lua +++ b/mods/ENTITIES/mobs_mc/chicken.lua @@ -20,6 +20,12 @@ mcl_mobs:register_mob("mobs_mc:chicken", { collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2}, runaway = true, floats = 1, + head_swivel = "Head_Control", + bone_eye_height = 1.8, + head_eye_height = 1.5, + curiosity = 10, + head_yaw="z", + visual_size = {x=3,y=3}, visual = "mesh", mesh = "mobs_mc_chicken.b3d", textures = { diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index cee8c2248..9cd22b798 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -17,6 +17,12 @@ local cow_def = { "mobs_mc_cow.png", "blank.png", }, }, + head_swivel = "Head_Control", + bone_eye_height = 3.4, + head_eye_height = 1.1, + horrizonatal_head_height=-.7, + curiosity = 2, + head_yaw="z", makes_footstep_sound = true, walk_velocity = 1, drops = { diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 16291f9fa..2ee943124 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -21,6 +21,9 @@ mcl_mobs:register_mob("mobs_mc:creeper", { pathfinding = 1, visual = "mesh", mesh = "mobs_mc_creeper.b3d", + head_swivel = "Head_Control", + bone_eye_height = 2.35, + curiosity = 2, textures = { {"mobs_mc_creeper.png", "mobs_mc_empty.png"}, diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d index 62fabd743..d3f6cbd28 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_cow.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_cow.b3d index f29c6a961..f60e9a6ab 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_cow.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_cow.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_creeper.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_creeper.b3d index e04ffc7b0..72887d8d4 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_creeper.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_creeper.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_pig.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_pig.b3d index 4bbaf6e23..30d3c5264 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_pig.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_pig.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_sheepfur.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_sheepfur.b3d index 7ee15fb55..dd4b74fdf 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_sheepfur.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_sheepfur.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_skeleton.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_skeleton.b3d index aa1681dbe..f4ff18e25 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_skeleton.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_skeleton.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_spider.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_spider.b3d index aec461a6b..c77d36cf3 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_spider.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_spider.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d index 1d46a162b..529f9fa62 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_villager_zombie.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_villager_zombie.b3d index b7dd9d7ee..a45eac602 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_villager_zombie.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_villager_zombie.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_wolf.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_wolf.b3d index 82684e303..606f10b94 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_wolf.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_wolf.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie.b3d index 1da2bc66b..b3b588ffa 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie.b3d differ diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 96e073ebe..f847e3446 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -18,6 +18,12 @@ mcl_mobs:register_mob("mobs_mc:pig", { "mobs_mc_pig.png", -- base "blank.png", -- saddle }}, + head_swivel = "Head_Control", + bone_eye_height = 2.9, + head_eye_height = 0.8, + horrizonatal_head_height=-.4, + curiosity = 3, + head_yaw="z", makes_footstep_sound = true, walk_velocity = 1, run_velocity = 3, diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index d2bab09d4..cb45242ef 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -61,7 +61,12 @@ mcl_mobs:register_mob("mobs_mc:sheep", { xp_min = 1, xp_max = 3, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45}, - + head_swivel = "Head_Control", + bone_eye_height = 3.3, + head_eye_height = 1.1, + horrizonatal_head_height=-.7, + curiosity = 6, + head_yaw="z", visual = "mesh", mesh = "mobs_mc_sheepfur.b3d", textures = { sheep_texture("unicolor_white") }, diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index 011ddf9c4..46b6ed9ce 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -25,6 +25,9 @@ local skeleton = { collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.98, 0.3}, pathfinding = 1, group_attack = true, + head_swivel = "Head_Control", + bone_eye_height = 2.35, + curiosity = .1, visual = "mesh", mesh = "mobs_mc_skeleton.b3d", textures = { { diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index 751937f89..9a0f49395 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -55,6 +55,10 @@ local spider = { minetest.add_entity(self.object:get_pos(), "mobs_mc:spider_eyes"):set_attach(self.object, "body.head", vector.new(0,-0.98,2), vector.new(90,180,180)) end end, + head_swivel = "Head_Control", + bone_eye_height = 1, + curiosity = 10, + head_yaw="z", collisionbox = {-0.7, -0.01, -0.7, 0.7, 0.89, 0.7}, visual = "mesh", mesh = "mobs_mc_spider.b3d", diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 7e4ca72ad..98e2bd9b0 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1235,6 +1235,9 @@ mcl_mobs:register_mob("mobs_mc:villager", { spawn_class = "passive", hp_min = 20, hp_max = 20, + head_swivel = "Head_Control", + bone_eye_height = 2.35, + curiosity = 10, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, visual = "mesh", mesh = "mobs_mc_villager.b3d", diff --git a/mods/ENTITIES/mobs_mc/villager_zombie.lua b/mods/ENTITIES/mobs_mc/villager_zombie.lua index 1e0259704..d0f4acd14 100644 --- a/mods/ENTITIES/mobs_mc/villager_zombie.lua +++ b/mods/ENTITIES/mobs_mc/villager_zombie.lua @@ -39,13 +39,16 @@ mcl_mobs:register_mob("mobs_mc:villager_zombie", { collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, visual = "mesh", mesh = "mobs_mc_villager_zombie.b3d", + head_swivel = "Head_Control", + bone_eye_height = 2.35, + curiosity = 2, textures = { - {"mobs_mc_empty.png", "mobs_mc_zombie_butcher.png", "mobs_mc_empty.png"}, - {"mobs_mc_empty.png", "mobs_mc_zombie_farmer.png", "mobs_mc_empty.png"}, - {"mobs_mc_empty.png", "mobs_mc_zombie_librarian.png", "mobs_mc_empty.png"}, - {"mobs_mc_empty.png", "mobs_mc_zombie_priest.png", "mobs_mc_empty.png"}, - {"mobs_mc_empty.png", "mobs_mc_zombie_smith.png", "mobs_mc_empty.png"}, - {"mobs_mc_empty.png", "mobs_mc_zombie_villager.png", "mobs_mc_empty.png"}, + {"mobs_mc_zombie_butcher.png"}, + {"mobs_mc_zombie_farmer.png"}, + {"mobs_mc_zombie_librarian.png"}, + {"mobs_mc_zombie_priest.png"}, + {"mobs_mc_zombie_smith.png"}, + {"mobs_mc_zombie_villager.png"}, }, visual_size = {x=2.75, y=2.75}, makes_footstep_sound = true, diff --git a/mods/ENTITIES/mobs_mc/wolf.lua b/mods/ENTITIES/mobs_mc/wolf.lua index 1436a2844..5013d67dd 100644 --- a/mods/ENTITIES/mobs_mc/wolf.lua +++ b/mods/ENTITIES/mobs_mc/wolf.lua @@ -26,6 +26,12 @@ local wolf = { {"mobs_mc_wolf.png"}, }, makes_footstep_sound = true, + head_swivel = "Head_Control", + bone_eye_height = 1.2, + head_eye_height = 1.1, + horrizonatal_head_height=0, + curiosity = 10, + head_yaw="z", sounds = { attack = "mobs_mc_wolf_bark", war_cry = "mobs_mc_wolf_growl", diff --git a/mods/ENTITIES/mobs_mc/zombie.lua b/mods/ENTITIES/mobs_mc/zombie.lua index 2a1efe83e..0858fb3ec 100644 --- a/mods/ENTITIES/mobs_mc/zombie.lua +++ b/mods/ENTITIES/mobs_mc/zombie.lua @@ -60,9 +60,8 @@ local zombie = { mesh = "mobs_mc_zombie.b3d", textures = { { - "mobs_mc_empty.png", -- armor "mobs_mc_zombie.png", -- texture - "mobs_mc_empty.png", -- wielded_item + "mobs_mc_empty.png", -- armor } }, makes_footstep_sound = true, @@ -127,9 +126,8 @@ local husk = table.copy(zombie) husk.description = S("Husk") husk.textures = { { - "mobs_mc_empty.png", -- armor "mobs_mc_husk.png", -- texture - "mobs_mc_empty.png", -- wielded_item + "mobs_mc_empty.png", -- armor } } husk.ignited_by_sunlight = false @@ -144,7 +142,6 @@ mcl_mobs:register_mob("mobs_mc:husk", husk) local baby_husk = table.copy(baby_zombie) baby_husk.description = S("Baby Husk") baby_husk.textures = {{ - "mobs_mc_empty.png", -- armor "mobs_mc_husk.png", -- texture "mobs_mc_empty.png", -- wielded_item }}