public void Serialize(MinecraftStream minecraftStream) { using var stream = new MinecraftStream(); using var dataStream = new MinecraftStream(); stream.WriteInt(Chunk.X); stream.WriteInt(Chunk.Z); stream.WriteBoolean(true); // full chunk int chunkSectionY = 0, mask = 0; foreach (var section in Chunk.Sections) { if ((changedSectionFilter & 1 << chunkSectionY) != 0) { mask |= 1 << chunkSectionY; section.WriteTo(dataStream); } chunkSectionY++; } stream.WriteVarInt(mask); Chunk.CalculateHeightmap(); var writer = new NbtWriter(stream, string.Empty); foreach (var(type, heightmap) in Chunk.Heightmaps) { writer.WriteLongArray(type.ToString().ToSnakeCase().ToUpper(), heightmap.GetDataArray().Cast <long>().ToArray()); } writer.EndCompound(); writer.Finish(); Chunk.BiomeContainer.WriteTo(stream); dataStream.Position = 0; stream.WriteVarInt((int)dataStream.Length); dataStream.CopyTo(stream); stream.WriteVarInt(0); minecraftStream.Lock.Wait(); minecraftStream.WriteVarInt(Id.GetVarIntLength() + (int)stream.Length); minecraftStream.WriteVarInt(Id); stream.Position = 0; stream.CopyTo(minecraftStream); minecraftStream.Lock.Release(); }
public void Serialize(MinecraftStream stream) { using var packetStream = new MinecraftStream(); packetStream.WriteBoolean(this.Reset); packetStream.WriteAdvancements(this.Advancements); //Not sure what this is for packetStream.WriteVarInt(this.RemovedAdvancements.Count); foreach (var removed in this.RemovedAdvancements) { packetStream.WriteString(removed); } //Write progress for advancements foreach (var(name, advancement) in this.Advancements) { packetStream.WriteVarInt(advancement.Criteria.Count); foreach (var criteria in advancement.Criteria) { packetStream.WriteString(criteria.Identifier); packetStream.WriteBoolean(criteria.Achieved); if (criteria.Achieved) { packetStream.WriteLong(criteria.AchievedAt.Value.ToUnixTimeMilliseconds()); } } } stream.Lock.Wait(); stream.WriteVarInt(this.Id.GetVarIntLength() + (int)packetStream.Length); stream.WriteVarInt(this.Id); packetStream.Position = 0; packetStream.CopyTo(stream); stream.Lock.Release(); }
public void Serialize(MinecraftStream stream) { using var packetStream = new MinecraftStream(); packetStream.WriteString(this.ObjectiveName); packetStream.WriteByte((sbyte)this.Mode); if (this.Mode is ScoreboardMode.Create or ScoreboardMode.Update) { packetStream.WriteChat((ChatMessage)this.Value); packetStream.WriteVarInt(this.Type); } stream.Lock.Wait(); stream.WriteVarInt(this.Id.GetVarIntLength() + (int)packetStream.Length); stream.WriteVarInt(this.Id); packetStream.Position = 0; packetStream.CopyTo(stream); stream.Lock.Release(); }
public void Serialize(MinecraftStream stream) { using var packetStream = new MinecraftStream(); packetStream.WriteString(this.EntityName, 40); packetStream.WriteByte(this.Action); packetStream.WriteString(this.ObjectiveName, 16); if (this.Action == 0) { packetStream.WriteVarInt(this.Value); } stream.Lock.Wait(); stream.WriteVarInt(this.Id.GetVarIntLength() + (int)packetStream.Length); stream.WriteVarInt(this.Id); packetStream.Position = 0; packetStream.CopyTo(stream); stream.Lock.Release(); }