Search in sources :

Example 31 with CompoundTag

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

the class GlowMetaItem method readNbtEnchants.

protected static Map<Enchantment, Integer> readNbtEnchants(String name, CompoundTag tag) {
    Map<Enchantment, Integer> result = null;
    if (tag.isList(name, TagType.COMPOUND)) {
        Iterable<CompoundTag> enchs = tag.getCompoundList(name);
        for (CompoundTag enchantmentTag : enchs) {
            if (enchantmentTag.isShort("id") && enchantmentTag.isShort("lvl")) {
                Enchantment enchantment = Enchantment.getById(enchantmentTag.getShort("id"));
                if (result == null)
                    result = new HashMap<>(4);
                result.put(enchantment, (int) enchantmentTag.getShort("lvl"));
            }
        }
    }
    return result;
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 32 with CompoundTag

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

the class GlowMetaItem method writeNbtEnchants.

protected static void writeNbtEnchants(String name, CompoundTag to, Map<Enchantment, Integer> enchants) {
    List<CompoundTag> ench = new ArrayList<>();
    for (Entry<Enchantment, Integer> enchantment : enchants.entrySet()) {
        CompoundTag enchantmentTag = new CompoundTag();
        enchantmentTag.putShort("id", enchantment.getKey().getId());
        enchantmentTag.putShort("lvl", enchantment.getValue());
        ench.add(enchantmentTag);
    }
    to.putCompoundList(name, ench);
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 33 with CompoundTag

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

the class GlowMetaLeatherArmor method writeNbt.

@Override
void writeNbt(CompoundTag tag) {
    super.writeNbt(tag);
    if (hasColor()) {
        CompoundTag display = new CompoundTag();
        display.putInt("color", color.asRGB());
        tag.putCompound("display", display);
    }
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 34 with CompoundTag

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

the class GlowItemFactory method writeNbt.

public CompoundTag writeNbt(ItemMeta meta) {
    CompoundTag result = new CompoundTag();
    toGlowMeta(meta).writeNbt(result);
    return result.isEmpty() ? null : result;
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 35 with CompoundTag

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

the class GlowMetaSpawn method writeNbt.

@Override
void writeNbt(CompoundTag tag) {
    super.writeNbt(tag);
    CompoundTag entityTag = getEntityTag() != null ? getEntityTag() : new CompoundTag();
    if (hasSpawnedType()) {
        entityTag.putString("id", "minecraft:" + getSpawnedType().getName());
    }
    tag.putCompound("EntityTag", entityTag);
}
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