public object Clone() { var cloned = new SkinResourcePatch(); cloned.Geometry = (GeometryIdentifier)Geometry?.Clone(); return(cloned); }
public object Clone() { var clonedSkin = (Skin)MemberwiseClone(); clonedSkin.Data = Data?.Clone() as byte[]; clonedSkin.Cape = Cape?.Clone() as Cape; clonedSkin.SkinResourcePatch = SkinResourcePatch?.Clone() as SkinResourcePatch; foreach (Animation animation in Animations) { clonedSkin.Animations.Add((Animation)animation.Clone()); } return(clonedSkin); }
public static string ToJson(SkinResourcePatch model) { var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; settings.DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate; settings.MissingMemberHandling = MissingMemberHandling.Error; //settings.Formatting = Formatting.Indented; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); settings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); string json = JsonConvert.SerializeObject(model, settings); return(json); }
public static bool TryParse(string json, SkinResourcePatch resourcePatch, out GeometryModel output) { JObject obj = JObject.Parse(json, new JsonLoadSettings()); var entries = new List <EntityModel>(); output = new GeometryModel(); foreach (var e in obj) { try { if (e.Key == "format_version" && e.Value.Type == JTokenType.String) { output.FormatVersion = e.Value.ToObject <string>(); } else if (e.Key == "minecraft:geometry" && e.Value.Type == JTokenType.Array) { var models = e.Value.ToObject <EntityModel[]>(serializer); if (models != null) { foreach (var model in models) { model.Name = model.Description.Identifier; model.Textureheight = model.Description.TextureHeight; model.Texturewidth = model.Description.TextureWidth; model.VisibleBoundsHeight = model.Description.VisibleBoundsHeight; model.VisibleBoundsWidth = model.Description.VisibleBoundsWidth; model.VisibleBoundsOffset = model.Description.VisibleBoundsOffset; if (entries.Contains(model)) { Log.Warn($"The name {model.Description.Identifier} was already in use!"); } else { entries.Add(model); } } continue; } } if ( /*e.Key == "format_version" || e.Value.Type == JTokenType.Array*/ !e.Key.StartsWith("geometry.")) { if (e.Value.Type == JTokenType.Array) { continue; foreach (var type in e.Value.ToObject <EntityModel[]>(serializer)) { //entries.TryAdd(e.Key, type); } } continue; } //if (e.Key == "minecraft:client_entity") continue; //if (e.Key.Contains("zombie")) Console.WriteLine(e.Key); var newModel = e.Value.ToObject <EntityModel>(serializer); if (newModel != null) { newModel.Name = e.Key; if (newModel.Description?.Identifier == null) { newModel.Description = new ModelDescription() { Identifier = e.Key, TextureHeight = newModel.Textureheight, TextureWidth = newModel.Texturewidth }; } if (!entries.Contains(newModel)) { entries.Add(newModel); } } } catch (Exception ex) { Log.Warn(ex, $"Failed to decode geometry"); } } if (entries.Count == 0) { output = null; return(false); } output.Geometry = entries; return(true); }
public static bool TryParse(string json, SkinResourcePatch resourcePatch, out GeometryModel output) { try { JObject obj = JObject.Parse(json, new JsonLoadSettings()); var entries = new List <EntityModel>(); output = new GeometryModel(); foreach (var e in obj) { try { if (e.Key == "format_version" && e.Value.Type == JTokenType.String) { output.FormatVersion = e.Value.ToObject <string>(); } else if (e.Key == "minecraft:geometry" && e.Value.Type == JTokenType.Array) { var models = e.Value.ToObject <EntityModel[]>(MCJsonConvert.Serializer); if (models != null) { foreach (var model in models) { if (entries.Contains(model)) { Log.Warn($"The name {model.Description.Identifier} was already in use!"); } else { entries.Add(model); } } continue; } } if (!e.Key.StartsWith("geometry.")) { if (e.Value.Type == JTokenType.Array) { continue; foreach (var type in e.Value.ToObject <OldEntityModel[]>(MCJsonConvert.Serializer)) { //entries.TryAdd(e.Key, type); } } continue; } var newModel = e.Value.ToObject <EntityModel>(MCJsonConvert.Serializer); if (newModel != null) { if (string.IsNullOrWhiteSpace(newModel.Description?.Identifier)) { newModel.Description.Identifier = e.Key; } if (!entries.Contains(newModel)) { entries.Add(newModel); } } } catch (Exception ex) { Log.Warn(ex, $"Failed to decode geometry"); } } if (entries.Count == 0) { output = null; return(false); } output.Geometry = entries; return(true); } catch (JsonReaderException) { output = null; return(false); } }