Search in sources :

Example 26 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.

the class CraftItemStack method asNMSCopy.

public static net.minecraft.server.v1_12_R1.ItemStack asNMSCopy(ItemStack original) {
    if (original instanceof CraftItemStack) {
        CraftItemStack stack = (CraftItemStack) original;
        return stack.handle == null ? net.minecraft.server.v1_12_R1.ItemStack.a : stack.handle.cloneItemStack();
    }
    if (original == null || original.getTypeId() <= 0) {
        return net.minecraft.server.v1_12_R1.ItemStack.a;
    }
    Item item = CraftMagicNumbers.getItem(original.getType());
    if (item == null) {
        return net.minecraft.server.v1_12_R1.ItemStack.a;
    }
    net.minecraft.server.v1_12_R1.ItemStack stack = new net.minecraft.server.v1_12_R1.ItemStack(item, original.getAmount(), original.getDurability(), false);
    if (original.hasItemMeta()) {
        setItemMeta(stack, original.getItemMeta());
    } else {
        // Converted after setItemMeta
        stack.convertStack();
    }
    return stack;
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) ItemStack(org.bukkit.inventory.ItemStack)

Example 27 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.

the class ItemMetaTest method testBlockStateMeta.

@Test
public void testBlockStateMeta() {
    for (Item item : (Iterable<Item>) Item.REGISTRY) {
        Block block = null;
        if (item instanceof ItemBlock) {
            block = ((ItemBlock) item).getBlock();
        } else if (item instanceof ItemReed) {
            block = ((ItemReed) item).a;
        }
        if (block != null) {
            if (block instanceof ITileEntity) {
                ItemStack stack = CraftItemStack.asNewCraftStack(Item.getItemOf(block));
                // Command blocks aren't unit testable atm
                if (stack.getType() == Material.AIR || stack.getType() == Material.COMMAND || stack.getType() == Material.COMMAND_CHAIN || stack.getType() == Material.COMMAND_REPEATING) {
                    return;
                }
                ItemMeta meta = stack.getItemMeta();
                assertTrue(stack + " has meta of type " + meta + " expected BlockStateMeta", meta instanceof BlockStateMeta);
                BlockStateMeta blockState = (BlockStateMeta) meta;
                assertNotNull(stack + " has null block state", blockState.getBlockState());
                blockState.setBlockState(blockState.getBlockState());
            }
        }
    }
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) Item(net.minecraft.server.v1_12_R1.Item) ITileEntity(net.minecraft.server.v1_12_R1.ITileEntity) Block(net.minecraft.server.v1_12_R1.Block) ItemBlock(net.minecraft.server.v1_12_R1.ItemBlock) ItemBlock(net.minecraft.server.v1_12_R1.ItemBlock) ItemStack(org.bukkit.inventory.ItemStack) ItemReed(net.minecraft.server.v1_12_R1.ItemReed) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Test(org.junit.Test)

Example 28 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item 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 29 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item 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 30 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project MyPet by xXKeyleXx.

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_12_R1.util.inventory.CustomInventory)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)30 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ItemStack (org.bukkit.inventory.ItemStack)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 ArrayList (java.util.ArrayList)10 Player (org.bukkit.entity.Player)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 PreparedStatement (java.sql.PreparedStatement)7 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 Location (org.bukkit.Location)5 OfflinePlayer (org.bukkit.OfflinePlayer)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5