public void Serialize(MinecraftStream minecraftStream) { using var stream = new MinecraftStream(); using var dataStream = new MinecraftStream(); stream.WriteInt(Chunk.X); stream.WriteInt(Chunk.Z); //Chunk.CalculateHeightmap(); var writer = new NbtWriter(stream, string.Empty); foreach (var(type, heightmap) in Chunk.Heightmaps) { if (type == ChunkData.HeightmapType.MotionBlocking) { writer.WriteTag(new NbtArray <long>(type.ToString().ToSnakeCase().ToUpper(), heightmap.GetDataArray().Cast <long>())); } } writer.EndCompound(); writer.TryFinish(); foreach (var section in Chunk.Sections) { if (section is { BlockStateContainer.IsEmpty: false })
public void WriteDimensionCodec(DimensionCodec value) { var writer = new NbtWriter(this, ""); value.TransferTags(writer); writer.EndCompound(); writer.TryFinish(); }
public void WriteMixedCodec(MixedCodec value) { var writer = new NbtWriter(this, ""); var list = new NbtList(NbtTagType.Compound, "value"); foreach (var(_, codec) in value.Dimensions) { codec.Write(list); } var dimensions = new NbtCompound(value.Dimensions.Name) { new NbtTag <string>("type", value.Dimensions.Name), list }; #region biomes var biomes = new NbtList(NbtTagType.Compound, "value"); foreach (var(_, biome) in value.Biomes) { biome.Write(biomes); } var biomeCompound = new NbtCompound(value.Biomes.Name) { new NbtTag <string>("type", value.Biomes.Name), biomes }; #endregion writer.WriteTag(dimensions); writer.WriteTag(biomeCompound); writer.EndCompound(); writer.TryFinish(); }
public async Task WriteSlotAsync(ItemStack slot) { if (slot is null) { slot = new ItemStack(0, 0) { Present = true } } ; var item = slot.GetItem(); await WriteBooleanAsync(slot.Present); if (slot.Present) { await WriteVarIntAsync(item.Id); await WriteByteAsync((sbyte)slot.Count); var writer = new NbtWriter(this, ""); var itemMeta = slot.ItemMeta; //TODO write enchants if (itemMeta.HasTags()) { writer.WriteBool("Unbreakable", itemMeta.Unbreakable); if (itemMeta.Durability > 0) { writer.WriteInt("Damage", itemMeta.Durability); } if (itemMeta.CustomModelData > 0) { writer.WriteInt("CustomModelData", itemMeta.CustomModelData); } if (itemMeta.CanDestroy != null) { writer.WriteListStart("CanDestroy", NbtTagType.String, itemMeta.CanDestroy.Count); foreach (var block in itemMeta.CanDestroy) { writer.WriteString(block); } writer.EndList(); } if (itemMeta.Name != null) { writer.WriteCompoundStart("display"); writer.WriteString("Name", new List <ChatMessage> { (ChatMessage)itemMeta.Name }.ToJson()); if (itemMeta.Lore != null) { writer.WriteListStart("Lore", NbtTagType.String, itemMeta.Lore.Count); foreach (var lore in itemMeta.Lore) { writer.WriteString(new List <ChatMessage> { (ChatMessage)lore }.ToJson()); } writer.EndList(); } writer.EndCompound(); } else if (itemMeta.Lore != null) { writer.WriteCompoundStart("display"); writer.WriteListStart("Lore", NbtTagType.String, itemMeta.Lore.Count); foreach (var lore in itemMeta.Lore) { writer.WriteString(new List <ChatMessage> { (ChatMessage)lore }.ToJson()); } writer.EndList(); writer.EndCompound(); } } writer.WriteString("id", item.UnlocalizedName); writer.WriteByte("Count", (byte)slot.Count); writer.EndCompound(); writer.TryFinish(); } }