-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add findEquipped and findAllEquipped to Curios/Trinkets support…
… layer #121
- Loading branch information
1 parent
2f3542b
commit a269d4a
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
fabric/src/main/java/net/blay09/mods/balm/fabric/compat/trinkets/TrinketsModCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package net.blay09.mods.balm.fabric.compat.trinkets; | ||
|
||
import dev.emi.trinkets.api.TrinketsApi; | ||
import net.minecraft.util.Tuple; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class TrinketsModCompat { | ||
public static boolean isEquipped(Player player, Predicate<ItemStack> predicate) { | ||
return TrinketsApi.getTrinketComponent(player).map(trinkets -> trinkets.isEquipped(predicate)).orElse(false); | ||
} | ||
|
||
public static ItemStack findEquipped(Player player, Predicate<ItemStack> predicate) { | ||
return TrinketsApi.getTrinketComponent(player) | ||
.flatMap(trinkets -> trinkets.getEquipped(predicate).stream().findFirst()) | ||
.map(Tuple::getB) | ||
.orElse(ItemStack.EMPTY); | ||
} | ||
|
||
public static List<ItemStack> findAllEquipped(Player player, Predicate<ItemStack> predicate) { | ||
return TrinketsApi.getTrinketComponent(player) | ||
.map(trinkets -> trinkets.getEquipped(predicate).stream().map(Tuple::getB).toList()) | ||
.orElse(List.of()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters