Skip to content

Commit 2acb343

Browse files
refactor(InvUtils): clean duplicated lambdas (#6396)
1 parent 65dcf4b commit 2acb343

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

  • src/main/java/meteordevelopment/meteorclient/utils/player

src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,27 @@ private InvUtils() {
3131

3232
// Predicates
3333

34+
private static Predicate<ItemStack> isOneOf(Item... items) {
35+
return itemStack -> {
36+
for (var item : items) if (itemStack.is(item)) return true;
37+
return false;
38+
};
39+
}
40+
3441
public static boolean testInMainHand(Predicate<ItemStack> predicate) {
3542
return predicate.test(mc.player.getMainHandItem());
3643
}
3744

3845
public static boolean testInMainHand(Item... items) {
39-
return testInMainHand(itemStack -> {
40-
for (var item : items) if (itemStack.is(item)) return true;
41-
return false;
42-
});
46+
return testInMainHand(isOneOf(items));
4347
}
4448

4549
public static boolean testInOffHand(Predicate<ItemStack> predicate) {
4650
return predicate.test(mc.player.getOffhandItem());
4751
}
4852

4953
public static boolean testInOffHand(Item... items) {
50-
return testInOffHand(itemStack -> {
51-
for (var item : items) if (itemStack.is(item)) return true;
52-
return false;
53-
});
54+
return testInOffHand(isOneOf(items));
5455
}
5556

5657
public static boolean testInHands(Predicate<ItemStack> predicate) {
@@ -73,10 +74,7 @@ public static boolean testInHotbar(Predicate<ItemStack> predicate) {
7374
}
7475

7576
public static boolean testInHotbar(Item... items) {
76-
return testInHotbar(itemStack -> {
77-
for (var item : items) if (itemStack.is(item)) return true;
78-
return false;
79-
});
77+
return testInHotbar(isOneOf(items));
8078
}
8179

8280
// Finding items
@@ -86,12 +84,7 @@ public static FindItemResult findEmpty() {
8684
}
8785

8886
public static FindItemResult findInHotbar(Item... items) {
89-
return findInHotbar(itemStack -> {
90-
for (Item item : items) {
91-
if (itemStack.getItem() == item) return true;
92-
}
93-
return false;
94-
});
87+
return findInHotbar(isOneOf(items));
9588
}
9689

9790
public static FindItemResult findInHotbar(Predicate<ItemStack> isGood) {
@@ -107,12 +100,7 @@ public static FindItemResult findInHotbar(Predicate<ItemStack> isGood) {
107100
}
108101

109102
public static FindItemResult find(Item... items) {
110-
return find(itemStack -> {
111-
for (Item item : items) {
112-
if (itemStack.getItem() == item) return true;
113-
}
114-
return false;
115-
});
103+
return find(isOneOf(items));
116104
}
117105

118106
public static FindItemResult find(Predicate<ItemStack> isGood) {

0 commit comments

Comments
 (0)