For other mods
Read collections, give cards and packs, and listen for pulls, drops, trades and completed sets.
Trading Cards has an API for other mods: a market that prices cards, a profile page that shows someone’s collection, a museum that takes donations. Compile against the mod jar (compileOnly) and check that tradingcards is loaded before touching it if Trading Cards is optional for you.
Reading
com.hardlineinteractive.tradingcards.TradingCardsApi reads the loaded cards and players’ collections:
CardDatabase db = TradingCardsApi.cards(level); // the loaded cards (client: what the server sent)
Optional<Card> card = TradingCardsApi.card(stack, level); // what card an item is
boolean shiny = TradingCardsApi.isFoil(stack); // Prismatic?
int number = TradingCardsApi.printNumber(stack); // 0 if not a numbered print
int price = TradingCardsApi.marketValue(stack, level); // a suggested price in shards
// Server side: a player's record
TradingCardsApi.CollectionSummary s = TradingCardsApi.summary(player);
// s.found()/s.total(), s.prismaticFound(), s.setsCompleted(), s.score(), s.rank(), s.packsOpened(), s.rarest(), s.perSet()
List<PlayerCards.Pull> pulls = TradingCardsApi.recentPulls(player); // newest first, up to 50
marketValue is the trade-in value with a premium for low print numbers (#1 is worth three times as much, fading out by #100).
Giving
ItemStack card = TradingCardsApi.makeCard("tradingcards:overworld/zombie", false); // just the item
TradingCardsApi.giveCard(player, "tradingcards:nether/blaze", true); // counts as found: milestones, events
TradingCardsApi.openPack(player, "tradingcards:collector"); // opens it with the full opening screen
Events
com.hardlineinteractive.tradingcards.api.TradingCardsEvents are posted on the server whenever something collectible happens:
| Event | When | Can change |
|---|---|---|
CardsReloaded |
The cards were loaded from datapacks. | |
CardDiscovered |
A player got a card they’d never had. | |
PackOpening |
A pack is about to open, cards already picked. | Edit the pulls, or cancel. |
PackOpened |
A pack was opened and its cards given. | |
CardDrop |
A mob with a card died. | The chance, Prismatic or not, or cancel. |
SetCompleted |
A player’s binder holds a whole set for the first time. | |
TradeCompleted |
Two players finished a trade. | |
CardsTradedIn |
Cards traded in at a Card Shop. | |
CardCrafted |
A card was made at a Card Shop. |
Advancements
The milestones use the trigger tradingcards:collection, and any datapack’s advancements can use it too:
"criteria": {
"netherite": {"trigger": "tradingcards:collection", "conditions": {"event": "rarity_pulled", "rarity": "tradingcards:netherite"}}
}
Its events are card_found, foil_found, pack_opened, rarity_pulled, set_completed, trade, trade_in and craft, with the optional conditions rarity, set and min_count.