Search in sources :

Example 36 with NBTTagCompound

use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_8_R3.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_8_R3.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ListTag(com.wasteofplastic.org.jnbt.ListTag) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 37 with NBTTagCompound

use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_8_R2.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_8_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R2.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_8_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_8_R2.NBTTagString) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ListTag(com.wasteofplastic.org.jnbt.ListTag) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 38 with NBTTagCompound

use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_9_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_9_R1.NBTTagCompound) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)

Example 39 with NBTTagCompound

use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_9_R2.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_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R2.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) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 40 with NBTTagCompound

use of net.minecraft.server.v1_8_R1.NBTTagCompound in project solinia3-core by mixxit.

the class SoliniaItemFactory method CreateItem.

public static ISoliniaItem CreateItem(ItemStack itemStack, boolean operatorCreated) throws SoliniaItemException, CoreStateInitException {
    SoliniaItem item = new SoliniaItem();
    item.setOperatorCreated(operatorCreated);
    item.setId(StateManager.getInstance().getConfigurationManager().getNextItemId());
    item.setBasename(itemStack.getType().name());
    item.setDisplayname(itemStack.getType().name());
    if (itemStack.getData() != null) {
        try {
            item.setColor(itemStack.getData().getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (itemStack.getType().name().equals("SKULL_ITEM")) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(itemStack);
        NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
        tag.getCompound("SkullOwner").getString("Id");
        String texturevalue = tag.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10).get(0).getString("Value");
        item.setTexturebase64(texturevalue);
    }
    StateManager.getInstance().getConfigurationManager().addItem(item);
    System.out.println("New Item Added: " + item.getId() + " - " + item.getDisplayname());
    return item;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItem(com.solinia.solinia.Models.SoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 Map (java.util.Map)30 ArrayList (java.util.ArrayList)21 ItemMeta (org.bukkit.inventory.meta.ItemMeta)21 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)19 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)12 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)12 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)12 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 HashMap (java.util.HashMap)8 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)7 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)7 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)6