Search in sources :

Example 46 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
 */
public ItemStack getSpawnEgg(EntityType type, int amount) {
    // Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    // Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
    NBTTagCompound id = new NBTTagCompound();
    if (!bToMConversion.containsKey(type)) {
        id.setString("id", "minecraft:" + type.toString().toLowerCase());
    } else {
        id.setString("id", "minecraft:" + bToMConversion.get(type));
    }
    tagCompound.set("EntityTag", id);
    stack.setTag(tagCompound);
    // Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
    return CraftItemStack.asBukkitCopy(stack);
}
Also used : NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)

Example 47 with NBTTagCompound

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

the class NMSHandler method setPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag)
     */
@SuppressWarnings({ "unchecked" })
@Override
public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) {
    Map<String, Tag> cont = (Map<String, Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag) contents.get("Potion"));
            if (stringTag != null) {
                String tag = ((StringTag) contents.get("Potion")).getValue();
                // Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag);
                net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
                NBTTagCompound tagCompound = stack.getTag();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                tagCompound.setString("Potion", tag);
                stack.setTag(tagCompound);
                return CraftItemStack.asBukkitCopy(stack);
            }
        }
    }
    // Schematic is old, the potions do not have tags
    // Set it to zero so that the potion bottles don't look like giant purple and black blocks
    chestItem.setDurability((short) 0);
    Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water.");
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 48 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
 */
public ItemStack getSpawnEgg(EntityType type, int amount) {
    // Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    // Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
    NBTTagCompound id = new NBTTagCompound();
    if (!bToMConversion.containsKey(type)) {
        id.setString("id", "minecraft:" + type.toString().toLowerCase());
    } else {
        id.setString("id", "minecraft:" + bToMConversion.get(type));
    }
    tagCompound.set("EntityTag", id);
    stack.setTag(tagCompound);
    // Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
    return CraftItemStack.asBukkitCopy(stack);
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 49 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_12_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_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_12_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_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 50 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_7_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_7_R3.NBTTagCompound) NBTTagString(net.minecraft.server.v1_7_R3.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_7_R3.NBTTagList) NBTTagString(net.minecraft.server.v1_7_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_7_R3.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