Search in sources :

Example 41 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    // TODO allow items like FIRE (51)
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    if (icon.getTags() != null) {
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) NBTTagCompound(net.minecraft.server.v1_9_R1.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_9_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) ItemStack(net.minecraft.server.v1_9_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)

Example 42 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project MyPet by xXKeyleXx.

the class ItemStackComparator method compareTagData.

public static boolean compareTagData(ItemStack i1, ItemStack i2) {
    if (i1.hasItemMeta() && i2.hasItemMeta()) {
        NBTTagCompound tag1 = CraftItemStack.asNMSCopy(i1).getTag();
        NBTTagCompound tag2 = CraftItemStack.asNMSCopy(i2).getTag();
        return tag1 != null && tag2 != null && tag1.equals(tag2);
    }
    return i1.hasItemMeta() == i2.hasItemMeta();
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R1.NBTTagCompound)

Example 43 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    // TODO allow items like FIRE (51)
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    if (icon.getTags() != null) {
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ItemStack(net.minecraft.server.v1_9_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)

Example 44 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project acidisland by tastybento.

the class NMSHandler method getSpawnEgg.

/**
 * Get spawn egg
 * @param type
 * @param amount
 * @return
 */
@SuppressWarnings("deprecation")
public ItemStack getSpawnEgg(EntityType type, int amount) {
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    NBTTagCompound id = new NBTTagCompound();
    id.setString("id", type.getName());
    tagCompound.set("EntityTag", id);
    stack.setTag(tagCompound);
    return CraftItemStack.asBukkitCopy(stack);
}
Also used : NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 45 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project acidisland by tastybento.

the class NMSHandler method setBook.

@Override
public ItemStack setBook(Tag item) {
    ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
    // Bukkit.getLogger().info(item.toString());
    if (((CompoundTag) item).getValue().containsKey("tag")) {
        Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
        // BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
        String author = "";
        if (contents.containsKey("author")) {
            author = ((StringTag) contents.get("author")).getValue();
        }
        // Bukkit.getLogger().info("Author: " + author);
        // bookMeta.setAuthor(author);
        String title = "";
        if (contents.containsKey("title")) {
            title = ((StringTag) contents.get("title")).getValue();
        }
        // Bukkit.getLogger().info("Title: " + title);
        // bookMeta.setTitle(title);
        List<String> lore = new ArrayList<String>();
        if (contents.containsKey("display")) {
            Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
            List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
            for (Tag s : loreTag) {
                lore.add(((StringTag) s).getValue());
            }
        }
        // Bukkit.getLogger().info("Lore: " + lore);
        net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
        // Pages
        // Create the NMS Stack's NBT (item data)
        NBTTagCompound tag = new NBTTagCompound();
        // Set the book's title
        tag.setString("title", title);
        tag.setString("author", author);
        if (contents.containsKey("pages")) {
            NBTTagList pages = new NBTTagList();
            List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
            for (Tag s : pagesTag) {
                pages.add(new NBTTagString(((StringTag) s).getValue()));
            }
            // Add the pages to the tag
            tag.set("pages", pages);
        }
        // Apply the tag to the item
        stack.setTag(tag);
        chestItem = CraftItemStack.asCraftMirror(stack);
        ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
        bookMeta.setLore(lore);
        chestItem.setItemMeta(bookMeta);
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)17 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)15 ListTag (com.wasteofplastic.org.jnbt.ListTag)15 StringTag (com.wasteofplastic.org.jnbt.StringTag)15 Tag (com.wasteofplastic.org.jnbt.Tag)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)10 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)5 GameProfile (com.mojang.authlib.GameProfile)4 Property (com.mojang.authlib.properties.Property)4 HashMap (java.util.HashMap)4