Custom Ball Compat API: Custom Balls & Catch-Rate Modifiers #35
Akkiruk
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Who this is for
Two situations:
As of 2.12.0 both of these are self-service. You don't need us to hardcode anything on our end.
Part 1: Custom Balls
Here's the minimum to get a ball recognized:
Call this once when your mod initializes. Once it's registered:
com.catchrate.apihas no runtime dependency on CatchRateDisplay, so you can depend on it ascompileOnly(ormodCompileOnlyif you're on Fabric/NeoForge Loom) and your mod will work fine even if a player doesn't have CatchRateDisplay installed. The provider just never gets called.CatchRateBallProvider
One method:
Returning null tells us to fall back to whatever we'd normally do for that ball ID. You probably won't need this for a ball (unlike a buff, a ball doesn't really come and go) but it's there.
BallApiContext
What you get handed, describing the target Pokémon and the situation:
speciesIdString"pikachu"levelIntprimaryTypeString"electric"secondaryTypeString?weightFloatbaseSpeedIntlabelsList<String>"legendary","mythical"statusPathString?"sleep","paralysis", null if healthyinBattleBooleanturnCountIntinBattlepokemonAspectsSet<String>BallApiResult
What you hand back:
multiplierFloatconditionMetBooleanreasonString"Quantum resonance"isGuaranteedBooleanCatchRateBallRegistry
Use your ball item's actual full ResourceLocation (
yourmodid:your_ball), not just the bare name. That's what stops two unrelated mods from colliding if they both happen to name a ball the same thing.A few other things worth flagging: if your provider throws an exception, we log it once and quietly skip that ball going forward instead of spamming your log every frame. Also, this API only controls what number CatchRateDisplay shows, it doesn't make your item function as a ball. You still need to register it as an actual PokeBallItem through Cobblemon's own API for it to be throwable and catch anything, that part's entirely between you and Cobblemon.
Part 2: Catch Rate Modifiers
This one's for a temporary boost rather than a physical ball, things like a carrot that was eaten or a potion effect. Each active modifier gets its own row on the HUD and multiplies into the final percentage.
Register once at init like the ball API. The difference here is that returning null is the normal, expected case whenever your buff isn't active, not an error. When it is active, keep returning a result, this gets evaluated continuously rather than once.
CatchRateModifierProvider
This one gets the Player directly rather than a context object, since a modifier is about the player's state (an effect, a held item, whatever) rather than the target Pokémon.
CatchRateModifierResult
multiplierFloatdescriptionString"Carrot Boost"CatchRateModifierRegistry
The ID just needs to be unique to you since there's no item backing it, unlike balls.
If multiple mods have an active modifier at the same time, they all show up as separate rows and all their multipliers get applied together. Same failure handling as the ball API too: a provider that throws gets logged once and skipped after that, not retried every frame.
Source
Both files are under
common/src/main/kotlin/com/catchrate/api/in this repo,CatchRateBallApi.ktfor Part 1 andCatchRateModifierApi.ktfor Part 2. The doc comments there have the same examples as above if you'd rather just read the source.If either API is missing a field you need, reply here and let me know.
All reactions