Search in sources :

Example 11 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class GlowChunk method toMessage.

/**
     * Creates a new {@link ChunkDataMessage} which can be sent to a client to stream
     * parts of this chunk to them.
     *
     * @param skylight Whether to include skylight data.
     * @param entireChunk Whether to send all chunk sections.
     * @return The {@link ChunkDataMessage}.
     */
public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk) {
    load();
    int sectionBitmask = 0;
    // filter sectionBitmask based on actual chunk contents
    if (sections != null) {
        int maxBitmask = (1 << sections.length) - 1;
        if (entireChunk) {
            sectionBitmask = maxBitmask;
        } else {
            sectionBitmask &= maxBitmask;
        }
        for (int i = 0; i < sections.length; ++i) {
            if (sections[i] == null || sections[i].isEmpty()) {
                // remove empty sections from bitmask
                sectionBitmask &= ~(1 << i);
            }
        }
    }
    ByteBuf buf = Unpooled.buffer();
    if (sections != null) {
        // get the list of sections
        for (int i = 0; i < sections.length; ++i) {
            if ((sectionBitmask & 1 << i) == 0) {
                continue;
            }
            sections[i].writeToBuf(buf, skylight);
        }
    }
    // biomes
    if (entireChunk && biomes != null) {
        buf.writeBytes(biomes);
    }
    ArrayList<CompoundTag> blockEntities = new ArrayList<>();
    for (BlockEntity blockEntity : getRawBlockEntities()) {
        CompoundTag tag = new CompoundTag();
        blockEntity.saveNbt(tag);
        blockEntities.add(tag);
    }
    return new ChunkDataMessage(x, z, entireChunk, sectionBitmask, buf, blockEntities.toArray(new CompoundTag[blockEntities.size()]));
}
Also used : ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) ByteBuf(io.netty.buffer.ByteBuf) CompoundTag(net.glowstone.util.nbt.CompoundTag) BlockEntity(net.glowstone.block.entity.BlockEntity)

Example 12 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class GlowPlayer method sendSignChange.

/**
     * Send a sign change, similar to {@link #sendSignChange(Location, String[])},
     * but using complete TextMessages instead of strings.
     *
     * @param location the location of the sign
     * @param lines    the new text on the sign or null to clear it
     * @throws IllegalArgumentException if location is null
     * @throws IllegalArgumentException if lines is non-null and has a length less than 4
     */
public void sendSignChange(SignEntity sign, Location location, TextMessage[] lines) throws IllegalArgumentException {
    checkNotNull(location, "location cannot be null");
    checkNotNull(lines, "lines cannot be null");
    checkArgument(lines.length == 4, "lines.length must equal 4");
    CompoundTag tag = new CompoundTag();
    sign.saveNbt(tag);
    afterBlockChanges.add(new UpdateBlockEntityMessage(location.getBlockX(), location.getBlockY(), location.getBlockZ(), GlowBlockEntity.SIGN.getValue(), tag));
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 13 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class PlayerProfile method fromNBT.

public static PlayerProfile fromNBT(CompoundTag tag) {
    // NBT: {Id: "", Name: "", Properties: {textures: [{Signature: "", Value: {}}]}}
    String uuidStr = tag.getString("Id");
    String name;
    if (tag.containsKey("Name")) {
        name = tag.getString("Name");
    } else {
        name = ProfileCache.getProfile(UUID.fromString(uuidStr)).getName();
    }
    List<PlayerProperty> properties = new ArrayList<>();
    if (tag.containsKey("Properties")) {
        CompoundTag texture = tag.getCompound("Properties").getCompoundList("textures").get(0);
        if (texture.containsKey("Signature")) {
            properties.add(new PlayerProperty("textures", texture.getString("Value"), texture.getString("Signature")));
        } else {
            properties.add(new PlayerProperty("textures", texture.getString("Value")));
        }
    }
    return new PlayerProfile(name, UUID.fromString(uuidStr), properties);
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 14 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class MojangsonParseTest method canParseType.

@Test
public void canParseType() {
    try {
        CompoundTag compound = Mojangson.parseCompound(testCase.getValue());
        Tag value = compound.getValue().get("value");
        // Checks if the TagType of the case and the parsed type are equal.
        if (value.getType() != testCase.getKey()) {
            fail("Incorrect type parsing for case " + testCase.getKey().getName() + " (Got " + value.getType().getName() + ") for Mojansgon: " + testCase.getValue());
        }
    } catch (MojangsonParseException e) {
        // Catches a parse failure.
        fail("Could not parse case for " + testCase.getKey().getName() + "( " + testCase.getValue() + "): " + e.getMessage());
    }
}
Also used : MojangsonParseException(net.glowstone.util.mojangson.ex.MojangsonParseException) CompoundTag(net.glowstone.util.nbt.CompoundTag) Tag(net.glowstone.util.nbt.Tag) CompoundTag(net.glowstone.util.nbt.CompoundTag) Test(org.junit.Test)

Example 15 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class SkullEntity method update.

@Override
public void update(GlowPlayer player) {
    super.update(player);
    CompoundTag nbt = new CompoundTag();
    saveNbt(nbt);
    player.sendBlockEntityChange(getBlock().getLocation(), GlowBlockEntity.SKULL, nbt);
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)58 ArrayList (java.util.ArrayList)9 NBTInputStream (net.glowstone.util.nbt.NBTInputStream)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)3 BlockEntity (net.glowstone.block.entity.BlockEntity)3 GlowEntity (net.glowstone.entity.GlowEntity)3 ByteBuf (io.netty.buffer.ByteBuf)2 FileOutputStream (java.io.FileOutputStream)2 UUID (java.util.UUID)2 ChunkSection (net.glowstone.chunk.ChunkSection)2 AttributeManager (net.glowstone.entity.AttributeManager)2 Modifier (net.glowstone.entity.AttributeManager.Modifier)2 GlowStructure (net.glowstone.generator.structures.GlowStructure)2 StructureBoundingBox (net.glowstone.generator.structures.util.StructureBoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 Material (org.bukkit.Material)2