Java 类net.minecraft.server.NBTTagList 实例源码

项目:CraftBukkit    文件:CraftItemStack.java   
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
    NBTTagList list = (item != null && item.hasEnchantments()) ? item.getEnchantments() : null;

    if (list == null || list.size() == 0) {
        return ImmutableMap.of();
    }

    ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();

    for (int i = 0; i < list.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        result.put(Enchantment.getById(id), level);
    }

    return result.build();
}
项目:CraftBukkit    文件:CraftMetaItem.java   
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    if (!tag.hasKey(key.NBT)) {
        return null;
    }

    NBTTagList ench = tag.getList(key.NBT, 10);
    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());

    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        enchantments.put(Enchantment.getById(id), level);
    }

    return enchantments;
}
项目:CraftBukkit    文件:CraftMetaItem.java   
static void applyEnchantments(Map<Enchantment, Integer> enchantments, NBTTagCompound tag, ItemMetaKey key) {
    if (enchantments == null || enchantments.size() == 0) {
        return;
    }

    NBTTagList list = new NBTTagList();

    for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
        NBTTagCompound subtag = new NBTTagCompound();

        subtag.setShort(ENCHANTMENTS_ID.NBT, (short) entry.getKey().getId());
        subtag.setShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue());

        list.add(subtag);
    }

    tag.set(key.NBT, list);
}
项目:CraftBukkit    文件:CraftMetaFirework.java   
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, 10);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());

    for (int i = 0; i < fireworkEffects.size(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
项目:CraftBukkit    文件:CraftMetaFirework.java   
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompound(FIREWORKS.NBT);
    itemTag.set(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new NBTTagList();
        for (FireworkEffect effect : this.effects) {
            effects.add(getExplosion(effect));
        }

        if (effects.size() > 0) {
            fireworks.set(EXPLOSIONS.NBT, effects);
        }
    }

    if (hasPower()) {
        fireworks.setByte(FLIGHT.NBT, (byte) power);
    }
}
项目:CraftBukkit    文件:CraftMetaBook.java   
CraftMetaBook(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(BOOK_TITLE.NBT)) {
        this.title = tag.getString(BOOK_TITLE.NBT);
    }

    if (tag.hasKey(BOOK_AUTHOR.NBT)) {
        this.author = tag.getString(BOOK_AUTHOR.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);
        String[] pageArray = new String[pages.size()];

        for (int i = 0; i < pages.size(); i++) {
            String page = pages.getString(i);
            pageArray[i] = page;
        }

        addPage(pageArray);
    }
}
项目:CraftBukkit    文件:CraftMetaPotion.java   
CraftMetaPotion(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(POTION_EFFECTS.NBT)) {
        NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
        int length = list.size();
        if (length > 0) {
            customEffects = new ArrayList<PotionEffect>(length);

            for (int i = 0; i < length; i++) {
                NBTTagCompound effect = list.get(i);
                PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
                int amp = effect.getByte(AMPLIFIER.NBT);
                int duration = effect.getInt(DURATION.NBT);
                boolean ambient = effect.getBoolean(AMBIENT.NBT);
                customEffects.add(new PotionEffect(type, duration, amp, ambient));
            }
        }
    }
}
项目:CraftBukkit    文件:CraftMetaPotion.java   
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);
    if (hasCustomEffects()) {
        NBTTagList effectList = new NBTTagList();
        tag.set(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInt(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectList.add(effectData);
        }
    }
}
项目:Craftbukkit    文件:CraftBanner.java   
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);

    if (result) {
        banner.color = base.getDyeData();

        NBTTagList newPatterns = new NBTTagList();

        for (Pattern p : patterns) {
            NBTTagCompound compound = new NBTTagCompound();
            compound.setInt("Color", p.getColor().getDyeData());
            compound.setString("Pattern", p.getPattern().getIdentifier());
            newPatterns.add(compound);
        }

        banner.patterns = newPatterns;

        banner.update();
    }

    return result;
}
项目:Craftbukkit    文件:CraftItemStack.java   
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
    NBTTagList list = (item != null && item.hasEnchantments()) ? item.getEnchantments() : null;

    if (list == null || list.size() == 0) {
        return ImmutableMap.of();
    }

    ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();

    for (int i = 0; i < list.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        result.put(Enchantment.getById(id), level);
    }

    return result.build();
}
项目:Craftbukkit    文件:CraftMetaBookSigned.java   
CraftMetaBookSigned(NBTTagCompound tag) {
    super(tag, false);

    boolean resolved = true;
    if (tag.hasKey(RESOLVED.NBT)) {
        resolved = tag.getBoolean(RESOLVED.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);

        for (int i = 0; i < pages.size(); i++) {
            String page = pages.getString(i);
            if (resolved) {
                try {
                    this.pages.add(ChatSerializer.a(page));
                    continue;
                } catch (Exception e) {
                    // Ignore and treat as an old book
                }
            }
            addPage(page);
        }
    }
}
项目:Craftbukkit    文件:CraftMetaItem.java   
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    if (!tag.hasKey(key.NBT)) {
        return null;
    }

    NBTTagList ench = tag.getList(key.NBT, 10);
    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());

    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        enchantments.put(Enchantment.getById(id), level);
    }

    return enchantments;
}
项目:Craftbukkit    文件:CraftMetaItem.java   
static void applyEnchantments(Map<Enchantment, Integer> enchantments, NBTTagCompound tag, ItemMetaKey key) {
    if (enchantments == null || enchantments.size() == 0) {
        return;
    }

    NBTTagList list = new NBTTagList();

    for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
        NBTTagCompound subtag = new NBTTagCompound();

        subtag.setShort(ENCHANTMENTS_ID.NBT, (short) entry.getKey().getId());
        subtag.setShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue());

        list.add(subtag);
    }

    tag.set(key.NBT, list);
}
项目:Craftbukkit    文件:CraftMetaBanner.java   
CraftMetaBanner(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey("BlockEntityTag")) {
        return;
    }

    NBTTagCompound entityTag = tag.getCompound("BlockEntityTag");

    base = entityTag.hasKey(BASE.NBT) ? DyeColor.getByDyeData((byte) entityTag.getInt(BASE.NBT)) : null;

    if (entityTag.hasKey(PATTERNS.NBT)) {
        NBTTagList patterns = entityTag.getList(PATTERNS.NBT, 10);
        for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
            NBTTagCompound p = patterns.get(i);
            this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
        }
    }
}
项目:Craftbukkit    文件:CraftMetaBanner.java   
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);

    NBTTagCompound entityTag = new NBTTagCompound();
    if (base != null) {
        entityTag.setInt(BASE.NBT, base.getDyeData());
    }

    NBTTagList newPatterns = new NBTTagList();

    for (Pattern p : patterns) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInt(COLOR.NBT, p.getColor().getDyeData());
        compound.setString(PATTERN.NBT, p.getPattern().getIdentifier());
        newPatterns.add(compound);
    }
    entityTag.set(PATTERNS.NBT, newPatterns);

    tag.set("BlockEntityTag", entityTag);
}
项目:Craftbukkit    文件:CraftMetaFirework.java   
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, 10);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());

    for (int i = 0; i < fireworkEffects.size(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
项目:Craftbukkit    文件:CraftMetaFirework.java   
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompound(FIREWORKS.NBT);
    itemTag.set(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new NBTTagList();
        for (FireworkEffect effect : this.effects) {
            effects.add(getExplosion(effect));
        }

        if (effects.size() > 0) {
            fireworks.set(EXPLOSIONS.NBT, effects);
        }
    }

    if (hasPower()) {
        fireworks.setByte(FLIGHT.NBT, (byte) power);
    }
}
项目:Craftbukkit    文件:CraftMetaPotion.java   
CraftMetaPotion(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(POTION_EFFECTS.NBT)) {
        NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
        int length = list.size();
        customEffects = new ArrayList<PotionEffect>(length);

        for (int i = 0; i < length; i++) {
            NBTTagCompound effect = list.get(i);
            PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
            int amp = effect.getByte(AMPLIFIER.NBT);
            int duration = effect.getInt(DURATION.NBT);
            boolean ambient = effect.getBoolean(AMBIENT.NBT);
            boolean particles = effect.getBoolean(SHOW_PARTICLES.NBT);
            customEffects.add(new PotionEffect(type, duration, amp, ambient, particles));
        }
    }
}
项目:Craftbukkit    文件:CraftMetaPotion.java   
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);
    if (customEffects != null) {
        NBTTagList effectList = new NBTTagList();
        tag.set(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInt(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectData.setBoolean(SHOW_PARTICLES.NBT, effect.hasParticles());
            effectList.add(effectData);
        }
    }
}
项目:Almura-Server    文件:CraftItemStack.java   
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
    ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();
    NBTTagList list = (item == null) ? null : item.getEnchantments();

    if (list == null) {
        return result.build();
    }

    for (int i = 0; i < list.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        result.put(Enchantment.getById(id), level);
    }

    return result.build();
}
项目:Almura-Server    文件:CraftMetaItem.java   
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    if (!tag.hasKey(key.NBT)) {
        return null;
    }

    NBTTagList ench = tag.getList(key.NBT);
    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());

    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        enchantments.put(Enchantment.getById(id), level);
    }

    return enchantments;
}
项目:Almura-Server    文件:CraftMetaItem.java   
static void applyEnchantments(Map<Enchantment, Integer> enchantments, NBTTagCompound tag, ItemMetaKey key) {
    if (enchantments == null || enchantments.size() == 0) {
        return;
    }

    NBTTagList list = new NBTTagList(key.NBT);

    for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
        NBTTagCompound subtag = new NBTTagCompound();

        subtag.setShort(ENCHANTMENTS_ID.NBT, (short) entry.getKey().getId());
        subtag.setShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue());

        list.add(subtag);
    }

    tag.set(key.NBT, list);
}
项目:Almura-Server    文件:CraftMetaFirework.java   
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());

    for (int i = 0; i < fireworkEffects.size(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
项目:Almura-Server    文件:CraftMetaFirework.java   
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompound(FIREWORKS.NBT);
    itemTag.setCompound(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new NBTTagList(EXPLOSIONS.NBT);
        for (FireworkEffect effect : this.effects) {
            effects.add(getExplosion(effect));
        }

        if (effects.size() > 0) {
            fireworks.set(EXPLOSIONS.NBT, effects);
        }
    }

    if (hasPower()) {
        fireworks.setByte(FLIGHT.NBT, (byte) power);
    }
}
项目:Almura-Server    文件:CraftMetaBook.java   
CraftMetaBook(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(BOOK_TITLE.NBT)) {
        this.title = tag.getString(BOOK_TITLE.NBT);
    }

    if (tag.hasKey(BOOK_AUTHOR.NBT)) {
        this.author = tag.getString(BOOK_AUTHOR.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getList(BOOK_PAGES.NBT);
        String[] pageArray = new String[pages.size()];

        for (int i = 0; i < pages.size(); i++) {
            String page = ((NBTTagString) pages.get(i)).data;
            pageArray[i] = page;
        }

        addPage(pageArray);
    }
}
项目:Almura-Server    文件:CraftMetaPotion.java   
CraftMetaPotion(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(POTION_EFFECTS.NBT)) {
        NBTTagList list = tag.getList(POTION_EFFECTS.NBT);
        int length = list.size();
        if (length > 0) {
            customEffects = new ArrayList<PotionEffect>(length);

            for (int i = 0; i < length; i++) {
                NBTTagCompound effect = (NBTTagCompound) list.get(i);
                PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
                int amp = effect.getByte(AMPLIFIER.NBT);
                int duration = effect.getInt(DURATION.NBT);
                boolean ambient = effect.getBoolean(AMBIENT.NBT);
                customEffects.add(new PotionEffect(type, duration, amp, ambient));
            }
        }
    }
}
项目:Almura-Server    文件:CraftMetaPotion.java   
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);
    if (hasCustomEffects()) {
        NBTTagList effectList = new NBTTagList();
        tag.set(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInt(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectList.add(effectData);
        }
    }
}
项目:Tweakkit-Server    文件:CraftItemStack.java   
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
    NBTTagList list = (item != null && item.hasEnchantments()) ? item.getEnchantments() : null;

    if (list == null || list.size() == 0) {
        return ImmutableMap.of();
    }

    ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();

    for (int i = 0; i < list.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        result.put(Enchantment.getById(id), level);
    }

    return result.build();
}
项目:Tweakkit-Server    文件:CraftMetaItem.java   
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    if (!tag.hasKey(key.NBT)) {
        return null;
    }

    NBTTagList ench = tag.getList(key.NBT, 10);
    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());

    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        // Spigot start - skip invalid enchantments
        Enchantment e = Enchantment.getById(id);
        if (e == null) continue;
        // Spigot end
        enchantments.put(e, level);
    }

    return enchantments;
}
项目:Tweakkit-Server    文件:CraftMetaItem.java   
static void applyEnchantments(Map<Enchantment, Integer> enchantments, NBTTagCompound tag, ItemMetaKey key) {
    if (enchantments == null /*|| enchantments.size() == 0*/) { // Spigot - remove size check
        return;
    }

    NBTTagList list = new NBTTagList();

    for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
        NBTTagCompound subtag = new NBTTagCompound();

        subtag.setShort(ENCHANTMENTS_ID.NBT, (short) entry.getKey().getId());
        subtag.setShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue());

        list.add(subtag);
    }

    tag.set(key.NBT, list);
}
项目:Tweakkit-Server    文件:CraftMetaFirework.java   
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, 10);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());

    for (int i = 0; i < fireworkEffects.size(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
项目:Tweakkit-Server    文件:CraftMetaFirework.java   
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompound(FIREWORKS.NBT);
    itemTag.set(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new NBTTagList();
        for (FireworkEffect effect : this.effects) {
            effects.add(getExplosion(effect));
        }

        if (effects.size() > 0) {
            fireworks.set(EXPLOSIONS.NBT, effects);
        }
    }

    if (hasPower()) {
        fireworks.setByte(FLIGHT.NBT, (byte) power);
    }
}
项目:Tweakkit-Server    文件:CraftMetaBook.java   
CraftMetaBook(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(BOOK_TITLE.NBT)) {
        this.title = limit( tag.getString(BOOK_TITLE.NBT), 1024 ); // Spigot
    }

    if (tag.hasKey(BOOK_AUTHOR.NBT)) {
        this.author = limit( tag.getString(BOOK_AUTHOR.NBT), 1024 ); // Spigot
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);
        String[] pageArray = new String[pages.size()];

        for (int i = 0; i < pages.size(); i++) {
            String page = limit( pages.getString(i), 2048 ); // Spigot
            pageArray[i] = page;
        }

        addPage(pageArray);
    }
}
项目:Tweakkit-Server    文件:CraftMetaPotion.java   
CraftMetaPotion(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(POTION_EFFECTS.NBT)) {
        NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
        int length = list.size();
        if (length > 0) {
            customEffects = new ArrayList<PotionEffect>(length);

            for (int i = 0; i < length; i++) {
                NBTTagCompound effect = list.get(i);
                PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
                int amp = effect.getByte(AMPLIFIER.NBT);
                int duration = effect.getInt(DURATION.NBT);
                boolean ambient = effect.getBoolean(AMBIENT.NBT);
                customEffects.add(new PotionEffect(type, duration, amp, ambient));
            }
        }
    }
}
项目:Tweakkit-Server    文件:CraftMetaPotion.java   
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);
    if (hasCustomEffects()) {
        NBTTagList effectList = new NBTTagList();
        tag.set(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInt(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectList.add(effectData);
        }
    }
}
项目:SpigotSource    文件:CraftBanner.java   
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = (isPlaced()) ? super.update(force, applyPhysics) : true;

    if (result) {
        banner.color = base.getDyeData();

        NBTTagList newPatterns = new NBTTagList();

        for (Pattern p : patterns) {
            NBTTagCompound compound = new NBTTagCompound();
            compound.setInt("Color", p.getColor().getDyeData());
            compound.setString("Pattern", p.getPattern().getIdentifier());
            newPatterns.add(compound);
        }

        banner.patterns = newPatterns;

        banner.update();
    }

    return result;
}
项目:SpigotSource    文件:CraftItemStack.java   
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
    NBTTagList list = (item != null && item.hasEnchantments()) ? item.getEnchantments() : null;

    if (list == null || list.size() == 0) {
        return ImmutableMap.of();
    }

    ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();

    for (int i = 0; i < list.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        result.put(Enchantment.getById(id), level);
    }

    return result.build();
}
项目:SpigotSource    文件:CraftMetaBookSigned.java   
CraftMetaBookSigned(NBTTagCompound tag) {
    super(tag, false);

    boolean resolved = true;
    if (tag.hasKey(RESOLVED.NBT)) {
        resolved = tag.getBoolean(RESOLVED.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);

        for (int i = 0; i < pages.size(); i++) {
            String page = pages.getString(i);
            if (resolved) {
                try {
                    this.pages.add(ChatSerializer.a(page));
                    continue;
                } catch (Exception e) {
                    // Ignore and treat as an old book
                }
            }
            addPage(page);
        }
    }
}
项目:SpigotSource    文件:CraftMetaItem.java   
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    if (!tag.hasKey(key.NBT)) {
        return null;
    }

    NBTTagList ench = tag.getList(key.NBT, 10);
    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());

    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);

        // Spigot start - skip invalid enchantments
        Enchantment e = Enchantment.getById(id);
        if (e == null) continue;
        // Spigot end
        enchantments.put(e, level);
    }

    return enchantments;
}
项目:SpigotSource    文件:CraftMetaItem.java   
static void applyEnchantments(Map<Enchantment, Integer> enchantments, NBTTagCompound tag, ItemMetaKey key) {
    if (enchantments == null /*|| enchantments.size() == 0*/) { // Spigot - remove size check
        return;
    }

    NBTTagList list = new NBTTagList();

    for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
        NBTTagCompound subtag = new NBTTagCompound();

        subtag.setShort(ENCHANTMENTS_ID.NBT, (short) entry.getKey().getId());
        subtag.setShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue());

        list.add(subtag);
    }

    tag.set(key.NBT, list);
}