X/Y/Z scale is multiplied by generic model scale.

This commit is contained in:
UnknownShadow200 2018-01-15 18:48:13 +11:00
parent a9788cf928
commit 0dbf3cba7d
2 changed files with 27 additions and 16 deletions

View File

@ -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) {

View File

@ -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);