public object Clone() { GeometryModel geometryModel = (GeometryModel)this.MemberwiseClone(); geometryModel.Geometry = new List <EntityModel>(); foreach (var geometry in this.Geometry) { geometryModel.Geometry.Add(geometry); } return((object)geometryModel); }
public static string ToJson(GeometryModel geometryModel) { var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; settings.DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate; settings.MissingMemberHandling = MissingMemberHandling.Ignore; //settings.Formatting = Formatting.Indented; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); settings.Converters.Add(new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() }); return(JsonConvert.SerializeObject(geometryModel, settings)); }
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); } }
private void InitializeGame(IProgressReceiver progressReceiver) { progressReceiver.UpdateProgress(0, "Initializing..."); API.Extensions.Init(GraphicsDevice); MCPacketFactory.Load(); //ConfigureServices(); var eventDispatcher = Services.GetRequiredService <IEventDispatcher>() as EventDispatcher; foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { eventDispatcher.LoadFrom(assembly); } //var options = Services.GetService<IOptionsProvider>(); // Log.Info($"Loading resources..."); if (!Resources.CheckResources(GraphicsDevice, progressReceiver, OnResourcePackPreLoadCompleted)) { Console.WriteLine("Press enter to exit..."); Console.ReadLine(); Exit(); return; } var profileManager = Services.GetService <ProfileManager>(); profileManager.LoadProfiles(progressReceiver); //GuiRenderer.LoadResourcePack(Resources.ResourcePack, null); AnvilWorldProvider.LoadBlockConverter(); PluginManager.EnablePlugins(); var storage = Services.GetRequiredService <IStorageSystem>(); if (storage.TryReadString("skin.json", out var str, Encoding.UTF8)) { if (GeometryModel.TryParse(str, null, out var geometryModel)) { var model = geometryModel.FindGeometry("geometry.humanoid.custom"); if (model == null) { model = geometryModel.FindGeometry("geometry.humanoid.customSlim"); } if (model != null) { PlayerModel = model; Log.Debug($"Player model loaded..."); } } } if (PlayerModel == null) { if (ModelFactory.TryGetModel("geometry.humanoid.customSlim", out var model)) { //model.Name = "geometry.humanoid.customSlim"; PlayerModel = model; } } if (PlayerModel != null) { //Log.Info($"Player model loaded..."); } if (storage.TryReadBytes("skin.png", out byte[] skinBytes))