org.bukkit.craftbukkit.inventory.CraftItemStack Java Examples

The following examples show how to use org.bukkit.craftbukkit.inventory.CraftItemStack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftMagicNumbers.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack modifyItemStack(ItemStack stack, String arguments) {
    net.minecraft.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);

    try
    {
        nmsStack.setTagCompound((net.minecraft.nbt.NBTTagCompound) net.minecraft.nbt.JsonToNBT.func_150315_a(arguments));
    }
    catch (net.minecraft.nbt.NBTException e)
    {
        e.printStackTrace();
    }

    stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack));

    return stack;
}
 
Example #2
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static void handleEditBookEvent(EntityPlayerMP player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.WRITABLE_BOOK) {
        if (!editBookEvent.isCancelled()) {
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
            CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta();
            List<ITextComponent> pages = meta.pages;
            for (int i = 0; i < pages.size(); i++) {
                pages.set(i, stripEvents(pages.get(i)));
            }
            CraftItemStack.setItemMeta(itemInHand, meta);
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.openContainer.getSlotFromInventory(player.inventory, itemInHandIndex);
        player.connection.sendPacket(new SPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
 
Example #3
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static EntityDeathEvent callEntityDeathEvent(EntityLivingBase victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    // CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();
    // Kettle start - clear captured drops to allow plugins make changes to them
    victim.capturedDrops.clear();
    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
        net.minecraft.entity.item.EntityItem entityitem = new net.minecraft.entity.item.EntityItem(victim.world, entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ(), CraftItemStack.asNMSCopy(stack));
        // world.dropItemNaturally(entity.getLocation(), stack); we don't want this, spawn items in EntityLivingBase.onDeath() (cauldron stuff)
        victim.capturedDrops.add(entityitem);
    }
    // Kettle end
    return event;
}
 
Example #4
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityPlayer who, int clickedX, int clickedY, int clickedZ, EnumFacing clickedFace, ItemStack itemstack, net.minecraft.item.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #5
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void showFakeItems(Plugin plugin, Player viewer, Location location, org.bukkit.inventory.ItemStack item, int count, Duration duration) {
    if(count <= 0) return;

    final EntityPlayer nmsPlayer = ((CraftPlayer) viewer).getHandle();
    final int[] entityIds = new int[count];

    for(int i = 0; i < count; i++) {
        final EntityItem entity = new EntityItem(nmsPlayer.getWorld(), location.getX(), location.getY(), location.getZ(), CraftItemStack.asNMSCopy(item));

        entity.motX = randomEntityVelocity();
        entity.motY = randomEntityVelocity();
        entity.motZ = randomEntityVelocity();

        sendPacket(viewer, new PacketPlayOutSpawnEntity(entity, ENTITY_TYPE_IDS.get(org.bukkit.entity.Item.class)));
        sendPacket(viewer, new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));

        entityIds[i] = entity.getId();
    }

    scheduleEntityDestroy(plugin, viewer.getUniqueId(), duration, entityIds);
}
 
Example #6
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
 
Example #7
Source File: CardinalNotifications.java    From CardinalPGM with MIT License 6 votes vote down vote up
public void UpdateNotificationAndBook(){
    Bukkit.getScheduler().runTaskAsynchronously(Cardinal.getInstance(), new Runnable() {
        @Override
        public void run() {
            try {
                chat = ComponentSerializer.parse(GitUtil.getUpdateMessage(notificationUrl));

                ItemStack NMSbook = new ItemStack(Item.getById(387));
                try {
                    NBTBase nbtbase = MojangsonParser.parse(ChatColor.translateAlternateColorCodes('`', GitUtil.getUpdateMessage(bookUrl)));
                    NMSbook.setTag((NBTTagCompound) nbtbase);
                } catch (MojangsonParseException mojangsonparseexception) {
                    Bukkit.getConsoleSender().sendMessage(mojangsonparseexception.getMessage());
                    return;
                }
                book = CraftItemStack.asBukkitCopy(NMSbook);
            } catch (IOException ignored) {
            }
        }
    });
}
 
Example #8
Source File: CraftThrownPotion.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setItem(ItemStack item) {
    // The ItemStack must not be null.
    Validate.notNull(item, "ItemStack cannot be null.");

    // The ItemStack must be a potion.
    Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");

    getHandle().potionDamage = CraftItemStack.asNMSCopy(item);
}
 
Example #9
Source File: CraftHumanEntity.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setItemOnCursor(ItemStack item) {
    net.minecraft.item.ItemStack stack = CraftItemStack.asNMSCopy(item);
    getHandle().inventory.setItemStack(stack);
    if (this instanceof CraftPlayer) {
        ((net.minecraft.entity.player.EntityPlayerMP) getHandle()).updateHeldItem(); // Send set slot for cursor
    }
}
 
Example #10
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) {
    CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory);
    inventory.setResult(CraftItemStack.asCraftMirror(result));

    PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair);
    Bukkit.getPluginManager().callEvent(event);

    org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult();

    return CraftItemStack.asNMSCopy(bitem);
}
 
