Exemplo n.º 1
0
        public ReadResults Parse(out Block result)
        {
            result = default;

            ReadResults readResults = ReadTag();

            if (!readResults.Successful)
            {
                return(readResults);
            }

            readResults = ResourceLocation.TryRead(StringReader, out Block);
            if (!readResults.Successful)
            {
                return(readResults);
            }

            // Temporary
            if (UseBedrock)
            {
                result = new Block(Block, null, null, IsTag);
                return(ReadResults.Success());
            }

            if (!IsTag && !Resources.Blocks.ContainsBlock(Block))
            {
                return(ReadResults.Failure(CommandError.UnknownBlock(Block)));
            }

            Dictionary <string, string> blockStates = null;

            if (StringReader.CanRead() && StringReader.Peek() == '[')
            {
                readResults = ReadBlockStates(out blockStates);
                if (!readResults.Successful)
                {
                    return(readResults);
                }
            }

            INbtTag nbt = null;

            if (StringReader.CanRead() && StringReader.Peek() == '{')
            {
                readResults = new NbtParser(StringReader).ReadCompound(out nbt);
                if (!readResults.Successful)
                {
                    return(readResults);
                }
            }

            result = new Block(Block, blockStates, nbt, IsTag);
            return(ReadResults.Success());
        }