@Override public int first(int materialId) { int i = 0; for (ItemStack slotItem : this) { if (slotItem == null) { if (materialId == 0) { return i; } } else if (slotItem.getTypeId() == materialId) { return i; } i++; } return -1; }
@Override public boolean contains(ItemStack item, int amount) { return contains(item.getTypeId(), amount); }
@Override public HashMap<Integer, ItemStack> all(int materialId) { HashMap<Integer, ItemStack> result = new HashMap<>(); int i = 0; for (ItemStack slotItem : this) { if (!InventoryUtil.isEmpty(slotItem) && slotItem.getTypeId() == materialId) { result.put(i, InventoryUtil.itemOrEmpty(slotItem)); } i++; } return result; }
/** * Gets the type of this item * * @return Type of the items in this stack */ @Utility public Material getType() { return getType0(getTypeId()); }
@Override @Utility public final int hashCode() { int hash = 1; hash = hash * 31 + getTypeId(); hash = hash * 31 + getAmount(); hash = hash * 31 + (getDurability() & 0xffff); hash = hash * 31 + (hasItemMeta() ? (meta == null ? getItemMeta().hashCode() : meta.hashCode()) : 0); return hash; }
/** * Write an item stack to the buffer. * * @param buf The buffer. * @param stack The stack to write, or null. */ public static void writeSlot(ByteBuf buf, ItemStack stack) { if (InventoryUtil.isEmpty(stack)) { buf.writeShort(-1); } else { buf.writeShort(stack.getTypeId()); buf.writeByte(stack.getAmount()); buf.writeShort(stack.getDurability()); if (stack.hasItemMeta()) { CompoundTag tag = GlowItemFactory.instance().writeNbt(stack.getItemMeta()); writeCompound(buf, tag); } else { writeCompound(buf, null); } } }
/** * This method is the same as equals, but does not consider stack size * (amount). * * @param stack the item stack to compare to * @return true if the two stacks are equal, ignoring the amount */ @Utility public boolean isSimilar(ItemStack stack) { if (stack == null) { return false; } if (stack == this) { return true; } return getTypeId() == stack.getTypeId() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta()) : true); }
/** * Creates a new item stack derived from the specified stack * * @param stack the stack to copy * @throws IllegalArgumentException if the specified stack is null or * returns an item meta not created by the item factory */ public ItemStack(final ItemStack stack) throws IllegalArgumentException { Validate.notNull(stack, "Cannot copy null stack"); this.type = stack.getTypeId(); this.amount = stack.getAmount(); this.durability = stack.getDurability(); this.data = stack.getData(); if (stack.hasItemMeta()) { setItemMeta0(stack.getItemMeta(), getType0()); } }
@Override @Deprecated public int clear(int id, int data) { int numCleared = 0; for (int i = 0; i < getSize(); ++i) { ItemStack stack = getItem(i); if (stack != null && (id == -1 || stack.getTypeId() == id) && (data == -1 || stack.getData().getData() == data)) { setItem(i, InventoryUtil.createEmptyStack()); if (!InventoryUtil.isEmpty(stack)) { // never report AIR as removed - else will report all empty slots cleared numCleared += stack.getAmount(); // report # items, not # stacks removed } } } return numCleared; }
return new int[]{item.getTypeId(), item.getDurability()};
@SuppressWarnings("deprecation") public static int getTypeId(ItemStack item) { return item.getTypeId(); }
/** * Gets the type of this item * * @return Type of the items in this stack */ @Utility public Material getType() { return getType0(getTypeId()); }
@Override @Utility public final int hashCode() { int hash = 1; hash = hash * 31 + getTypeId(); hash = hash * 31 + getAmount(); hash = hash * 31 + (getDurability() & 0xffff); hash = hash * 31 + (hasItemMeta() ? (meta == null ? getItemMeta().hashCode() : meta.hashCode()) : 0); return hash; }
public static Item convert(ItemStack itemInHand) { if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null); return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null); } }
public int getBlockID() { return getMyPet().getBlock() != null ? getMyPet().getBlock().getTypeId() : 0; }
/** * @param item */ public ItemStackEntry(ItemStack item) { this.typeId = item.getTypeId(); this.data = item.getData().getData(); this.durability = item.getDurability(); this.enchantments = item.getEnchantments(); this.amount = item.getAmount(); }
/** * Transfers the item type, data and enchantments from one item stack to the other * * @param from which Item Stack to read the info * @param to which Item Stack to transfer the info to */ @SuppressWarnings("deprecation") public static void transferInfo(org.bukkit.inventory.ItemStack from, org.bukkit.inventory.ItemStack to) { // Transfer type, durability and any other remaining metadata information to.setTypeId(from.getTypeId()); to.setDurability(from.getDurability()); setMetaTag(to, LogicUtil.clone(getMetaTag(from))); }
public static boolean hasItems(Player player, BlockTypeEntry item, int amount) { for (ItemStack i : player.getInventory()) { if (i == null) { continue; } if (i.getTypeId() == item.getTypeId()) { if (item.getData() == 0 || i.getData().getData() == item.getData()) { amount -= i.getAmount(); } } } return amount <= 0; }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent e) { HumanEntity human = e.getWhoClicked(); if (human instanceof Player && e.getInventory() instanceof CraftingInventory) { final Player player = (Player) human; if (e.getCurrentItem() != null) { if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) { sendDelayedArmorUpdate(player); return; } } if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) { sendDelayedArmorUpdate(player); } } }