diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index a179d53e6..9f68434ac 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -610,3 +610,95 @@ function mcl_util.get_pointed_thing(player, liquid) end end end + +-- This following part is 2 wrapper functions + helpers for +-- object:set_bones +-- and player:set_properties preventing them from being resent on +-- every globalstep when they have not changed. + +local function roundN(n, d) + if type(n) ~= "number" then return n end + local m = 10^d + return math.floor(n * m + 0.5) / m +end + +local function close_enough(a,b) + local rt=true + if type(a) == "table" and type(b) == "table" then + for k,v in pairs(a) do + if roundN(v,2) ~= roundN(b[k],2) then + rt=false + break + end + end + else + rt = roundN(a,2) == roundN(b,2) + end + return rt +end + +local function props_changed(props,oldprops) + local changed=false + local p={} + for k,v in pairs(props) do + if not close_enough(v,oldprops[k]) then + p[k]=v + changed=true + end + end + return changed,p +end + +--tests for roundN +local test_round1=15 +local test_round2=15.00199999999 +local test_round3=15.00111111 +local test_round4=15.00999999 + +assert(roundN(test_round1,2)==roundN(test_round1,2)) +assert(roundN(test_round1,2)==roundN(test_round2,2)) +assert(roundN(test_round1,2)==roundN(test_round3,2)) +assert(roundN(test_round1,2)~=roundN(test_round4,2)) + +-- tests for close_enough +local test_cb = {-0.35,0,-0.35,0.35,0.8,0.35} --collisionboxes +local test_cb_close = {-0.351213,0,-0.35,0.35,0.8,0.351212} +local test_cb_diff = {-0.35,0,-1.35,0.35,0.8,0.35} + +local test_eh = 1.65 --eye height +local test_eh_close = 1.65123123 +local test_eh_diff = 1.35 + +local test_nt = { r = 225, b = 225, a = 225, g = 225 } --nametag +local test_nt_diff = { r = 225, b = 225, a = 0, g = 225 } + +assert(close_enough(test_cb,test_cb_close)) +assert(not close_enough(test_cb,test_cb_diff)) +assert(close_enough(test_eh,test_eh_close)) +assert(not close_enough(test_eh,test_eh_diff)) +assert(not close_enough(test_nt,test_nt_diff)) --no floats involved here + +--tests for properties_changed +local test_properties_set1={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }} +local test_properties_set2={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 1.35, nametag_color = { r = 225, b = 225, a = 225, g = 225 }} + +local test_p1,_=props_changed(test_properties_set1,test_properties_set1) +local test_p2,_=props_changed(test_properties_set1,test_properties_set2) + +assert(not test_p1) +assert(test_p2) + +function mcl_util.set_properties(obj,props) + local changed,p=props_changed(props,obj:get_properties()) + if changed then + obj:set_properties(p) + end +end + +function mcl_util.set_bone_position(obj,b,p,r) --bone,position,rotation + local oldp,oldr=obj:get_bone_position(b) + if vector.equals(vector.round(oldp),vector.round(p)) and vector.equals(vector.round(oldr),vector.round(r)) then + return + end + obj:set_bone_position(b,p,r) +end diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index eedb038fb..3fd374fd6 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,63 @@ 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 or obj:get_luaentity() and obj:get_luaentity().name == self.name and self ~= obj:get_luaentity() then + if not self._locked_object then + if math.random(5000/self.curiosity) == 1 then + self._locked_object = obj + end + else + if math.random(10000/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:get_luaentity() then + _locked_object_eye_height = self._locked_object:get_luaentity().head_eye_height + end + 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))*self.head_pitch_multiplier + if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.type == "monster") then + mcl_util.set_bone_position(self.object,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 + mcl_util.set_bone_position(self.object,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 + mcl_util.set_bone_position(self.object,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 + mcl_util.set_bone_position(self.object,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 + mcl_util.set_bone_position(self.object,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 + mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9)) + else + mcl_util.set_bone_position(self.object,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 +4010,14 @@ 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 + head_pitch_multiplier = def.head_pitch_multiplier or 1, --for inverted pitch + 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/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 4a2156cc1..b94bc656e 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -26,6 +26,12 @@ mcl_mobs:register_mob("mobs_mc:blaze", { rotate = -180, visual = "mesh", mesh = "mobs_mc_blaze.b3d", + head_swivel = "head.control", + bone_eye_height = 4, + head_eye_height = 3.5, + curiosity = 10, + head_yaw_offset = 180, + head_pitch_multiplier=-1, textures = { {"mobs_mc_blaze.png"}, }, diff --git a/mods/ENTITIES/mobs_mc/chicken.lua b/mods/ENTITIES/mobs_mc/chicken.lua index 17d34f11d..034cb89db 100644 --- a/mods/ENTITIES/mobs_mc/chicken.lua +++ b/mods/ENTITIES/mobs_mc/chicken.lua @@ -20,6 +20,13 @@ 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 = 4, + head_eye_height = 1.5, + horrizonatal_head_height = -.3, + curiosity = 10, + head_yaw="z", + visual_size = {x=1,y=1}, 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..f1d1da46e 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 = 10, + head_eye_height = 1.1, + horrizonatal_head_height=-1.8, + 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/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index c6dfece02..c5923d4df 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -263,8 +263,8 @@ mcl_mobs:register_mob("mobs_mc:enderman", { end end if not spider_eyes then - minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.low", vector.new(0,3.25,-1.98), vector.new(90,0,180)) - minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.low", vector.new(1,3.25,-1.98), vector.new(90,0,180)) + minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.top", vector.new(0,2.54,-1.99), vector.new(90,0,180)) + minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.top", vector.new(1,2.54,-1.99), vector.new(90,0,180)) end end, sounds = { diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 243db7c12..9f5a049b7 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -22,6 +22,9 @@ mcl_mobs:register_mob("mobs_mc:iron_golem", { collisionbox = {-0.7, -0.01, -0.7, 0.7, 2.69, 0.7}, visual = "mesh", mesh = "mobs_mc_iron_golem.b3d", + head_swivel = "head.control", + bone_eye_height = 3.38, + curiosity = 10, textures = { {"mobs_mc_iron_golem.png"}, }, diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index c050375ad..dc3d4aca0 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -58,6 +58,14 @@ mcl_mobs:register_mob("mobs_mc:llama", { shoot_offset = 1, --3.5 *would* be a good value visually but it somehow messes with the projectiles trajectory spawn_in_group_min = 4, spawn_in_group = 6, + + head_swivel = "head.control", + bone_eye_height = 11, + head_eye_height = 3, + horrizonatal_head_height=0, + curiosity = 60, + head_yaw = "z", + hp_min = 15, hp_max = 30, xp_min = 1, diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_blaze.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_blaze.b3d index 2328c8a64..7593baa2f 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_blaze.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_blaze.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_chicken.b3d index 62fabd743..623a467b9 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_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_evoker.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_evoker.b3d index 6e1017e0c..4a429f7c3 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_evoker.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_evoker.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_illusioner.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_illusioner.b3d index 7bb719ffb..6bdcbf339 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_illusioner.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_illusioner.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_iron_golem.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_iron_golem.b3d index a7fbd352b..db87e6540 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_iron_golem.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_iron_golem.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_llama.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_llama.b3d index 72f503b33..8e1da8b24 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_llama.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_llama.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_parrot.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_parrot.b3d index 7cb326d3d..2f59c313b 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_parrot.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_parrot.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_polarbear.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_polarbear.b3d index bb64b2b79..cbda1f8c9 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_polarbear.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_polarbear.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_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_vindicator.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_vindicator.b3d index ae14e8edb..d220e895c 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_vindicator.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_vindicator.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_witherskeleton.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_witherskeleton.b3d index c1b808307..ec2952cf5 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_witherskeleton.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_witherskeleton.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie_pigman.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie_pigman.b3d index 0b9f4f7c9..7fb31e388 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie_pigman.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_zombie_pigman.b3d differ diff --git a/mods/ENTITIES/mobs_mc/ocelot.lua b/mods/ENTITIES/mobs_mc/ocelot.lua index 6c2d6cd20..574b5e763 100644 --- a/mods/ENTITIES/mobs_mc/ocelot.lua +++ b/mods/ENTITIES/mobs_mc/ocelot.lua @@ -36,6 +36,12 @@ local ocelot = { hp_max = 10, xp_min = 1, xp_max = 3, + head_swivel = "head.control", + bone_eye_height = 6.2, + head_eye_height = 0.4, + horrizonatal_head_height=-0, + head_yaw="z", + curiosity = 4, collisionbox = {-0.3, -0.01, -0.3, 0.3, 0.69, 0.3}, visual = "mesh", mesh = "mobs_mc_cat.b3d", diff --git a/mods/ENTITIES/mobs_mc/parrot.lua b/mods/ENTITIES/mobs_mc/parrot.lua index f33a5015d..52bb77280 100644 --- a/mods/ENTITIES/mobs_mc/parrot.lua +++ b/mods/ENTITIES/mobs_mc/parrot.lua @@ -135,6 +135,10 @@ mcl_mobs:register_mob("mobs_mc:parrot", { hp_max = 6, xp_min = 1, xp_max = 3, + head_swivel = "head.control", + bone_eye_height = 1.1, + horrizonatal_head_height=0, + curiosity = 10, collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.89, 0.25}, visual = "mesh", mesh = "mobs_mc_parrot.b3d", diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 96e073ebe..98b1db805 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 = 7.5, + head_eye_height = 0.8, + horrizonatal_head_height=-1, + curiosity = 3, + head_yaw="z", makes_footstep_sound = true, walk_velocity = 1, run_velocity = 3, diff --git a/mods/ENTITIES/mobs_mc/polar_bear.lua b/mods/ENTITIES/mobs_mc/polar_bear.lua index 6912df3a9..c81525f09 100644 --- a/mods/ENTITIES/mobs_mc/polar_bear.lua +++ b/mods/ENTITIES/mobs_mc/polar_bear.lua @@ -24,6 +24,12 @@ mcl_mobs:register_mob("mobs_mc:polar_bear", { textures = { {"mobs_mc_polarbear.png"}, }, + head_swivel = "head.control", + bone_eye_height = 2.6, + head_eye_height = 1, + horrizonatal_head_height = 0, + curiosity = 20, + head_yaw="z", visual_size = {x=3.0, y=3.0}, makes_footstep_sound = true, damage = 6, diff --git a/mods/ENTITIES/mobs_mc/rabbit.lua b/mods/ENTITIES/mobs_mc/rabbit.lua index 00f2f5d7e..a28b34359 100644 --- a/mods/ENTITIES/mobs_mc/rabbit.lua +++ b/mods/ENTITIES/mobs_mc/rabbit.lua @@ -15,7 +15,12 @@ local rabbit = { xp_min = 1, xp_max = 3, collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.49, 0.2}, - + head_swivel = "head.control", + bone_eye_height = 2, + head_eye_height = 0.5, + horrizonatal_head_height = -.3, + curiosity = 20, + head_yaw="z", visual = "mesh", mesh = "mobs_mc_rabbit.b3d", textures = { diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index d2bab09d4..b27ddfd34 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..ce80a680b 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.38, + curiosity = 6, visual = "mesh", mesh = "mobs_mc_skeleton.b3d", textures = { { diff --git a/mods/ENTITIES/mobs_mc/skeleton_wither.lua b/mods/ENTITIES/mobs_mc/skeleton_wither.lua index 5fbd273f7..da25e368d 100644 --- a/mods/ENTITIES/mobs_mc/skeleton_wither.lua +++ b/mods/ENTITIES/mobs_mc/skeleton_wither.lua @@ -24,11 +24,14 @@ mcl_mobs:register_mob("mobs_mc:witherskeleton", { collisionbox = {-0.35, -0.01, -0.35, 0.35, 2.39, 0.35}, visual = "mesh", mesh = "mobs_mc_witherskeleton.b3d", + head_swivel = "head.control", + bone_eye_height = 2.38, + curiosity = 60, textures = { { "mobs_mc_empty.png", -- armor - "mobs_mc_wither_skeleton.png", -- wither skeleton "default_tool_stonesword.png", -- sword + "mobs_mc_wither_skeleton.png", -- wither skeleton } }, visual_size = {x=1.2, y=1.2}, 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..f44e42cb5 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1235,6 +1235,10 @@ mcl_mobs:register_mob("mobs_mc:villager", { spawn_class = "passive", hp_min = 20, hp_max = 20, + head_swivel = "head.control", + bone_eye_height = 6.3, + head_eye_height = 2.2, + 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_evoker.lua b/mods/ENTITIES/mobs_mc/villager_evoker.lua index 26e8f157b..070fcdb2e 100644 --- a/mods/ENTITIES/mobs_mc/villager_evoker.lua +++ b/mods/ENTITIES/mobs_mc/villager_evoker.lua @@ -21,6 +21,10 @@ mcl_mobs:register_mob("mobs_mc:evoker", { hp_max = 24, xp_min = 10, xp_max = 10, + head_swivel = "head.control", + bone_eye_height = 6.3, + head_eye_height = 2.2, + curiosity = 10, collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.95, 0.4}, visual = "mesh", mesh = "mobs_mc_villager.b3d", diff --git a/mods/ENTITIES/mobs_mc/villager_illusioner.lua b/mods/ENTITIES/mobs_mc/villager_illusioner.lua index a130b20d1..fd4a7e183 100644 --- a/mods/ENTITIES/mobs_mc/villager_illusioner.lua +++ b/mods/ENTITIES/mobs_mc/villager_illusioner.lua @@ -33,6 +33,10 @@ mcl_mobs:register_mob("mobs_mc:illusioner", { "mobs_mc_illusionist.png", --hat "mcl_bows_bow.png", }, }, + head_swivel = "head.control", + bone_eye_height = 2.2, + head_eye_height = 2.2, + curiosity = 10, sounds = { -- TODO: more sounds distance = 16, diff --git a/mods/ENTITIES/mobs_mc/villager_vindicator.lua b/mods/ENTITIES/mobs_mc/villager_vindicator.lua index efb0dd89f..67db51680 100644 --- a/mods/ENTITIES/mobs_mc/villager_vindicator.lua +++ b/mods/ENTITIES/mobs_mc/villager_vindicator.lua @@ -23,14 +23,18 @@ mcl_mobs:register_mob("mobs_mc:vindicator", { collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, visual = "mesh", mesh = "mobs_mc_vindicator.b3d", - textures = { - { - "mobs_mc_vindicator.png", - "blank.png", --no hat - "default_tool_steelaxe.png", - -- TODO: Glow when attacking (mobs_mc_vindicator.png) - }, - }, + head_swivel = "head.control", + bone_eye_height = 2.2, + head_eye_height = 2.2, + curiosity = 10, + textures = { + { + "mobs_mc_vindicator.png", + "blank.png", --no hat + "default_tool_steelaxe.png", + -- TODO: Glow when attacking (mobs_mc_vindicator.png) + }, + }, visual_size = {x=2.75, y=2.75}, makes_footstep_sound = true, damage = 13, 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..711a46799 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 = 3.5, + head_eye_height = 1.1, + horrizonatal_head_height=0, + curiosity = 3, + 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..62f3312e5 100644 --- a/mods/ENTITIES/mobs_mc/zombie.lua +++ b/mods/ENTITIES/mobs_mc/zombie.lua @@ -53,6 +53,11 @@ local zombie = { hp_max = 20, xp_min = 5, xp_max = 5, + head_swivel = "head.control", + bone_eye_height = 6.3, + head_eye_height = 2.2, + curiosity = 7, + head_pitch_multiplier=-1, breath_max = -1, armor = {undead = 90, fleshy = 90}, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.8, 0.3}, @@ -62,7 +67,6 @@ local zombie = { { "mobs_mc_empty.png", -- armor "mobs_mc_zombie.png", -- texture - "mobs_mc_empty.png", -- wielded_item } }, makes_footstep_sound = true, @@ -129,7 +133,6 @@ husk.textures = { { "mobs_mc_empty.png", -- armor "mobs_mc_husk.png", -- texture - "mobs_mc_empty.png", -- wielded_item } } husk.ignited_by_sunlight = false @@ -144,9 +147,8 @@ 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 + "mobs_mc_husk.png", -- texture }} baby_husk.ignited_by_sunlight = false baby_husk.sunlight_damage = 0 diff --git a/mods/ENTITIES/mobs_mc/zombiepig.lua b/mods/ENTITIES/mobs_mc/zombiepig.lua index 68e62f550..05e4d8577 100644 --- a/mods/ENTITIES/mobs_mc/zombiepig.lua +++ b/mods/ENTITIES/mobs_mc/zombiepig.lua @@ -25,13 +25,17 @@ local pigman = { group_attack = { "mobs_mc:pigman", "mobs_mc:baby_pigman" }, damage = 9, reach = 2, + head_swivel = "head.control", + bone_eye_height = 2.4, + head_eye_height = 1.4, + curiosity = 15, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, visual = "mesh", mesh = "mobs_mc_zombie_pigman.b3d", textures = { { + "mobs_mc_zombie_pigman.png", --pigman "blank.png", --baby "default_tool_goldsword.png", --sword - "mobs_mc_zombie_pigman.png", --pigman } }, visual_size = {x=3, y=3}, sounds = { diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index be95455c9..e9bfc5b9e 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -121,98 +121,8 @@ end local node_stand, node_stand_below, node_head, node_feet, node_head_top local is_swimming --- This following part is 2 wrapper functions for player:set_bones --- and player:set_properties preventing them from being resent on --- every globalstep when they have not changed. - -local function roundN(n, d) - if type(n) ~= "number" then return n end - local m = 10^d - return math.floor(n * m + 0.5) / m -end - -local function close_enough(a,b) - local rt=true - if type(a) == "table" and type(b) == "table" then - for k,v in pairs(a) do - if roundN(v,2) ~= roundN(b[k],2) then - rt=false - break - end - end - else - rt = roundN(a,2) == roundN(b,2) - end - return rt -end - - - -local function props_changed(props,oldprops) - local changed=false - local p={} - for k,v in pairs(props) do - if not close_enough(v,oldprops[k]) then - p[k]=v - changed=true - end - end - return changed,p -end - ---tests for roundN -local test_round1=15 -local test_round2=15.00199999999 -local test_round3=15.00111111 -local test_round4=15.00999999 - -assert(roundN(test_round1,2)==roundN(test_round1,2)) -assert(roundN(test_round1,2)==roundN(test_round2,2)) -assert(roundN(test_round1,2)==roundN(test_round3,2)) -assert(roundN(test_round1,2)~=roundN(test_round4,2)) - --- tests for close_enough -local test_cb = {-0.35,0,-0.35,0.35,0.8,0.35} --collisionboxes -local test_cb_close = {-0.351213,0,-0.35,0.35,0.8,0.351212} -local test_cb_diff = {-0.35,0,-1.35,0.35,0.8,0.35} - -local test_eh = 1.65 --eye height -local test_eh_close = 1.65123123 -local test_eh_diff = 1.35 - -local test_nt = { r = 225, b = 225, a = 225, g = 225 } --nametag -local test_nt_diff = { r = 225, b = 225, a = 0, g = 225 } - -assert(close_enough(test_cb,test_cb_close)) -assert(not close_enough(test_cb,test_cb_diff)) -assert(close_enough(test_eh,test_eh_close)) -assert(not close_enough(test_eh,test_eh_diff)) -assert(not close_enough(test_nt,test_nt_diff)) --no floats involved here - ---tests for properties_changed -local test_properties_set1={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }} -local test_properties_set2={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 1.35, nametag_color = { r = 225, b = 225, a = 225, g = 225 }} - -local test_p1,_=props_changed(test_properties_set1,test_properties_set1) -local test_p2,_=props_changed(test_properties_set1,test_properties_set2) - -assert(not test_p1) -assert(test_p2) - -local function set_properties_conditional(player,props) - local changed,p=props_changed(props,player:get_properties()) - if changed then - player:set_properties(p) - end -end - -local function set_bone_position_conditional(player,b,p,r) --bone,position,rotation - local oldp,oldr=player:get_bone_position(b) - if vector.equals(vector.round(oldp),vector.round(p)) and vector.equals(vector.round(oldr),vector.round(r)) then - return - end - player:set_bone_position(b,p,r) -end +local set_bone_position_conditional = mcl_util.set_bone_position +local set_properties_conditional = mcl_util.set_properties local function get_overall_velocity(vector) local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2)