예제 #1
0
        public bool TryGetBedrockBitmap(ResourceLocation location, out Image <Rgba32> bitmap)
        {
            bitmap = null;
            foreach (var resourcePack in ActiveBedrockResourcePacks.Reverse())
            {
                if (resourcePack.TryGetTexture(location, out var f))
                {
                    bitmap = f;
                    return(true);
                }
            }

            return(false);
        }
예제 #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());
            }
        }
예제 #3
0
        public bool Asynchronous => true; //ActiveResourcePacks.All(x => x.Asynchronous);

        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            LoadHWID();

            PreloadCallback = preloadCallback;

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            string defaultResources;
            string defaultBedrock;

            if (!CheckJavaAssets(progressReceiver, out defaultResources))
            {
                return(false);
            }

            if (!CheckBedrockAssets(progressReceiver, out defaultBedrock))
            {
                return(false);
            }

            progressReceiver?.UpdateProgress(0, "Loading vanilla resources...");

            var vanilla = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultResources), preloadCallback);

            if (vanilla.Info != null)
            {
                vanilla.Info.Name = "Vanilla";
            }

            ActiveResourcePacks.AddFirst((McResourcePack)vanilla);

            Alex.AudioEngine.Initialize((McResourcePack)vanilla);

            // Log.Info($"Loading bedrock resources...");

            progressReceiver?.UpdateProgress(0, "Loading bedrock resources...");

            var vanillaBedrock = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultBedrock));

            ActiveBedrockResourcePacks.AddFirst((BedrockResourcePack)vanillaBedrock);
            //Log.Info($"Loading known entity data...");

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(
                device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            EntityFactory.Load(this, progressReceiver);

            ItemFactory.Init(RegistryManager, this, progressReceiver);

            BlockEntityFactory.LoadResources(device, this);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            BlockMapper.Init(progressReceiver);

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            var data = ReadResource("Alex.Resources.nethergames.png");

            NethergamesLogo = TextureUtils.BitmapToTexture2D(Alex.GraphicsDevice, Image.Load(data));

            return(true);
        }