Beispiel #1
0
        static List <BlockState> GetBlockData(Stream InputStream)
        {
            /*
             * This whole section is just a tangled mess to parse the blockstate JSON files.
             *
             * Rather than even try to parse the JSON myself with string operators (cancer),
             * I decided to use an external function library.
             */
            List <BlockState>           BlockStates     = new List <BlockState>();     //Generate the lists
            List <ModelReference>       ModelList       = new List <ModelReference>(); //before using them
            Dictionary <string, string> ModelDictionary = new Dictionary <string, string>();

            using (StreamReader sr = new StreamReader(InputStream))
            {
                JObject JsonOutput = JObject.Parse(sr.ReadToEnd());
                foreach (KeyValuePair <string, JToken> Token in JsonOutput)
                {
                    if (Token.Key == "variants")
                    {
                        BlockStates = new List <BlockState>();
                        foreach (JToken Variants in Token.Value)
                        {
                            foreach (JToken StateToken in Variants.Values <JToken>())
                            {
                                ModelList       = new List <ModelReference>();
                                ModelDictionary = new Dictionary <string, string>();
                                foreach (JToken ModelToken in StateToken.Children())
                                {
                                    ModelDictionary.Add(ModelToken.ToObject <JProperty>().Name, ModelToken.ToObject <string>());
                                }
                                ModelList.Add(new ModelReference(ModelDictionary));
                                BlockStates.Add(new BlockState(Variants.ToObject <JProperty>().Name, ModelList));
                            }
                        }
                        //PackBlocks.Add(new Block(Entry.Name.Split('.')[0], BlockStates));
                    }
                    else
                    {
                        throw new TrashMonkeyException("Model is multipart!");
                    }
                }
            }
            return(BlockStates);
        }
Beispiel #2
0
        static void GetBlockStates(string PathInput)
        {
            List <Block> Blocks = new List <Block>();

            using (ZipArchive MinecraftJar = ZipFile.OpenRead(PathInput))
            {
                IEnumerable <ZipArchiveEntry> BlockStateEntries = MinecraftJar.Entries.Where(Entry => (Entry.Name.EndsWith(".json")) && (Entry.FullName.EndsWith(@"minecraft/blockstates/" + Entry.Name)));
                foreach (ZipArchiveEntry Entry in BlockStateEntries)
                {
                    /*
                     * This whole section is just a tangled mess to parse the blockstate JSON files.
                     *
                     * Rather than even try to parse the JSON myself with string operators (cancer),
                     * I decided to use an external function library.
                     */
                    List <BlockState>           BlockStates     = new List <BlockState>();     //Generate the lists
                    List <ModelReference>       ModelList       = new List <ModelReference>(); //before using them
                    Dictionary <string, string> ModelDictionary = new Dictionary <string, string>();
                    using (StreamReader sr = new StreamReader(Entry.Open()))
                    {
                        try
                        {
                            JObject JsonOutput = JObject.Parse(sr.ReadToEnd());
                            foreach (KeyValuePair <string, JToken> Token in JsonOutput)
                            {
                                if (Token.Key == "variants")
                                {
                                    BlockStates = new List <BlockState>();
                                    foreach (JToken Variants in Token.Value)
                                    {
                                        foreach (JToken StateToken in Variants.Values <JToken>())
                                        {
                                            ModelList       = new List <ModelReference>();
                                            ModelDictionary = new Dictionary <string, string>();
                                            foreach (JToken ModelToken in StateToken.Children())
                                            {
                                                ModelDictionary.Add(ModelToken.ToObject <JProperty>().Name, ModelToken.ToObject <string>());
                                            }
                                            ModelList.Add(new ModelReference(ModelDictionary));
                                            BlockStates.Add(new BlockState(Variants.ToObject <JProperty>().Name, ModelList));
                                        }
                                    }
                                    Blocks.Add(new Block(Entry.Name.Split('.')[0], BlockStates));
                                }
                            }
                        }
                        catch
                        {
                            /*
                             * For some reason Mojang has a crappy blockstate for acacia_wall_sign.
                             * It has a random 'n' after all the data, which gives my code AIDS
                             * unless I put it all in a try/catch. :P
                             */
                        }
                    }
                }
                ResourcePack[] ResourcePacks = null;
                foreach (ResourcePack Pack in ResourcePacks)
                {
                    switch (Pack.Type)
                    {
                    case ResourcePack.PackType.Mod:
                    case ResourcePack.PackType.Jar:
                    case ResourcePack.PackType.Zip:

                        break;

                    case ResourcePack.PackType.Folder:

                        break;

                    default:
                        break;
                    }
                }

                List <ZipArchiveEntry> BlockModelEntries = new List <ZipArchiveEntry>();

                foreach (Block block in Blocks)
                {
                    BlockModelEntries.Add(MinecraftJar.GetEntry("assets/minecraft/models/" + block.BlockStates[0].Models[0].ModelData["model"] + ".json"));
                }

                BlockModelEntries = BlockModelEntries.Distinct().ToList();

                List <BlockModel> BlockModels = new List <BlockModel>();

                foreach (ZipArchiveEntry Entry in BlockModelEntries)
                {
                }


                Console.Write("");

                //IEnumerable<ZipArchiveEntry> BlockModelEntries = MinecraftJar.Entries.Where(Entry => (Entry.Name.EndsWith(".json")) && (Entry.FullName.EndsWith(@"minecraft/models/block/" + Entry.Name)));
                //foreach (ZipArchiveEntry Entry in BlockModelEntries)
                //{

                //}
            }
        }