Example #1
0
        private void LoadModels(IProgressReceiver progressReceiver, McResourcePack resourcePack, bool replaceModels,
                                bool reportMissingModels)
        {
            Stopwatch sw            = Stopwatch.StartNew();
            var       modelRegistry = RegistryManager.GetRegistry <ResourcePackModelBase>();

            int imported = 0;

            if (modelRegistry is BlockModelRegistry bmr)
            {
                imported = bmr.LoadResourcePack(progressReceiver, resourcePack);
            }

            Log.Info($"Imported {imported} block models from resourcepack in {sw.ElapsedMilliseconds}ms!");

            sw.Restart();

            MeasureProfiler.StartCollectingData();
            imported = BlockFactory.LoadBlockstates(RegistryManager, this, resourcePack, replaceModels, reportMissingModels, progressReceiver);
            MeasureProfiler.SaveData();

            MeasureProfiler.StopCollectingData();

            Log.Info($"Imported {imported} blockstates from resourcepack in {sw.ElapsedMilliseconds}ms!");
        }
Example #2
0
        private void LoadResourcePacks(GraphicsDevice device, IProgressReceiver progress, string[] resourcePacks)
        {
            var countBefore = ActiveResourcePacks.Count;

            var first  = ActiveResourcePacks.First.Value;
            var before = ActiveResourcePacks.ToArray();

            foreach (var item in before.Skip(1))
            {
                item.Dispose();
            }

            ActiveResourcePacks.Clear();

            ActiveResourcePacks.AddFirst(first);

            if (_hasInit)
            {
                PreloadCallback?.Invoke(first.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
                Atlas.Reset();
            }

            foreach (string file in resourcePacks)
            {
                try
                {
                    string resourcePackPath = Path.Combine(ResourcePackDirectory.FullName, file);
                    if (File.Exists(resourcePackPath))
                    {
                        //Log.Info($"Loading resourcepack {file}...");

                        //using (FileStream stream = new FileStream(resourcePackPath, FileMode.Open))
                        {
                            // using (ZipFileSystem zipFileSystem = )
                            {
                                var pack = LoadResourcePack(progress, new ZipFileSystem(new FileStream(resourcePackPath, FileMode.Open), Path.GetFileNameWithoutExtension(resourcePackPath)), null);

                                if (pack is McResourcePack javaPack)
                                {
                                    if (pack.Info != null && string.IsNullOrWhiteSpace(pack.Info.Name))
                                    {
                                        pack.Info.Name = Path.GetFileNameWithoutExtension(file);
                                    }

                                    ActiveResourcePacks.AddLast(javaPack);
                                }
                                else if (pack is BedrockResourcePack bedrockPack)
                                {
                                    ActiveBedrockResourcePacks.AddLast(bedrockPack);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e, $"Could not load resourcepack {file}: {e.ToString()}");
                }
            }

            var  active  = ActiveResourcePacks.ToArray();
            bool isFirst = true;

            foreach (var resourcePack in active)
            {
                Alex.GuiRenderer.LoadLanguages(resourcePack, progress);

                LoadModels(progress, resourcePack, !isFirst, isFirst);
                if (isFirst)
                {         //Only load models for vanilla until above we fix blockstate replacement issues.
                    isFirst = false;
                    // break;
                }
            }

            Stopwatch sw = Stopwatch.StartNew();

            MeasureProfiler.StartCollectingData();
            var imported = BlockFactory.LoadBlockstates(RegistryManager, this, false, false, progress);

            MeasureProfiler.SaveData();

            MeasureProfiler.StopCollectingData();

            Log.Info($"Imported {imported} blockstates from resourcepack in {sw.ElapsedMilliseconds}ms!");

            var textures = new Dictionary <ResourceLocation, AtlasGenerator.ImageEntry>();

            for (var index = 0; index < active.Length; index++)
            {
                var resourcePack = active[index];

                progress?.UpdateProgress(0, $"Loading textures: {resourcePack.Info?.Name ?? "Unknown"}");

                Atlas.LoadResourcePackOnTop(device,
                                            textures,
                                            resourcePack,
                                            progress, index == active.Length - 1);
                //LoadTextures(device, progress, resourcePack, ref textures, index == active.Length - 1);
            }

            foreach (var resourcePack in ActiveBedrockResourcePacks)
            {
                LoadEntityModels(resourcePack, progress);
                int modelCount = EntityFactory.LoadModels(resourcePack, this, device, true, progress);

                Log.Info($"Imported {modelCount} entity models...");
            }

            progress?.UpdateProgress(0, $"Loading UI textures...");
            Alex.GuiRenderer.LoadResourcePackTextures(this, progress);

            progress?.UpdateProgress(50, "Loading language...");
            if (!Alex.GuiRenderer.SetLanguage(Options.AlexOptions.MiscelaneousOptions.Language.Value))
            {
                Alex.GuiRenderer.SetLanguage(CultureInfo.InstalledUICulture.Name);
            }

            progress?.UpdateProgress(100, "Loading language...");

            var f = ActiveResourcePacks.LastOrDefault(x => x.FontBitmap != null);

            if (f != null)
            {
                PreloadCallback?.Invoke(f.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
            }
        }