Example #11
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
static ItemStack asNMS(org.bukkit.inventory.ItemStack bukkit) {
    if(bukkit instanceof CraftItemStack) {
        return ((CraftItemStack) bukkit).getHandle();
    } else {
        return CraftItemStack.asNMSCopy(bukkit);
    }
}
 
Example #12
Source File: CraftItemFrame.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setItem(org.bukkit.inventory.ItemStack item) {
    if (item == null || item.getTypeId() == 0) {
        getHandle().getDataWatcher().addObjectByDataType(2, 5);
        getHandle().getDataWatcher().setObjectWatched(2);
    } else {
        getHandle().setDisplayedItem(CraftItemStack.asNMSCopy(item));
    }
}
 
Example #13
Source File: CraftMagicNumbers.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack modifyItemStack(ItemStack stack, String arguments) {
    net.minecraft.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);

    try {
        nmsStack.setTagCompound((NBTTagCompound) JsonToNBT.getTagFromJson(arguments));
    } catch (NBTException ex) {
        Logger.getLogger(CraftMagicNumbers.class.getName()).log(Level.SEVERE, null, ex);
    }

    stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack));

    return stack;
}
 
Example #14
Source File: FishingInterface.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
private static net.minecraft.util.WeightedRandomFishable toNms(WeightedRandomFishable bukkit) {
    net.minecraft.util.WeightedRandomFishable ret =
            new net.minecraft.util.WeightedRandomFishable(
                    CraftItemStack.asNMSCopy(bukkit.getItemStack()),
                    bukkit.getWeight()).func_150709_a(bukkit.getDamageFraction());
    if (bukkit.hasRandomEnchantments()) {
        ret.func_150707_a();
    }
    return ret;
}
 
Example #15
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static EntityBreedEvent callEntityBreedEvent(EntityLivingBase child, EntityLivingBase mother, EntityLivingBase father, EntityLivingBase breeder, ItemStack bredWith, int experience) {
    LivingEntity breederEntity = (LivingEntity) (breeder == null ? null : breeder.getBukkitEntity());
    CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone();

    EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience);
    child.world.getServer().getPluginManager().callEvent(event);
    return event;
}
 
Example #16
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(net.minecraft.entity.EntityLivingBase who, net.minecraft.item.ItemStack itemstack, net.minecraft.entity.projectile.EntityArrow entityArrow, float force) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Arrow arrow = (Arrow) entityArrow.getBukkitEntity();

    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }

    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
    Bukkit.getPluginManager().callEvent(event);

    return event;
}
 
