Java Code Examples for net.runelite.api.ItemContainer#getItems()
The following examples show how to use
net.runelite.api.ItemContainer#getItems() .
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: PuzzleSolverOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private int[] getItemIds(ItemContainer container, boolean useNormalSolver) { int[] itemIds = new int[DIMENSION * DIMENSION]; Item[] items = container.getItems(); for (int i = 0; i < items.length; i++) { itemIds[i] = items[i].getId(); } // If blank is in the last position, items doesn't contain it, so let's add it manually if (itemIds.length > items.length) { itemIds[items.length] = BLANK_TILE_VALUE; } return convertToSolverFormat(itemIds, useNormalSolver); }
Example 2
Source File: BankPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private Multiset<Integer> getBankItemSet() { ItemContainer itemContainer = client.getItemContainer(InventoryID.BANK); if (itemContainer == null) { return HashMultiset.create(); } Multiset<Integer> set = HashMultiset.create(); for (Item item : itemContainer.getItems()) { if (item.getId() != ItemID.BANK_FILLER) { set.add(item.getId(), item.getQuantity()); } } return set; }
Example 3
Source File: BankPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private Item[] getBankTabItems() { final ItemContainer container = client.getItemContainer(InventoryID.BANK); if (container == null) { return null; } final Item[] items = container.getItems(); int currentTab = client.getVar(Varbits.CURRENT_BANK_TAB); if (currentTab > 0) { int startIndex = 0; for (int i = currentTab - 1; i > 0; i--) { startIndex += client.getVar(TAB_VARBITS.get(i - 1)); } int itemCount = client.getVar(TAB_VARBITS.get(currentTab - 1)); return Arrays.copyOfRange(items, startIndex, startIndex + itemCount); } return items; }
Example 4
Source File: BankPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private Multiset<Integer> getBankItemSet() { ItemContainer itemContainer = client.getItemContainer(InventoryID.BANK); if (itemContainer == null) { return HashMultiset.create(); } Multiset<Integer> set = HashMultiset.create(); for (Item item : itemContainer.getItems()) { if (item.getId() != ItemID.BANK_FILLER) { set.add(item.getId(), item.getQuantity()); } } return set; }
Example 5
Source File: ZalcanoUtil.java From plugins with GNU General Public License v3.0 | 6 votes |
/** * Courtesy of OP * * @param itemId * @return */ int countStackInInventory(int itemId) { ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY); if (inventory != null) { Item[] items = inventory.getItems(); for (int i = 0; i < 28; ++i) { if (i < items.length) { Item item = items[i]; if (item.getId() >= 0 && item.getId() == itemId) { return item.getQuantity(); } } } } return 0; }
Example 6
Source File: BankPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private Item[] getBankTabItems() { final ItemContainer container = client.getItemContainer(InventoryID.BANK); if (container == null) { return null; } final Item[] items = container.getItems(); int currentTab = client.getVar(Varbits.CURRENT_BANK_TAB); if (currentTab > 0) { int startIndex = 0; for (int i = currentTab - 1; i > 0; i--) { startIndex += client.getVar(TAB_VARBITS.get(i - 1)); } int itemCount = client.getVar(TAB_VARBITS.get(currentTab - 1)); return Arrays.copyOfRange(items, startIndex, startIndex + itemCount); } return items; }
Example 7
Source File: BankPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private Item[] getSeedVaultItems() { final ItemContainer itemContainer = client.getItemContainer(InventoryID.SEED_VAULT); if (itemContainer == null) { return null; } return itemContainer.getItems(); }
Example 8
Source File: LeftClickCast.java From ExternalPlugins with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onItemContainerChanged(ItemContainerChanged event) { final ItemContainer ic = event.getItemContainer(); if (client.getItemContainer(InventoryID.EQUIPMENT) != ic) { return; } isMage = false; for (Item item : ic.getItems()) { final String name = client.getItemDefinition(item.getId()).getName().toLowerCase(); if (name.contains("staff") || name.contains("wand")) { isMage = true; break; } } if (config.disableStaffChecks()) { isMage = true; } }
Example 9
Source File: WintertodtPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
@Subscribe private void onItemContainerChanged(ItemContainerChanged event) { final ItemContainer container = event.getItemContainer(); if (!isInWintertodt || container != client.getItemContainer(InventoryID.INVENTORY)) { return; } final Item[] inv = container.getItems(); numRoots = 0; numKindling = 0; for (Item item : inv) { switch (item.getId()) { case BRUMA_ROOT: ++numRoots; break; case BRUMA_KINDLING: ++numKindling; break; } } //If we're currently fletching but there are no more roots, go ahead and abort fletching immediately if (numRoots == 0 && currentActivity == WintertodtActivity.FLETCHING) { currentActivity = WintertodtActivity.IDLE; } //Otherwise, if we're currently feeding the brazier but we've run out of both roots and kindling, abort the feeding activity else if (numRoots == 0 && numKindling == 0 && currentActivity == WintertodtActivity.FEEDING_BRAZIER) { currentActivity = WintertodtActivity.IDLE; } }
Example 10
Source File: SuppliesTrackerPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
/** * Checks for changes between the provided inventories in runes specifically to add those runes * to the supply tracker * <p> * we can't in general just check for when inventory slots change but this method is only run * immediately after the player performs a cast animation or cast menu click/entry * * @param itemContainer the new inventory * @param oldInv the old inventory */ private void checkUsedRunes(ItemContainer itemContainer, Item[] oldInv) { try { for (int i = 0; i < itemContainer.getItems().length; i++) { Item newItem = itemContainer.getItems()[i]; Item oldItem = oldInv[i]; boolean isRune = false; for (int runeId : RUNE_IDS) { if (oldItem.getId() == runeId) { isRune = true; break; } } if (isRune && (newItem.getId() != oldItem.getId() || newItem.getQuantity() != oldItem.getQuantity())) { int quantity = oldItem.getQuantity(); if (newItem.getId() == oldItem.getId()) { quantity -= newItem.getQuantity(); } // ensure that only positive quantities are added since it is reported // that sometimes checkUsedRunes is called on the same tick that a player // gains runes in their inventory if (quantity > 0 && quantity < 35) { buildEntries(oldItem.getId(), quantity); } } } } catch (IndexOutOfBoundsException ignored) { } }
Example 11
Source File: SuppliesTrackerPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
/** * checks the player's cape slot to determine what percent of their darts are lost * - where lost means either break or drop to floor * * @return the percent lost */ private double getAccumulatorPercent() { double percent = NO_AVAS_PERCENT; ItemContainer equipment = client.getItemContainer(InventoryID.EQUIPMENT); if (equipment != null && equipment.getItems().length > EQUIPMENT_CAPE_SLOT) { int capeID = equipment.getItems()[EQUIPMENT_CAPE_SLOT].getId(); switch (capeID) { case AVAS_ASSEMBLER: case AVAS_ASSEMBLER_L: case ASSEMBLER_MAX_CAPE: percent = ASSEMBLER_PERCENT; break; case AVAS_ACCUMULATOR: case AVAS_ACCUMULATOR_23609: case ACCUMULATOR_MAX_CAPE: // TODO: the ranging cape can be used as an attractor so this could be wrong case RANGING_CAPE: percent = ACCUMULATOR_PERCENT; break; case AVAS_ATTRACTOR: percent = ATTRACTOR_PERCENT; break; } } return percent; }
Example 12
Source File: PrayerPotion.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public int heals(Client client) { boolean hasHolyWrench = false; ItemContainer equipContainer = client.getItemContainer(InventoryID.EQUIPMENT); if (equipContainer != null) { Item[] equip = equipContainer.getItems(); final int ring = ItemUtil.safeGetItemIdAtIndex(equip, EquipmentInventorySlot.RING.getSlotIdx()); final int cape = ItemUtil.safeGetItemIdAtIndex(equip, EquipmentInventorySlot.CAPE.getSlotIdx()); hasHolyWrench = ring == ItemID.RING_OF_THE_GODS_I; hasHolyWrench |= HOLY_WRENCH_IDS.contains(cape); } if (!hasHolyWrench) { ItemContainer invContainer = client.getItemContainer(InventoryID.INVENTORY); if (invContainer != null) { hasHolyWrench = ItemUtil.containsAnyItemId(invContainer.getItems(), HOLY_WRENCH_IDS); } } double percent = hasHolyWrench ? perc + .02 : perc; int max = getStat().getMaximum(client); return (((int) (max * percent)) * (delta >= 0 ? 1 : -1)) + delta; }
Example 13
Source File: InventoryViewerOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public Dimension render(Graphics2D graphics) { final ItemContainer itemContainer = client.getItemContainer(InventoryID.INVENTORY); if (itemContainer == null) { return null; } final Item[] items = itemContainer.getItems(); for (int i = 0; i < INVENTORY_SIZE; i++) { if (i < items.length) { final Item item = items[i]; if (item.getQuantity() > 0) { final BufferedImage image = getImage(item); if (image != null) { panelComponent.getChildren().add(new ImageComponent(image)); continue; } } } // put a placeholder image so each item is aligned properly and the panel is not resized panelComponent.getChildren().add(PLACEHOLDER_IMAGE); } return super.render(graphics); }
Example 14
Source File: TabInterface.java From plugins with GNU General Public License v3.0 | 5 votes |
private ItemDefinition getItem(int idx) { ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK); Item item = null; if (bankContainer != null) { item = bankContainer.getItems()[idx]; } if (item != null) { return itemManager.getItemDefinition(item.getId()); } return null; }
Example 15
Source File: BankPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private Item[] getSeedVaultItems() { final ItemContainer itemContainer = client.getItemContainer(InventoryID.SEED_VAULT); if (itemContainer == null) { return null; } return itemContainer.getItems(); }
Example 16
Source File: EquipmentItemRequirement.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public boolean meetsRequirements(Client client) { ItemContainer equipmentContainer = client.getItemContainer(InventoryID.EQUIPMENT); if (equipmentContainer == null) { return false; } Item[] equipedItems = equipmentContainer.getItems(); return EquipmentHelper.wearsItem(equipedItems, this.item); }
Example 17
Source File: PrayerPotion.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public int heals(Client client) { boolean hasHolyWrench = false; ItemContainer equipContainer = client.getItemContainer(InventoryID.EQUIPMENT); if (equipContainer != null) { Item cape = equipContainer.getItem(CAPE_SLOT); Item ring = equipContainer.getItem(RING_SLOT); hasHolyWrench = ring != null && ring.getId() == ItemID.RING_OF_THE_GODS_I; if (cape != null) { int capeId = cape.getId(); hasHolyWrench |= capeId == ItemID.PRAYER_CAPE; hasHolyWrench |= capeId == ItemID.PRAYER_CAPET; hasHolyWrench |= capeId == ItemID.PRAYER_CAPE_10643; // No idea what this is hasHolyWrench |= capeId == ItemID.MAX_CAPE; hasHolyWrench |= capeId == ItemID.MAX_CAPE_13282; // Or these hasHolyWrench |= capeId == ItemID.MAX_CAPE_13342; } } if (!hasHolyWrench) { ItemContainer invContainer = client.getItemContainer(InventoryID.INVENTORY); if (invContainer != null) { for (Item itemStack : invContainer.getItems()) { int item = itemStack.getId(); hasHolyWrench = item == ItemID.HOLY_WRENCH; hasHolyWrench |= item == ItemID.PRAYER_CAPE; hasHolyWrench |= item == ItemID.PRAYER_CAPET; hasHolyWrench |= item == ItemID.PRAYER_CAPE_10643; hasHolyWrench |= item == ItemID.MAX_CAPE; hasHolyWrench |= item == ItemID.MAX_CAPE_13282; hasHolyWrench |= item == ItemID.MAX_CAPE_13342; if (hasHolyWrench) { break; } } } } double percent = hasHolyWrench ? perc + .02 : perc; int max = getStat().getMaximum(client); return (((int) (max * percent)) * (delta >= 0 ? 1 : -1)) + delta; }
Example 18
Source File: RunecraftPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onItemContainerChanged(ItemContainerChanged event) { final ItemContainer container = event.getItemContainer(); if (container == client.getItemContainer(InventoryID.INVENTORY)) { degradedPouchInInventory = false; for (Item item : container.getItems()) { if (!medDegrade && item.getId() == ItemID.MEDIUM_POUCH_5511) { medDegrade = true; mediumCharges = 0; degradedPouchInInventory = true; } else if (!largeDegrade && item.getId() == ItemID.LARGE_POUCH_5513) { largeDegrade = true; largeCharges = 0; degradedPouchInInventory = true; } else if (!giantDegrade && item.getId() == ItemID.GIANT_POUCH_5515) { giantDegrade = true; giantCharges = 0; degradedPouchInInventory = true; } else if (medDegrade && item.getId() == ItemID.MEDIUM_POUCH) { medDegrade = false; mediumCharges = MEDIUM_DEGRADE; } else if (largeDegrade && item.getId() == ItemID.LARGE_POUCH) { largeDegrade = false; largeCharges = LARGE_DEGRADE; } else if (giantDegrade && item.getId() == ItemID.GIANT_POUCH) { giantDegrade = false; giantCharges = GIANT_DEGRADE; } } } }
Example 19
Source File: BankTagsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onMenuOptionClicked(MenuOptionClicked event) { if (event.getParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && event.getMenuOpcode() == MenuOpcode.RUNELITE && event.getOption().startsWith(EDIT_TAGS_MENU_OPTION)) { event.consume(); int inventoryIndex = event.getParam0(); ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK); if (bankContainer == null) { return; } Item[] items = bankContainer.getItems(); if (inventoryIndex < 0 || inventoryIndex >= items.length) { return; } Item item = bankContainer.getItems()[inventoryIndex]; if (item == null) { return; } int itemId = item.getId(); ItemDefinition itemDefinition = itemManager.getItemDefinition(itemId); String name = itemDefinition.getName(); // Get both tags and vartags and append * to end of vartags name Collection<String> tags = tagManager.getTags(itemId, false); tagManager.getTags(itemId, true).stream() .map(i -> i + "*") .forEach(tags::add); boolean isSearchOpen = client.getVar(VarClientInt.INPUT_TYPE) == InputType.SEARCH.getType(); String searchText = client.getVar(VarClientStr.INPUT_TEXT); String initialValue = Text.toCSV(tags); chatboxPanelManager.openTextInput(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)") .addCharValidator(FILTERED_CHARS) .value(initialValue) .onDone((Consumer<String>) (newValue) -> clientThread.invoke(() -> { // Split inputted tags to vartags (ending with *) and regular tags final Collection<String> newTags = new ArrayList<>(Text.fromCSV(newValue.toLowerCase())); final Collection<String> newVarTags = new ArrayList<>(newTags).stream().filter(s -> s.endsWith(VAR_TAG_SUFFIX)).map(s -> { newTags.remove(s); return s.substring(0, s.length() - VAR_TAG_SUFFIX.length()); }).collect(Collectors.toList()); // And save them tagManager.setTagString(itemId, Text.toCSV(newTags), false); tagManager.setTagString(itemId, Text.toCSV(newVarTags), true); // Check both previous and current tags in case the tag got removed in new tags or in case // the tag got added in new tags tabInterface.updateTabIfActive(Text.fromCSV(initialValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); tabInterface.updateTabIfActive(Text.fromCSV(newValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); })) .build(); if (isSearchOpen) { bankSearch.reset(false); bankSearch.search(InputType.SEARCH, searchText, false); } } else { tabInterface.handleClick(event); } }
Example 20
Source File: IdleNotifierPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onItemContainerChanged(ItemContainerChanged event) { ItemContainer itemContainer = event.getItemContainer(); if (itemContainer != client.getItemContainer(InventoryID.INVENTORY) || !config.outOfItemsIdle()) { return; } Item[] items = itemContainer.getItems(); ArrayList<Integer> itemQuantities = new ArrayList<>(); ArrayList<Integer> itemIds = new ArrayList<>(); // Populate list of items in inventory without duplicates for (Item value : items) { int itemId = OutOfItemsMapping.mapFirst(value.getId()); if (itemIds.indexOf(itemId) == -1) // -1 if item not yet in list { itemIds.add(itemId); } } // Populate quantity of each item in inventory for (int j = 0; j < itemIds.size(); j++) { itemQuantities.add(0); for (Item item : items) { if (itemIds.get(j) == OutOfItemsMapping.mapFirst(item.getId())) { itemQuantities.set(j, itemQuantities.get(j) + item.getQuantity()); } } } itemQuantitiesChange.clear(); // Calculate the quantity of each item consumed by the last action if (!itemIdsPrevious.isEmpty()) { for (int i = 0; i < itemIdsPrevious.size(); i++) { int id = itemIdsPrevious.get(i); int currentIndex = itemIds.indexOf(id); int currentQuantity; if (currentIndex != -1) // -1 if item is no longer in inventory { currentQuantity = itemQuantities.get(currentIndex); } else { currentQuantity = 0; } itemQuantitiesChange.add(currentQuantity - itemQuantitiesPrevious.get(i)); } } else { itemIdsPrevious = itemIds; itemQuantitiesPrevious = itemQuantities; return; } // Check we have enough items left for another action. for (int i = 0; i < itemQuantitiesPrevious.size(); i++) { if (-itemQuantitiesChange.get(i) * 2 > itemQuantitiesPrevious.get(i)) { lastTimeItemsUsedUp = Instant.now(); return; } } itemIdsPrevious = itemIds; itemQuantitiesPrevious = itemQuantities; }