public static bool TryParse(ref byte[] buffer, out NbtCompoundTag result) { var parser = new NbtParser(); Stream nbtStream = new MemoryStream(buffer); if (buffer[0] == 0) { buffer = buffer[1..];
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()); }
public ReadResults Parse(out Item result) { result = default; ReadResults readResults = ReadTag(out bool isTag); if (!readResults.Successful) { return(readResults); } readResults = ResourceLocation.TryRead(StringReader, out ResourceLocation item); if (!readResults.Successful) { return(readResults); } // Temporary if (UseBedrock) { result = new Item(item, null, isTag); return(ReadResults.Success()); } if (!isTag && !Resources.Items.Contains(item)) { return(ReadResults.Failure(CommandError.UnknownItem(item))); } if (StringReader.CanRead() && StringReader.Peek() == '{') { readResults = new NbtParser(StringReader).ReadCompound(out INbtTag nbt); if (readResults.Successful) { result = new Item(item, nbt, isTag); } return(readResults); } result = new Item(item, null, isTag); return(ReadResults.Success()); }
public override void Read(byte[] array) { McInt.TryParse(ref array, out ChunkX); // int McInt.TryParse(ref array, out ChunkZ); // int McBoolean.TryParse(ref array, out Fullchunk); // bool McVarint.TryParse(ref array, out PrimaryBitMask); // var int McNbtCompoundTag.TryParse(ref array, out Heightmaps); if (Fullchunk) { McVarint.TryParse(ref array, out Biomeslength); Biomes = new int[Biomeslength]; for (int i = 0; i < Biomeslength; i++) { McVarint.TryParse(ref array, out Biomes[i]); } } // chunk data McVarint.TryParse(ref array, out Size); // size varint McByteArray.TryParse(Size, ref array, out Data); // Byte array // BlockEntities McVarint.TryParse(ref array, out NumberOfBlockEntities); BlockEntities = new NbtCompoundTag[NumberOfBlockEntities]; var read1 = new NbtParser(); Stream stream1 = new MemoryStream(array); for (int i = 0; i < NumberOfBlockEntities; i++) { BlockEntities[i] = read1.ParseNbtStream(stream1); } }