示例#1
0
    private void WriteDimension(Dimension dimension, IMinecraftPacket packet)
    {
        var nbtDimension = NbtSerializer.SerializeCompound(dimension.Element, "");
        var nbtFile      = new NbtFile(nbtDimension);

        packet.WriteBytes(nbtFile.GetBuffer());
    }
示例#2
0
    public void SerializeComplexCompoundTest()
    {
        var faker   = new Faker();
        var element = new CustomComplexNbtElement
        {
            IntegerValue = faker.Random.Int(),
            FlatElement  = new CustomFlatNbtElement
            {
                ByteValue    = faker.Random.Byte(),
                ShortValue   = faker.Random.Short(),
                IntegerValue = faker.Random.Int(),
                FloatValue   = faker.Random.Float(),
                LongValue    = faker.Random.Long(),
                DoubleValue  = faker.Random.Double(),
                StringValue  = faker.Lorem.Sentence(),
            }
        };

        NbtCompound compound = NbtSerializer.SerializeCompound(element);

        Assert.NotNull(compound);
        AssertTag <NbtInt, int>(compound, "integer_value", element.IntegerValue, x => x.IntValue);

        NbtCompound innerCompound = compound.Get("flat_element_compound") as NbtCompound;

        Assert.NotNull(innerCompound);
        AssertTag <NbtByte, byte>(innerCompound, "byte_value", element.FlatElement.ByteValue, x => x.ByteValue);
        AssertTag <NbtShort, short>(innerCompound, "short_value", element.FlatElement.ShortValue, x => x.ShortValue);
        AssertTag <NbtInt, int>(innerCompound, "integer_value", element.FlatElement.IntegerValue, x => x.IntValue);
        AssertTag <NbtFloat, float>(innerCompound, "float_value", element.FlatElement.FloatValue, x => x.FloatValue);
        AssertTag <NbtLong, long>(innerCompound, "long_value", element.FlatElement.LongValue, x => x.LongValue);
        AssertTag <NbtDouble, double>(innerCompound, "double_value", element.FlatElement.DoubleValue, x => x.DoubleValue);
        AssertTag <NbtString, string>(innerCompound, "string_value", element.FlatElement.StringValue, x => x.StringValue);
    }
示例#3
0
    private void WriteDimensionsAndBiomes(IEnumerable <Dimension> dimensions, IEnumerable <Biome> biomes, IMinecraftPacket packet)
    {
        IEnumerable <NbtTag> dimensionsTags = dimensions.Select(x => NbtSerializer.SerializeCompound(x));
        IEnumerable <NbtTag> biomesTags     = biomes.Select(x => NbtSerializer.SerializeCompound(x));

        var nbtCompound = new NbtCompound("")
        {
            new NbtCompound("minecraft:dimension_type")
            {
                new NbtString("type", "minecraft:dimension_type"),
                new NbtList("value", dimensionsTags, NbtTagType.Compound)
            },
            new NbtCompound("minecraft:worldgen/biome")
            {
                new NbtString("type", "minecraft:worldgen/biome"),
                new NbtList("value", biomesTags, NbtTagType.Compound)
            }
        };
        var nbtFile = new NbtFile(nbtCompound);

        packet.WriteBytes(nbtFile.GetBuffer());
    }