Search in sources :

Example 1 with CompoundTag

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

the class GlowMetaPotion method toNBT.

public static CompoundTag toNBT(PotionEffect effect) {
    CompoundTag tag = new CompoundTag();
    tag.putByte("Id", effect.getType().getId());
    tag.putInt("Duration", effect.getDuration());
    tag.putByte("Amplifier", effect.getAmplifier());
    tag.putBool("Ambient", effect.isAmbient());
    tag.putBool("ShowParticles", effect.hasParticles());
    return tag;
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 2 with CompoundTag

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

the class GlowMetaSpawn method readNbt.

@Override
void readNbt(CompoundTag tag) {
    super.readNbt(tag);
    if (tag.isCompound("EntityTag")) {
        CompoundTag entity = tag.getCompound("EntityTag");
        if (entity.isString("id")) {
            String id = entity.getString("id");
            if (id.startsWith("minecraft:")) {
                id = id.substring("minecraft:".length());
            }
            type = EntityType.fromName(id);
        }
        this.entityTag = entity;
    }
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 3 with CompoundTag

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

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 4 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 5 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)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)95 ArrayList (java.util.ArrayList)21 Location (org.bukkit.Location)15 UUID (java.util.UUID)11 IOException (java.io.IOException)8 GlowEntity (net.glowstone.entity.GlowEntity)8 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)8 Material (org.bukkit.Material)7 File (java.io.File)6 NbtOutputStream (net.glowstone.util.nbt.NbtOutputStream)6 BlockEntity (net.glowstone.block.entity.BlockEntity)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 NbtInputStream (net.glowstone.util.nbt.NbtInputStream)5 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 EntityType (org.bukkit.entity.EntityType)4 List (java.util.List)3 GlowBlock (net.glowstone.block.GlowBlock)3 Tag (net.glowstone.util.nbt.Tag)3 Pattern (org.bukkit.block.banner.Pattern)3