diff --git a/MCGalaxy/Entity/Entities.cs b/MCGalaxy/Entity/Entities.cs index c71f8a09f..c22155f24 100644 --- a/MCGalaxy/Entity/Entities.cs +++ b/MCGalaxy/Entity/Entities.cs @@ -198,14 +198,19 @@ namespace MCGalaxy { static void SendModelScales(Player pl, byte id, Entity entity) { if (!pl.Supports(CpeExt.EntityProperty)) return; - SendModelScale(pl, id, EntityProp.ScaleX, entity.ScaleX); - SendModelScale(pl, id, EntityProp.ScaleY, entity.ScaleY); - SendModelScale(pl, id, EntityProp.ScaleZ, entity.ScaleZ); + + string model = entity.Model; + float scale = AABB.GetScaleFrom(ref model); + SendModelScale(pl, id, EntityProp.ScaleX, entity.ScaleX * scale); + SendModelScale(pl, id, EntityProp.ScaleY, entity.ScaleY * scale); + SendModelScale(pl, id, EntityProp.ScaleZ, entity.ScaleZ * scale); } static void SendModelScale(Player pl, byte id, EntityProp axis, float value) { if (value == 0) return; - pl.Send(Packet.EntityProperty(id, axis, (int)(value * 1000))); + int packed = (int)(value * 1000); + if (packed == 0) return; + pl.Send(Packet.EntityProperty(id, axis, packed)); } static void SendModel(Player pl, byte id, string model) { diff --git a/MCGalaxy/util/Math/AABB.cs b/MCGalaxy/util/Math/AABB.cs index 9b465acaf..4a33f2816 100644 --- a/MCGalaxy/util/Math/AABB.cs +++ b/MCGalaxy/util/Math/AABB.cs @@ -93,9 +93,7 @@ namespace MCGalaxy.Maths { public static AABB ModelAABB(Entity entity, Level lvl) { string model = entity.Model; - int sep = model.IndexOf('|'); - string scaleStr = sep == -1 ? null : model.Substring(sep + 1); - model = sep == -1 ? model : model.Substring(0, sep); + float scale = GetScaleFrom(ref model); AABB bb; byte raw; @@ -107,17 +105,12 @@ namespace MCGalaxy.Maths { bb = AABB.Make(new Vec3S32(0, 0, 0), BaseSize(model)); } bb = bb.Expand(-1); // adjust the model AABB inwards slightly - - float scale; - if (!Utils.TryParseDecimal(scaleStr, out scale)) scale = 1.0f; - if (scale < 0.01f) scale = 0.01f; + float max = model.CaselessEq("chibi") ? 3 : 2; - scale = Math.Min(scale, max); - float scaleX = scale, scaleY = scale, scaleZ = scale; - if (entity.ScaleX != 0) scaleX = Math.Min(entity.ScaleX, max); - if (entity.ScaleY != 0) scaleY = Math.Min(entity.ScaleY, max); - if (entity.ScaleZ != 0) scaleZ = Math.Min(entity.ScaleZ, max); + if (entity.ScaleX != 0) scaleX = Math.Min(entity.ScaleX * scale, max); + if (entity.ScaleY != 0) scaleY = Math.Min(entity.ScaleY * scale, max); + if (entity.ScaleZ != 0) scaleZ = Math.Min(entity.ScaleZ * scale, max); bb.Min.X = (int)(bb.Min.X * scaleX); bb.Max.X = (int)(bb.Max.X * scaleX); bb.Min.Y = (int)(bb.Min.Y * scaleY); bb.Max.Y = (int)(bb.Max.Y * scaleY); @@ -126,6 +119,19 @@ namespace MCGalaxy.Maths { return bb; } + internal static float GetScaleFrom(ref string model) { + int sep = model.IndexOf('|'); + string scaleStr = sep == -1 ? null : model.Substring(sep + 1); + model = sep == -1 ? model : model.Substring(0, sep); + + float scale; + if (!Utils.TryParseDecimal(scaleStr, out scale)) scale = 1.0f; + if (scale < 0.01f) scale = 0.01f; + + float max = model.CaselessEq("chibi") ? 3 : 2; + return Math.Min(scale, max); + } + static Vec3S32 BaseSize(string model) { if (model.CaselessEq("chicken")) return new Vec3S32(16, 24, 16); if (model.CaselessEq("creeper")) return new Vec3S32(16, 52, 16);