-
Notifications
You must be signed in to change notification settings - Fork 121
Hooks
BaseMod uses a subscription model to handle hooks. If you want to receive a specific hook you subscribeTo it and if you want to stop receiving the event you unsubscribeFrom it.
-
BaseMod.subscribe(this)wherethisis an instance of some subscriber, this method will subscribethisto all hooks it implements subscribers for. -
BaseMod.unsubscribe(this)wherethisis an instance of some subscriber, this method will unsubscribethisfrom all hooks it implements subscribers for. -
BaseMod.subscribe(this, Class<? extends ISubscriber> toAddClass)wherethisis an instance of some subscriber, this method will subscribethisto only thetoAddClasshook. -
BaseMod.unsubscribe(this, Class<? extends ISubscriber> toRemoveClass)wherethisis an instance of some subscriber, this method will unsubscribethisfrom only thetoRemoveClasshook.
BaseMod.subscribeTo...(this)BaseMod.unsubscribeFrom...(this)
Sometimes you need to unsubscribe from an event after it's triggered once. Maybe you only want to listen for the first time a card is played or the first time a dungeon is set up. In that case you're going to want to unsubscribe from a hook in the callback method for the hook. However if you were to directly call BaseMod.unsubscribe in your receiveSomeReallyCoolEvent method you will throw a ConcurrentModificationException which is what happens in Java when you try and modify a list at the same time it is being iterated over. To avoid this exception you need to use BaseMod.unsubscribeLater which will register your subscriber to be unsubscribed after the bit of code that could throw the exception.
This is NOT A COMPLETE LIST of hooks. Check src/main/java/basemod/interfaces for a complete list.
-
PostDrawSubscriber- After a card is drawn. -
PostExhaustSubscriber- After a card is exhausted. -
OnCardUseSubscriber- Directly after a card is used (can be used to add additional functionality to cards on use).
-
PostEnergyRechargeSubscriber- At the start of every player turn, after energy has recharged.
PreRenderSubscriber-
ModelRenderSubscriber- Used in conjunction withreceiveCameraRender. -
PreRoomRenderSubscriber- Under the player and monsters, over the background. -
RenderSubscriber- Under tips and the cursor, above everything else. -
PostRenderSubscriber- Above everything.
-
PostInitializeSubscriber- One time only, at the end ofCardCrawlGame.initialize(). -
PostDungeonInitializeSubscriber- After dungeon initialization completes. -
StartActSubscriber- After a new act is started - only occurs when the player transitions between acts OR starts a new game and begins the Exordium act. -
PostCampfireSubscriber- After a campfire action is performed. Returning false will allow another action to be performed. -
PreStartGameSubscriber- When starting a new game or continuing, before generating/loading the player. -
StartGameSubscriber- When starting a new game or continuing, after generating/loading the player and before dungeon generation. -
PreUpdateSubscriber- Immediately after input is read. -
PostUpdateSubscriber- Immediately before input is disposed. -
PreDungeonUpdateSubscriber- Called before anything happens inAbstractDungeon.update(). -
PostDungeonUpdateSubscriber- Called after everything happens inAbstractDungeon.update(). -
PrePlayerUpdateSubscriber- Called before anything happens inAbstractPlayer.update(). -
PostPlayerUpdateSubscriber- Called after everything happens inAbstractPlayer.update(). -
PostBattleSubscriber- Called after all of the logic is completed inAbstractRoom.endBattle(). -
OnPowersModifiedSubscriber- Called afterAbstractDungeon.onModifyPower(). PostPowerApplySubscriber-
MaxHPChangeSubscriber- Immediately before maxHealth is changed forAbstractCreature, allows you to change the amount of hp changed. PostEnergyRechargeSubscriber
-
PostCreateStartingDeckSubscriber- Immediately after the character's starting deck is created. Returning true will remove all the cards from the default starting deck. Add the cards you want to be in the starting deck tocardsToAdd. -
PostCreateStartingRelicsSubscriber- Immediately after the character's starting relics are created. Returning true will remove all the default relics from the player. Add the relics you want to be in the starting deck torelicsToAdd. RelicGetSubscriber
-
PostCreateShopRelicSubscriber- Immediately after the shop generates its relics. Modifyingrelicswill change the relics in the shop.screenInstanceis an instance of theShopScreen. -
PostCreateShopPotionSubscriber- Immediately after the shop generates its potions. Modifyingpotionswill change the potions in the shop.screenInstanceis an instance of theShopScreen.
-
PrePotionUseSubscriber- Immediately before a potion is used. -
PostPotionUseSubscriber- Immediately after a potion is used. -
PotionGetSubscriber- When the player gets a potion.
-
EditCardsSubscriber- When you should register any cards to add or remove withBaseMod.addCardandBaseMod.removeCard. Do NOT initialize any cards or register any cards to add or remove outside of this handler. Slay the Spire needs some things to be done in certain orders and this handler ensures that happens correctly. Note that removing any cards involved in game events is undefined behavior currently. -
EditRelicsSubscriber- When you should register any relics to add or remove withBaseMod.addRelicandBaseMod.removeRelic. Do NOT initialize any relics or register any relics to add or remove outside of this handler. Slay the Spire needs some things to be done in certain orders and this handler ensures that happens correctly. Note that removing any relics involved in game events is undefined behavior currently. -
EditCharactersSubscriber- When you should register any characters to add or remove withBaseMod.addCharacterandBaseMod.removeCharacter. Do NOT initialize any characters or register any relics to add or remove outside of this handler. Slay the Spire needs some things to be done in certain orders and this handler ensures that happens correctly. Note that removing the default characters IS NOT supported at this time. -
SetUnlocksSubscriber- When you should register any custom unlocks. Note that removing any unlocks that exist in the base game won't work (it shouldn't crash but it won't do anything). Do NOT set up any custom unlocks outside of this handler. Slay The Spire needs some things to be done in certain orders and this handler ensures that happens correctly.
Here is a simple example that shows how you would go about doing something when the player draws a card. For example purposes all that is done is that it logs the card name to the console.
@SpireInitializer
public class MyMod implements PostDrawSubscriber {
public MyMod() {
BaseMod.subscribe(this);
}
public static void initialize() {
MyMod mod = new MyMod();
}
@Override
public void receivePostDraw(AbstractCard card) {
logger.info("card ID: " + card.cardID + " was drawn!");
}
}