Beispiel #1
0
        public override void Cache(McResourcePack pack)
        {
            if (!Model.Textures.TryGetValue("layer0", out var t))
            {
                t = Model.Textures.FirstOrDefault(x => x.Value != null).Value;
            }

            if (t == null)
            {
                return;
            }

            List <VertexPositionColor> vertices = new List <VertexPositionColor>();

            if (pack.TryGetBitmap(t, out var rawTexture))
            {
                var texture = rawTexture.CloneAs <Rgba32>();

                float toolPosX = 0.0f;
                float toolPosY = 1.0f;
                float toolPosZ = (1f / 16f) * 7.5f;

                for (int y = 0; y < texture.Height; y++)
                {
                    for (int x = 0; x < texture.Width; x++)
                    {
                        var pixel = texture[x, y];
                        if (pixel.A == 0)
                        {
                            continue;
                        }

                        Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A);

                        ItemModelCube built =
                            new ItemModelCube(new Vector3(1f / texture.Width, 1f / texture.Height, 1f / 16f));
                        built.BuildCube(color);

                        var origin = new Vector3(
                            (toolPosX + (1f / texture.Width) * x),
                            toolPosY - (1f / texture.Height) * y,
                            toolPosZ
                            );

                        vertices.AddRange(Modify(built.Front, origin));
                        vertices.AddRange(Modify(built.Bottom, origin));
                        vertices.AddRange(Modify(built.Back, origin));
                        vertices.AddRange(Modify(built.Top, origin));
                        vertices.AddRange(Modify(built.Left, origin));
                        vertices.AddRange(Modify(built.Right, origin));
                    }
                }
            }

            Vertices = vertices.ToArray();
        }
Beispiel #2
0
 public static void LoadResources(GraphicsDevice graphicsDevice, McResourcePack resourcePack)
 {
     if (resourcePack.TryGetBitmap("minecraft:entity/chest/normal", out var bmp))
     {
         ChestTexture = TextureUtils.BitmapToTexture2D(graphicsDevice, bmp);
     }
     else
     {
         Log.Warn($"Could not load chest texture.");
     }
 }
Beispiel #3
0
        private void ProcessBlockStateModel(McResourcePack resourcePack, Dictionary <ResourceLocation, ImageEntry> textures, BlockStateModel bsModel)
        {
            var model = bsModel.Model;

            foreach (var texture in model.Textures)
            {
                var text = texture.Value;

                if (text[0] == '#')
                {
                    var substr = text.Substring(1);

                    if (model.Textures.TryGetValue(substr, out var p))
                    {
                        text = p;
                    }
                    else
                    {
                        var parent = model.Parent;

                        while (parent != null)
                        {
                            if (parent.Textures.TryGetValue(substr, out string parentName))
                            {
                                text = parentName;

                                break;
                            }

                            parent = parent.Parent;
                        }
                    }
                }

                var key = new ResourceLocation(text);

                var alreadyLoaded = textures.ContainsKey(key);
                if (!alreadyLoaded && resourcePack.TryGetBitmap(key, out var bmp))
                {
                    TextureMeta meta = null;
                    resourcePack.TryGetTextureMeta(key, out meta);

                    textures.TryAdd(key, new ImageEntry(bmp, meta));
                }
                else if (!alreadyLoaded)
                {
                    if (texture.Value[0] != '#' || text[0] != '#')
                    {
                        Log.Warn(
                            $"Could not get bitmap {texture.Value} or {text} (Key: {texture.Key} Model: {bsModel.ModelName})");
                    }
                }
            }
        }
        public static void LoadResources(GraphicsDevice graphicsDevice, McResourcePack resourcePack)
        {
            if (resourcePack.TryGetBitmap("minecraft:entity/chest/normal", out var bmp))
            {
                ChestTexture = TextureUtils.BitmapToTexture2D(graphicsDevice, bmp);
            }
            else
            {
                Log.Warn($"Could not load chest texture.");
            }

            if (resourcePack.TryGetBitmap("minecraft:entity/chest/ender", out var enderBmp))
            {
                EnderChestTexture = TextureUtils.BitmapToTexture2D(graphicsDevice, enderBmp);
            }
            else
            {
                Log.Warn($"Could not load enderchest texture");
            }

            if (resourcePack.TryGetBitmap("minecraft:entity/steve", out var steveBmp))
            {
                SkullTexture = TextureUtils.BitmapToTexture2D(graphicsDevice, steveBmp);
            }
            else
            {
                Log.Warn($"Could not load skull texture");
            }


            if (resourcePack.TryGetBitmap("minecraft:entity/signs/oak", out var signBmp))
            {
                SignTexture = TextureUtils.BitmapToTexture2D(graphicsDevice, signBmp);
            }
            else
            {
                Log.Warn($"Could not load sign texture");
            }
        }
