Skip to content

Commit

Permalink
Fix InventoryUtils.count() actually counting slots instead of items
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 26, 2024
1 parent 2b35c69 commit f7e2aaa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/net/wurstclient/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public static int count(Predicate<ItemStack> predicate, int maxInvSlot)
* Counts the number of items in the player's inventory that match the given
* predicate, searching from slot 0 to {@code maxInvSlot-1}.
*
* <p>
* Note: Attempting to count empty slots will always return 0.
*
* @param predicate
* checks if an item should be counted
* @param maxInvSlot
Expand All @@ -114,8 +117,10 @@ public static int count(Predicate<ItemStack> predicate, int maxInvSlot)
public static int count(Predicate<ItemStack> predicate, int maxInvSlot,
boolean includeOffhand)
{
return (int)getMatchingSlots(predicate, maxInvSlot, includeOffhand)
.count();
PlayerInventory inventory = MC.player.getInventory();

return getMatchingSlots(predicate, maxInvSlot, includeOffhand)
.map(slot -> inventory.getStack(slot).getCount()).sum();
}

private static IntStream getMatchingSlots(Predicate<ItemStack> predicate,
Expand Down

0 comments on commit f7e2aaa

Please sign in to comment.