Example #17
Source File: CraftBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public Collection<ItemStack> getDrops() {
    List<ItemStack> drops = new ArrayList<ItemStack>();

    net.minecraft.block.Block block = this.getNMSBlock();
    if (block != Blocks.air) {
        byte data = getData();
        // based on nms.Block.dropNaturally
        int count = block.quantityDroppedWithBonus(0, chunk.getHandle().worldObj.rand);
        for (int i = 0; i < count; ++i) {
            Item item = block.getItemDropped(data, chunk.getHandle().worldObj.rand, 0);
            if (item != null) {
                // Skulls are special, their data is based on the tile entity
                if (Blocks.skull == block) {
                    net.minecraft.item.ItemStack nmsStack = new net.minecraft.item.ItemStack(item, 1, block.getDamageValue(chunk.getHandle().worldObj, x, y, z));
                    TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().worldObj.getTileEntity(x, y, z);

                    if (tileentityskull.func_145904_a() == 3 && tileentityskull.func_152108_a() != null) {
                        nmsStack.setTagCompound(new NBTTagCompound());
                        NBTTagCompound nbttagcompound = new NBTTagCompound();

                        NBTUtil.func_152460_a(nbttagcompound, tileentityskull.func_152108_a());
                        nmsStack.getTagCompound().setTag("SkullOwner", nbttagcompound);
                    }

                    drops.add(CraftItemStack.asBukkitCopy(nmsStack));
                    // We don't want to drop cocoa blocks, we want to drop cocoa beans.
                } else if (Blocks.cocoa == block) {
                    int dropAmount = (BlockCocoa.func_149987_c(data) >= 2 ? 3 : 1);
                    for (int j = 0; j < dropAmount; ++j) {
                        drops.add(new ItemStack(Material.INK_SACK, 1, (short) 3));
                    }
                } else {
                    drops.add(new ItemStack(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(item), 1, (short) block.damageDropped(data)));
                }
            }
        }
    }
    return drops;
}
 
Example #18
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static PlayerItemMendEvent callPlayerItemMendEvent(EntityPlayer entity, EntityXPOrb orb, ItemStack nmsMendedItem, int repairAmount) {
    Player player = (Player) entity.getBukkitEntity();
    org.bukkit.inventory.ItemStack bukkitStack = CraftItemStack.asCraftMirror(nmsMendedItem);
    PlayerItemMendEvent event = new PlayerItemMendEvent(player, bukkitStack, (ExperienceOrb) orb.getBukkitEntity(), repairAmount);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
 
Example #19
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(EntityPlayer who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(x, y, z);

    BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #20
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(EntityLivingBase who, ItemStack itemstack, EntityArrow entityArrow, float force) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Arrow arrow = (Arrow) entityArrow.getBukkitEntity();

    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }

    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
    Bukkit.getPluginManager().callEvent(event);

    return event;
}
 
Example #21
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static PlayerInteractEvent callPlayerInteractEvent(EntityPlayer who, Action action, BlockPos position, EnumFacing direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = null;
    if (position != null) {
        blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
    } else {
        switch (action) {
            case LEFT_CLICK_BLOCK:
                action = Action.LEFT_CLICK_AIR;
                break;
            case RIGHT_CLICK_BLOCK:
                action = Action.RIGHT_CLICK_AIR;
                break;
        }
    }
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);

    if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
        itemInHand = null;
    }

    PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
    if (cancelledBlock) {
        event.setUseInteractedBlock(Event.Result.DENY);
    }
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #22
Source File: OreDictionaryInterface.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<OreDictionaryEntry> getOreEntries(ItemStack itemStack) {
    int[] ids = OreDictionary.getOreIDs(CraftItemStack.asNMSCopy(itemStack));

    ImmutableList.Builder<OreDictionaryEntry> builder = ImmutableList.builder();
    for (int id : ids) {
        builder.add(OreDictionaryEntry.valueOf(id));
    }

    return builder.build();
}
 
Example #23
Source File: OreDictionaryInterface.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> getDefinitions(OreDictionaryEntry entry) {
    @SuppressWarnings("deprecation")
    List<net.minecraft.item.ItemStack> items = OreDictionary.getOres(entry.getId());

    ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
    for (net.minecraft.item.ItemStack nmsItem : items) {
        builder.add(CraftItemStack.asCraftMirror(nmsItem));
    }

    return builder.build();
}
 