Beispiel #5
0
        public void GetTextures(McResourcePack resourcePack,
                                Dictionary <ResourceLocation, ImageEntry> textures,
                                IProgressReceiver progressReceiver)
        {
            /*List<ResourceLocation> texturePaths = new List<ResourceLocation>();
             * foreach (var model in resourcePack.BlockModels)
             * {
             *      foreach (var texture in model.Value.Textures)
             *      {
             *              if (!texturePaths.Contains(texture.Value))
             *                      texturePaths.Add(texture.Value);
             *      }
             *     // model.Value.Textures
             * }*/

            int done = 0;
            //    var items = resourcePack.Textures.Where(x => texturePaths.Contains(x.Key)).ToArray();
            var texturePaths = resourcePack.Textures.Where(x => x.Key.Path.Contains("block/")).ToArray();

            foreach (var path in texturePaths)
            {
                progressReceiver?.UpdateProgress(done++, texturePaths.Length, "Resolving textures...", path.ToString());

                if (resourcePack.TryGetBitmap(path.Key, out var texture))
                {
                    TextureMeta meta = null;
                    resourcePack.TryGetTextureMeta(path.Key, out meta);
                    //var entry = new ImageEntry(texture.Value.Value, meta);

                    if (textures.ContainsKey(path.Key))
                    {
                        if (meta != null)
                        {
                            textures[path.Key].Meta = meta;
                        }

                        if (texture != null)
                        {
                            textures[path.Key].Image = texture;
                        }

                        //textures[texture.Key] = entry;
                    }
                    else
                    {
                        textures.Add(path.Key, new ImageEntry(texture, meta));
                    }
                }
            }
        }
Beispiel #6
0
        public override void Cache(McResourcePack pack)
        {
            string t = string.Empty;

            if (!Model.Textures.TryGetValue("layer0", out t))
            {
                t = Model.Textures.FirstOrDefault(x => x.Value != null).Value;
            }

            if (t == default)
            {
                return;
            }

            List <VertexPositionColor> vertices = new List <VertexPositionColor>();
            List <short> indexes = new List <short>();

            if (pack.TryGetBitmap(t, out var rawTexture))
            {
                var texture = rawTexture.CloneAs <Rgba32>();

                int   i               = 0;
                float toolPosX        = 0.0f;
                float toolPosY        = 1.0f;
                float toolPosZ        = (1f / 16f) * 7.5f;
                int   verticesPerTool = texture.Width * texture.Height * 36;


                for (int y = 0; y < texture.Height; y++)
                {
                    for (int x = 0; x < texture.Width; x++)
                    {
                        var pixel = texture[x, y];
                        if (pixel.A == 0)
                        {
                            continue;
                        }

                        Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A);

                        ItemModelCube built =
                            new ItemModelCube(new Vector3(1f / texture.Width, 1f / texture.Height, 1f / 16f));
                        built.BuildCube(color);

                        var origin = new Vector3(
                            (toolPosX + (1f / texture.Width) * x),
                            toolPosY - (1f / texture.Height) * y,
                            toolPosZ
                            );

                        vertices = ModifyCubeIndexes(vertices, ref built.Front, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Back, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Top, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Bottom, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Left, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Right, origin);

                        var indices = built.Front.indexes
                                      .Concat(built.Back.indexes)
                                      .Concat(built.Top.indexes)
                                      .Concat(built.Bottom.indexes)
                                      .Concat(built.Left.indexes)
                                      .Concat(built.Right.indexes)
                                      .ToArray();

                        indexes.AddRange(indices);
                    }
                }
            }

            Vertices = vertices.ToArray();

            for (var index = 0; index < Vertices.Length; index++)
            {
                var vertice = Vertices[index];
                Vertices[index] = vertice;
            }

            Indexes = indexes.ToArray();
        }
