From f7e2aaa91f3c1a0affbaae25e8b8e4cac1b1ed10 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Tue, 26 Nov 2024 10:37:03 +0100 Subject: [PATCH] Fix InventoryUtils.count() actually counting slots instead of items --- src/main/java/net/wurstclient/util/InventoryUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/wurstclient/util/InventoryUtils.java b/src/main/java/net/wurstclient/util/InventoryUtils.java index a067f0a371..eaf18cfa9e 100644 --- a/src/main/java/net/wurstclient/util/InventoryUtils.java +++ b/src/main/java/net/wurstclient/util/InventoryUtils.java @@ -101,6 +101,9 @@ public static int count(Predicate 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}. * + *

+ * Note: Attempting to count empty slots will always return 0. + * * @param predicate * checks if an item should be counted * @param maxInvSlot @@ -114,8 +117,10 @@ public static int count(Predicate predicate, int maxInvSlot) public static int count(Predicate 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 predicate,