Example #24
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Collection<ItemStack> getDrops() {
    List<ItemStack> drops = new ArrayList<ItemStack>();

    net.minecraft.block.Block block = this.getNMSBlock();
    if (block != Blocks.AIR) {
        IBlockState data = getData0();
        // based on nms.Block.dropNaturally
        int count = block.quantityDroppedWithBonus(0, chunk.getHandle().getWorld().rand);
        for (int i = 0; i < count; ++i) {
            Item item = block.getItemDropped(data, chunk.getHandle().getWorld().rand, 0);
            if (item != Items.AIR) {
                // Skulls are special, their data is based on the tile entity
                if (Blocks.SKULL == block) {
                    net.minecraft.item.ItemStack nmsStack = new net.minecraft.item.ItemStack(item, 1, block.damageDropped(data));
                    TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().getWorld().getTileEntity(new BlockPos(x, y, z));

                    if (tileentityskull.getSkullType() == 3 && tileentityskull.getPlayerProfile() != null) {
                        nmsStack.setTagCompound(new NBTTagCompound());
                        NBTTagCompound nbttagcompound = new NBTTagCompound();

                        NBTUtil.writeGameProfile(nbttagcompound, tileentityskull.getPlayerProfile());
                        nmsStack.getTagCompound().setTag("SkullOwner", nbttagcompound);
                    }

                    drops.add(CraftItemStack.asBukkitCopy(nmsStack));
                    // We don't want to drop cocoa blocks, we want to drop cocoa beans.
                } else if (Blocks.COCOA == block) {
                    int age = (Integer) data.getValue(BlockCocoa.AGE);
                    int dropAmount = (age >= 2 ? 3 : 1);
                    for (int j = 0; j < dropAmount; ++j) {
                        drops.add(new ItemStack(Material.INK_SACK, 1, (short) 3));
                    }
                } else {
                    drops.add(new ItemStack(CraftMagicNumbers.getMaterial(item), 1, (short) block.damageDropped(data)));
                }
            }
        }
    }
    return drops;
}
 
Example #25
Source File: CraftWorld.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Item dropItem(Location loc, ItemStack item) {
    Validate.notNull(item, "Cannot drop a Null item.");
    Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR.");
    EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
    entity.pickupDelay = 10;
    world.spawnEntity(entity, SpawnReason.CUSTOM);
    // TODO this is inconsistent with how Entity.getBukkitEntity() works.
    // However, this entity is not at the moment backed by a server entity class so it may be left.
    return new CraftItem(world.getServer(), entity);
}
 
Example #26
Source File: CraftSplashPotion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setItem(ItemStack item) {
    // The ItemStack must not be null.
    Validate.notNull(item, "ItemStack cannot be null.");

    // The ItemStack must be a potion.
    Validate.isTrue(item.getType() == Material.SPLASH_POTION, "ItemStack must be a splash potion. This item stack was " + item.getType() + ".");

    getHandle().setItem(CraftItemStack.asNMSCopy(item));
}
 
Example #27
Source File: CraftLingeringPotion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void setItem(ItemStack item) {
    // The ItemStack must not be null.
    Validate.notNull(item, "ItemStack cannot be null.");

    // The ItemStack must be a potion.
    Validate.isTrue(item.getType() == Material.LINGERING_POTION, "ItemStack must be a lingering potion. This item stack was " + item.getType() + ".");

    getHandle().setItem(CraftItemStack.asNMSCopy(item));
}
 
Example #28
Source File: CraftThrownPotion.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public ItemStack getItem() {
    return CraftItemStack.asBukkitCopy(getHandle().getPotion());
}
 
Example #29
Source File: Items.java    From CardinalPGM with MIT License 4 votes vote down vote up
public static boolean itemsEqual(ItemStack item1, ItemStack item2) {
    if (!item1.getType().equals(item2.getType())) return false;
    return toMaxDurability(item1).isSimilar(toMaxDurability(item2)) || CraftItemStack.asCraftCopy(item1).getHandle().getTag().equals(CraftItemStack.asCraftCopy(item2).getHandle().getTag());
}
 
Example #30
Source File: NMS.java    From CardinalPGM with MIT License 4 votes vote down vote up
public static NBTTagCompound getItemNBT(ItemStack item) {
    return item instanceof CraftItemStack ? ((CraftItemStack) item).getHandle().c(TAG) : new NBTTagCompound();
}