Beispiel #7
0
        private void Cache(McResourcePack pack)
        {
            var t = Model.Textures.FirstOrDefault(x => x.Value != null);

            if (t.Value == default)
            {
                return;
            }

            List <VertexPositionColor> vertices = new List <VertexPositionColor>();
            List <short> indexes = new List <short>();

            if (pack.TryGetBitmap(t.Value, out Bitmap texture))
            {
                int   i               = 0;
                float toolPosX        = 0.0f;
                float toolPosY        = 0.0f;
                float toolPosZ        = 0.0f;
                int   verticesPerTool = texture.Width * texture.Height * 36;


                for (int y = 0; y < texture.Height; y++)
                {
                    for (int x = 0; x < texture.Width; x++)
                    {
                        var pixel = texture.GetPixel(x, y);
                        if (pixel.A == 0)
                        {
                            continue;
                        }

                        Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A);

                        ItemModelCube built = new ItemModelCube(new Vector3(1f / texture.Width));
                        built.BuildCube(color);

                        var origin = new Vector3(toolPosX + (1f / texture.Width) * x, toolPosY - (1f / texture.Height) * y, toolPosZ);

                        vertices = ModifyCubeIndexes(vertices, ref built.Front, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Back, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Top, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Bottom, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Left, origin);
                        vertices = ModifyCubeIndexes(vertices, ref built.Right, origin);

                        var indices = built.Front.indexes
                                      .Concat(built.Back.indexes)
                                      .Concat(built.Top.indexes)
                                      .Concat(built.Bottom.indexes)
                                      .Concat(built.Left.indexes)
                                      .Concat(built.Right.indexes)
                                      .ToArray();

                        indexes.AddRange(indices);
                    }
                }
            }

            Vertices = vertices.ToArray();

            for (var index = 0; index < Vertices.Length; index++)
            {
                var vertice = Vertices[index];
                Vertices[index] = vertice;
            }

            Indexes = indexes.ToArray();
        }
Beispiel #8
0
        private void GetTextures(McResourcePack resourcePack,
                                 Dictionary <ResourceLocation, Image <Rgba32>[]> seperateFrames,
                                 Dictionary <ResourceLocation, Image <Rgba32> > regularTextures, IProgressReceiver progressReceiver)
        {
            progressReceiver.UpdateProgress(0, "Processing blockstate textures...");
            int blockstatesProcessed = 0;
            int totalStates          = resourcePack.BlockStates.Count;

            foreach (var state in resourcePack.BlockStates)
            {
                progressReceiver.UpdateProgress((int)(100D * ((double)blockstatesProcessed / (double)totalStates)), null, state.Key);

                var blockState = BlockFactory.GetBlockState(state.Key);

                if (blockState.Name == "Unknown")
                {
                    Log.Warn($"Missing blockstate: {state.Key}");
                    blockstatesProcessed++;
                    continue;
                }

                foreach (var variant in state.Value.Variants)
                {
                    foreach (var entry in BlockState.ParseData(variant.Key))
                    {
                        blockState = blockState.WithProperty(entry.Key, entry.Value);
                    }

                    foreach (var va in variant.Value)
                    {
                        var model = va.Model;

                        foreach (var texture in model.Textures)
                        //foreach(var element in model.Elements)
                        //foreach(var face in element.Faces)
                        {
                            //  var text = face.Value.Texture; //ResourcePackBlockModel.ResolveTexture(model, texture.Value);
                            var text = texture.Value;
                            if (text[0] == '#')
                            {
                                var substr = text.Substring(1);

                                if (model.Textures.TryGetValue(substr, out var p))
                                {
                                    text = p;
                                }
                                else
                                {
                                    var parent = model.Parent;

                                    while (parent != null)
                                    {
                                        if (parent == null)
                                        {
                                            break;
                                        }

                                        if (parent.Textures.TryGetValue(substr, out string parentName))
                                        {
                                            text = parentName;

                                            break;
                                        }

                                        parent = parent.Parent;
                                    }
                                }
                            }

                            if (resourcePack.TryGetBitmap(text, out var bmp))
                            {
                                if (blockState.Block.Animated && !seperateFrames.ContainsKey(text))
                                {
                                    var frameSize = GetTextureDimensions(resourcePack, text);
                                    seperateFrames.Add(text, GetFrames(bmp, (int)frameSize.X, (int)frameSize.Y));
                                }
                                else if (!blockState.Block.Animated &&
                                         regularTextures.All(x => x.Key != text))
                                {
                                    regularTextures.Add(text, bmp);
                                }
                            }
                            else
                            {
                                /// if (!texture.Value)
                                //	Log.Warn($"Could not get bitmap {texture.Value} or {text} (Key: {texture.Key} Model: {model.Name})");
                            }
                        }
                    }
                }

                blockstatesProcessed++;
                // state.
            }

            if (resourcePack.TryGetBitmap("block/water_flow", out var flow))
            {
                var frameSize = GetTextureDimensions(resourcePack, "block/water_flow");
                seperateFrames.TryAdd("block/water_flow", GetFrames(flow, (int)frameSize.X, (int)frameSize.Y));
            }

            if (resourcePack.TryGetBitmap("block/water_still", out var still))
            {
                var frameSize = GetTextureDimensions(resourcePack, "block/water_still");
                seperateFrames.TryAdd("block/water_still", GetFrames(still, (int)frameSize.X, (int)frameSize.Y));
            }
        }