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

项目:redismine    文件:RedisCheckChunks.java   
/**
 * Not really a test.
 */
@Test
public void checkStoredChunks() throws Exception {
    Jedis jedis = new Jedis("localhost");

    Set<String> keys = jedis.keys("world:*");

    for (String key : keys) {
        byte[] bytes = jedis.get(key.getBytes(UTF_8));
        DataInputStream dataStream = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(bytes)));

        try {
            NBTTagCompound a = NBTCompressedStreamTools.a(dataStream);
        } catch (Exception e) {
            System.out.println("bad chunk at " + key + " (" + bytes.length + " bytes) : " + e);
        }
    }
}
项目: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   
@Overridden
void applyToItem(NBTTagCompound itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, new NBTTagString(displayName));
    }

    if (hasLore()) {
        setDisplayTag(itemTag, LORE.NBT, createStringList(lore));
    }

    applyEnchantments(enchantments, itemTag, ENCHANTMENTS);

    if (hasRepairCost()) {
        itemTag.setInt(REPAIR.NBT, repairCost);
    }

    if (attributes != null) {
        itemTag.set(ATTRIBUTES.NBT, attributes);
    }
}
项目: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   
static NBTTagCompound getExplosion(FireworkEffect effect) {
    NBTTagCompound explosion = new NBTTagCompound();

    if (effect.hasFlicker()) {
        explosion.setBoolean(EXPLOSION_FLICKER.NBT, true);
    }

    if (effect.hasTrail()) {
        explosion.setBoolean(EXPLOSION_TRAIL.NBT, true);
    }

    addColors(explosion, EXPLOSION_COLORS, effect.getColors());
    addColors(explosion, EXPLOSION_FADE, effect.getFadeColors());

    explosion.setByte(EXPLOSION_TYPE.NBT, (byte) getNBT(effect.getType()));

    return explosion;
}
项目: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    文件:CraftMetaBook.java   
@Override
void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    }

    if (hasPages()) {
        itemData.set(BOOK_PAGES.NBT, createStringList(pages));
    }
}
项目: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    文件:CraftOfflinePlayer.java   
public String getName() {
    Player player = getPlayer();
    if (player != null) {
        return player.getName();
    }

    // This might not match lastKnownName but if not it should be more correct
    if (profile.getName() != null) {
        return profile.getName();
    }

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("lastKnownName")) {
            return data.getString("lastKnownName");
        }
    }

    return null;
}
项目:CraftBukkit    文件:CraftOfflinePlayer.java   
public long getFirstPlayed() {
    Player player = getPlayer();
    if (player != null) return player.getFirstPlayed();

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("firstPlayed")) {
            return data.getLong("firstPlayed");
        } else {
            File file = getDataFile();
            return file.lastModified();
        }
    } else {
        return 0;
    }
}
项目:CraftBukkit    文件:CraftOfflinePlayer.java   
public long getLastPlayed() {
    Player player = getPlayer();
    if (player != null) return player.getLastPlayed();

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("lastPlayed")) {
            return data.getLong("lastPlayed");
        } else {
            File file = getDataFile();
            return file.lastModified();
        }
    } else {
        return 0;
    }
}
项目: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    文件:CraftItemStack.java   
public static boolean setItemMeta(net.minecraft.server.ItemStack item, ItemMeta itemMeta) {
    if (item == null) {
        return false;
    }
    if (CraftItemFactory.instance().equals(itemMeta, null)) {
        item.setTag(null);
        return true;
    }
    if (!CraftItemFactory.instance().isApplicable(itemMeta, getType(item))) {
        return false;
    }

    itemMeta = CraftItemFactory.instance().asMetaFor(itemMeta, getType(item));
    if (itemMeta == null) return true;

    NBTTagCompound tag = new NBTTagCompound();
    item.setTag(tag);

    ((CraftMetaItem) itemMeta).applyToItem(tag);

    return true;
}
项目: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   
@Overridden
void applyToItem(NBTTagCompound itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, new NBTTagString(displayName));
    }

    if (hasLore()) {
        setDisplayTag(itemTag, LORE.NBT, createStringList(lore));
    }

    if (hideFlag != 0) {
        itemTag.setInt(HIDEFLAGS.NBT, hideFlag);
    }

    applyEnchantments(enchantments, itemTag, ENCHANTMENTS);

    if (hasRepairCost()) {
        itemTag.setInt(REPAIR.NBT, repairCost);
    }

    for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
        itemTag.set(e.getKey(), e.getValue());
    }
}
项目: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   
static NBTTagCompound getExplosion(FireworkEffect effect) {
    NBTTagCompound explosion = new NBTTagCompound();

    if (effect.hasFlicker()) {
        explosion.setBoolean(EXPLOSION_FLICKER.NBT, true);
    }

    if (effect.hasTrail()) {
        explosion.setBoolean(EXPLOSION_TRAIL.NBT, true);
    }

    addColors(explosion, EXPLOSION_COLORS, effect.getColors());
    addColors(explosion, EXPLOSION_FADE, effect.getFadeColors());

    explosion.setByte(EXPLOSION_TYPE.NBT, (byte) getNBT(effect.getType()));

    return explosion;
}
项目: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);
        }
    }
}
项目:Craftbukkit    文件:CraftOfflinePlayer.java   
public String getName() {
    Player player = getPlayer();
    if (player != null) {
        return player.getName();
    }

    // This might not match lastKnownName but if not it should be more correct
    if (profile.getName() != null) {
        return profile.getName();
    }

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("lastKnownName")) {
            return data.getString("lastKnownName");
        }
    }

    return null;
}
项目:Craftbukkit    文件:CraftOfflinePlayer.java   
public long getFirstPlayed() {
    Player player = getPlayer();
    if (player != null) return player.getFirstPlayed();

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("firstPlayed")) {
            return data.getLong("firstPlayed");
        } else {
            File file = getDataFile();
            return file.lastModified();
        }
    } else {
        return 0;
    }
}
项目:Craftbukkit    文件:CraftOfflinePlayer.java   
public long getLastPlayed() {
    Player player = getPlayer();
    if (player != null) return player.getLastPlayed();

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("lastPlayed")) {
            return data.getLong("lastPlayed");
        } else {
            File file = getDataFile();
            return file.lastModified();
        }
    } else {
        return 0;
    }
}
项目: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   
@Overridden
void applyToItem(NBTTagCompound itemTag) {
    if (hasDisplayName()) {
        setDisplayTag(itemTag, NAME.NBT, new NBTTagString(NAME.NBT, displayName));
    }

    if (hasLore()) {
        setDisplayTag(itemTag, LORE.NBT, createStringList(lore, LORE));
    }

    applyEnchantments(enchantments, itemTag, ENCHANTMENTS);

    if (hasRepairCost()) {
        itemTag.setInt(REPAIR.NBT, repairCost);
    }

    if (attributes != null) {
        itemTag.set(ATTRIBUTES.NBT, attributes);
    }
}
项目: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   
static NBTTagCompound getExplosion(FireworkEffect effect) {
    NBTTagCompound explosion = new NBTTagCompound();

    if (effect.hasFlicker()) {
        explosion.setBoolean(EXPLOSION_FLICKER.NBT, true);
    }

    if (effect.hasTrail()) {
        explosion.setBoolean(EXPLOSION_TRAIL.NBT, true);
    }

    addColors(explosion, EXPLOSION_COLORS, effect.getColors());
    addColors(explosion, EXPLOSION_FADE, effect.getFadeColors());

    explosion.setByte(EXPLOSION_TYPE.NBT, (byte) getNBT(effect.getType()));

    return explosion;
}
项目: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);
    }
}