Interface BattleController

All Superinterfaces:
BattleEvents, BattleMessaging, BattleRandomContext, BattleSimulationContext, BattleSpectating, BattleStateView, ContextHolder, LegacyBattleAISupport, RegistryBacked
All Known Implementing Classes:
MultiLaneBattleController, StandardBattleController

  • Method Details

    • update

      void update()
      Updates the battle every tick.
    • doTurnLogic

      void doTurnLogic()
    • advanceToMoves

      default void advanceToMoves()
    • takeFullTurn

      default void takeFullTurn(Runnable moveSelection)
    • takeFullTurn

      default void takeFullTurn()
    • endTurn

      void endTurn()
      Handles end-of-turn effects.
    • modifyStats

      default void modifyStats()
      Modifies Pokémon stats during a turn.
    • modifyStatsCancellable

      void modifyStatsCancellable(PixelmonWrapper attacker)
      Modifies Pokémon stats during a turn after deciding which Pokémon gets to make a move.
      Parameters:
      attacker - The Pokémon using a move.
    • sync

      default <T> void sync(ContextKey<T> key)
      This method synchronizes the value stored in the battle context for the given key to all clients participating in the battle.
      This should be called whenever a value in the battle context is changed that needs to be known by the clients, such as the ContextKeys.TURN_TIME which is required by the clients to display the turn timer.
      Type Parameters:
      T - The type of the value in the battle context to synchronize.
      Parameters:
      key - The key of the value in the battle context to synchronize to the clients.
    • shouldSendBattleStartPackets

      default boolean shouldSendBattleStartPackets()
      Determines whether participant initialization should emit battle start packets directly. Multi-lane battles disable this on their lane controllers so the parent controller can send a single packet with the full cross-lane battle view.
      Returns:
      Whether this controller should send battle start packets from its participants.
    • shouldSendBattleStartPackets

      default void shouldSendBattleStartPackets(boolean shouldSendBattleStartPackets)
      Sets whether participant initialization should emit battle start packets directly.
      Parameters:
      shouldSendBattleStartPackets - Whether this controller should send battle start packets.
    • sendBattleScenePackets

      default void sendBattleScenePackets()
      Sends the context-selected battle scene to each player in this battle, if one is configured.

      Each packet is anchored to the receiving player's current block position so every client renders the scene around its own player.

    • sendBattleScenePacket

      default void sendBattleScenePacket(net.minecraft.server.level.ServerPlayer player)
      Sends the context-selected battle scene to one player, if one is configured.
      Parameters:
      player - the player receiving the scene
    • spawnEntityForBattle

      @Nullable default PixelmonEntity spawnEntityForBattle(PixelmonWrapper wrapper)
      This method spawns a PixelmonEntity for the given PixelmonWrapper if entities should be spawned for this battle. It returns the spawned entity, or null if entities should not be spawned for this battle or if the spawn event was canceled.
      Parameters:
      wrapper - The PixelmonWrapper to spawn an entity for.
      Returns:
      The spawned PixelmonEntity, or null if entities should not be spawned for this battle or if the spawn event was canceled.
    • getLastAttack

      Attack getLastAttack()
    • getLastTempAttack

      Attack getLastTempAttack()
    • addBattleAnimation

      void addBattleAnimation(ActiveBattleAnimation animation)
      Stores a battle animation that is currently running for this battle.
      Parameters:
      animation - The animation to store
    • battleAnimationChannelId

      default String battleAnimationChannelId()
    • battleAnimationChannelId

      default void battleAnimationChannelId(String battleAnimationChannelId)
    • isBattleAnimationChannelBusy

      default boolean isBattleAnimationChannelBusy(String channel)
    • cleanUpBattleAnimationChannel

      default void cleanUpBattleAnimationChannel(String channel)
    • acknowledgeBattleAnimation

      default void acknowledgeBattleAnimation(net.minecraft.server.level.ServerPlayer player, UUID acknowledgementId)
      Acknowledges completion of a client-side battle animation wait.
      Parameters:
      player - the client that acknowledged the animation
      acknowledgementId - the acknowledgement token sent to the client
    • endBattle

      default Map<BattleParticipant,BattleResults> endBattle()
      Concludes the battle and determines a victor.
    • endBattleWithoutXP

      default Map<BattleParticipant,BattleResults> endBattleWithoutXP()
      Concludes the battles and determines a victor. Does not reward any experience.
    • endBattle

      default Map<BattleParticipant,BattleResults> endBattle(BattleEndCause cause)
      Ends the battle with the given cause.
    • endBattle

      Ends the battle with the given cause and any precalculated results. This method is called by ALL other end of battle methods.
    • removePlayer

      default void removePlayer(net.minecraft.server.level.ServerPlayer player, BattleEndCause cause)
      Handles a player leaving the server while in this battle, such as by logging out or dying. By default this ends the battle.
    • forfeitBattleForPlayerAndTheirTeam

      default Map<BattleParticipant,BattleResults> forfeitBattleForPlayerAndTheirTeam(BattleEndCause battleEndCause, net.minecraft.world.entity.player.Player player)
    • switchPokemon

      void switchPokemon(UUID switchingPokemonUUID, UUID newPokemonUUID, boolean switchInstantly)
      Switches a Pokémon out for a different one.
      Parameters:
      switchingPokemonUUID - The Pokémon switching out.
      newPokemonUUID - The Pokémon to switch into.
      switchInstantly - True if the switch will happen immediately, false if the switch will happen during the turn.
    • hasSwitchedDuringThisMove

      boolean hasSwitchedDuringThisMove()
      This method returns if a Pokémon has switched due to a move during this move. This is used to prevent multiple Pokémon from switching out during one move, such as with moves like U-Turn or Volt Switch. Only one Pokémon may switch per move.
      Returns:
      If a Pokémon has switched due to a move during this move.
    • hasSwitchedDuringThisMove

      void hasSwitchedDuringThisMove(boolean hasSwitchedDuringThisMove)
      This method sets whether a Pokémon has switched due to a move during this move. This is used to prevent multiple Pokémon from switching out during one move, such as with moves like U-Turn or Volt Switch. Only one Pokémon may switch per move.
      Parameters:
      hasSwitchedDuringThisMove - If a Pokémon has switched due to a move during this move.
    • turnList

      List<PixelmonWrapper> turnList()
      This method returns the order of Pokémon moving during a battle turn.
      Returns:
      The order of Pokémon moving during a battle turn.
    • turnList

      void turnList(List<PixelmonWrapper> turnList)
      This method sets the order of Pokémon moving during a battle turn.
      Parameters:
      turnList - The order of Pokémon moving during a battle turn.
    • getTurnForPokemon

      default int getTurnForPokemon(PixelmonWrapper pokemon)
      Gets the position of the specified Pokémon in the turn order.
      Parameters:
      pokemon - The Pokémon to find the turn for.
      Returns:
      The position of the Pokémon in the turn order, or -1 if the Pokémon does not move in the turn.
    • getTurn

      default int getTurn(PixelmonWrapper pixelmonWrapper)
      Gets the ID of the turn for the pokemon
      Parameters:
      pixelmonWrapper - The pokemon
      Returns:
      The turn ID
    • isLastMover

      default boolean isLastMover()
      Checks whether the current ply is the last Pokémon in turn order.
      Returns:
      Whether the current ply is the last Pokémon in turn order.
    • getFirstMover

      default PixelmonWrapper getFirstMover(PixelmonWrapper... pokemonList)
      Gets the first Pokémon to move in the turn order from the given list.
      Parameters:
      pokemonList - A list of Pokémon to get the first mover from.
      Returns:
      The first Pokémon within the list who can move in the turn order, or null if none of them are able to.
    • getFirstMover

      default PixelmonWrapper getFirstMover(List<PixelmonWrapper> pokemonList)
      Gets the first Pokémon to move in the turn order from the given list.
      Parameters:
      pokemonList - A list of Pokémon to get the first mover from.
      Returns:
      The first Pokémon within the list who can move in the turn order, or null if none of them are able to.
    • getLastMover

      default PixelmonWrapper getLastMover(PixelmonWrapper... pokemonList)
      Gets the last Pokémon to move in the turn order from the given list.
      Parameters:
      pokemonList - A list of Pokémon to get the first mover from.
      Returns:
      The last Pokémon within the list who can move in the turn order, or null if none of them are able to.
    • getLastMover

      default PixelmonWrapper getLastMover(List<PixelmonWrapper> pokemonList)
      Gets the last Pokémon to move in the turn order from the given list.
      Parameters:
      pokemonList - A list of Pokémon to get the first mover from.
      Returns:
      The last Pokémon within the list who can move in the turn order, or null if none of them are able to.
    • removeFromTurnList

      default void removeFromTurnList(PixelmonWrapper pw)
      Removes a Pokémon from the turn list if the Pokémon has not made a move yet.
      Parameters:
      pw - The Pokémon to remove.
    • getDefaultTurnOrder

      default List<PixelmonWrapper> getDefaultTurnOrder()
      Gets the turn order of Pokémon in the battle without accounting for priority.
      Returns:
      The turn order of Pokémon in the battle without accounting for priority.
    • getPositionOfPokemon

      default int getPositionOfPokemon(PixelmonWrapper poke)
      Returns the position of the specified Pokémon in battle.
      Parameters:
      poke - The Pokémon to get the position of.
      Returns:
      The Pokémon's position.
    • getPokemonAtPosition

      default PixelmonWrapper getPokemonAtPosition(int position)
      Returns the Pokémon at the specified position in the battle. Creates a lineup of Pokémon starting from participants.get(0).controlledPokemon[0] until participants.get(participants.size()-1).controlledPokemon[ controlledPokemon.length-1] This lineup is static from battle beginning.
      Parameters:
      position - The position to get the Pokémon from.
      Returns:
      The Pokémon at the specified position.
    • getPositionOfPokemon

      default int getPositionOfPokemon(PixelmonWrapper poke, BattleParticipant bp)
      Returns the battle position of a Pokémon. Used by switch-out moves and items (Baton Pass, Eject Pack, Emergency Exit, Volt Switch) to tell the client which slot is being switched out. The client looks up teamPokemon[position] keyed by battlePosition, not list-index. Returning the list-index would resolve to the wrong slot any time the team had compacted from a no-reserve faint.
      Parameters:
      poke - The Pokémon to get the position of.
      bp - The participant with the Pokémon.
      Returns:
      The Pokémon's battle position, or -1 if it's not in the participant's team.
    • setFlee

      void setFlee(UUID fleeingUUID)
      Sets a Pokémon to flee in the turn.
      Parameters:
      fleeingUUID - The fleeing Pokémon.
    • checkValid

      default boolean checkValid()
      Checks whether the battle is in a valid state. End the battle if it is not.
      Returns:
      Whether the battle is valid.
    • enableReturnHeldItems

      default void enableReturnHeldItems(PixelmonWrapper attacker, PixelmonWrapper target)
      Enables returning held items for participants of the attacker and target of an action.
      Parameters:
      attacker - The action's user.
      target - The action's target.
    • getAbilityIfPresent

      default Optional<Ability> getAbilityIfPresent(Class<? extends AbstractAbility> abilityClass)
      Gets an instance of an ability if it is present in the battle.
      Returns:
      If present, the instance of the ability.
    • getPokemonWithAbility

      default List<PixelmonWrapper> getPokemonWithAbility(Class<? extends AbstractAbility> abilityClass)
      Gets pokemon with an ability if they are present in the battle.
      Returns:
      The pokemon with the specified ability, or an empty list.
    • duringSwitchAction

      boolean duringSwitchAction()
      Checks whether the battle controller is performing hard swaps causing aligned switch-in effects
      Returns:
      whether the controller is occupied with hard switches
    • setAllReady

      default void setAllReady()
      Sets all players as ready.
    • pauseBattle

      void pauseBattle()
      Pauses the battle.
    • endPause

      void endPause()
      Unpauses the battle.
    • participantCanDynamax

      boolean participantCanDynamax(BattleParticipant part)
      Checks if a participant is capable of dynamaxing and that it is their turn.
    • lastAttack

      Attack lastAttack()
    • lastAttack

      void lastAttack(Attack attack)
    • lastTempAttack

      Attack lastTempAttack()
    • lastTempAttack

      void lastTempAttack(Attack attack)
    • lastSimulatedAttack

      Attack lastSimulatedAttack()
    • lastSimulatedAttack

      void lastSimulatedAttack(Attack attack)
    • lastSimulatedTempAttack

      Attack lastSimulatedTempAttack()
    • lastSimulatedTempAttack

      void lastSimulatedTempAttack(Attack attack)
    • getPokemonOrderedByAbilityGain

      List<PixelmonWrapper> getPokemonOrderedByAbilityGain()
    • timedAbilityStarted

      void timedAbilityStarted(PixelmonWrapper pw)
      Moves pokemon to end of list of pokemon gaining their abilities
    • updateRemovedPokemon

      default void updateRemovedPokemon(PixelmonWrapper poke)
      Updates players when a Pokémon is removed from battle and not replaced.
      Parameters:
      poke - The Pokémon to remove.
    • publishSwitchPokemonEvent

      default void publishSwitchPokemonEvent(PixelmonWrapper switchedOut, PixelmonWrapper switchedIn)
    • publishRevivedPokemonEvent

      default void publishRevivedPokemonEvent(PixelmonWrapper revived)
    • publishPokemonHealthUpdate

      default void publishPokemonHealthUpdate(PixelmonWrapper pokemon, int previousHealth)
    • clearHurtTimer

      default void clearHurtTimer()
      Resets the hurt timers of all Pokémon in battle.
    • setUseItem

      default void setUseItem(UUID pokemonUUID, net.minecraft.world.entity.player.Player user, net.minecraft.world.item.ItemStack usedStack, int additionalInfo)
      Sets an item that the player will use during the turn.
      Parameters:
      pokemonUUID - The Pokémon the item is used on.
      user - The player using the item.
      usedStack - The item being used.
      additionalInfo - An additional argument for the item being used.
    • setUseItem

      default void setUseItem(UUID pokemonUUID, net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack usedStack, UUID targetPokemonUUID)
      Sets an item that the player will use during the turn.
      Parameters:
      pokemonUUID - The Pokémon the player currently has in battle.
      player - The player using the item.
      usedStack - The item being used.
      targetPokemonUUID - The Pokémon the item is being used on.
    • checkedPokemon

      Set<Pokemon> checkedPokemon()
      This method returns a set of Pokémon that need to be evolved at the end of the turn. This is used to keep track of Pokémon that need to be evolved at the end of the turn after all actions have been resolved, so that they can be evolved before the next turn starts.
      Returns:
      A set of Pokémon that need to be evolved at the end of the turn.
    • reviveAfterDefeat

      void reviveAfterDefeat(BattleParticipant p)
      Finds any statuses affecting the whole team and determines where a Pokémon being sent into battle should be positioned. Then sends out the newly revived Pokémon as an entity if it can, and sets the revived Pokémon's battle position, sets it as on the battlefield and applies the statuses. Finally, triggers some affects that occur when a Pokémon switches in.
      Parameters:
      p - the trainer that needs to send out a now revived Pokémon.
    • checkPokemon

      void checkPokemon()
      Checks the conditions of the active Pokémon.
    • reserveFaintOrder

      default void reserveFaintOrder(PixelmonWrapper target, @Nullable PixelmonWrapper source, @Nullable DamageTypeEnum damageType)
      Reserves this position in the faint order for effects whose user faints before their target, such as Self-Destruct and Final Gambit.
    • reserveFaintOrderBefore

      default void reserveFaintOrderBefore(PixelmonWrapper target, PixelmonWrapper beforeTarget, @Nullable PixelmonWrapper source, @Nullable DamageTypeEnum damageType)
      Reserves a faint immediately before an existing faint. This is used by effects such as Innards Out whose owner wins if its retaliation knocks out both final Pokémon.
    • recordFaintOrder

      default void recordFaintOrder(PixelmonWrapper target, @Nullable PixelmonWrapper source, @Nullable DamageTypeEnum damageType)
      Records a faint after all cancellable faint hooks have completed successfully.
    • consumeAllItems

      default void consumeAllItems(List<PixelmonWrapper> consumed)
      Consumes all the Pokémon's held items simultaneously.
    • currentlyActingPokemon

      PixelmonWrapper currentlyActingPokemon()
    • currentlyActingPokemon

      void currentlyActingPokemon(PixelmonWrapper currentlyActingPokemon)
    • storeSwitchInActivation

      void storeSwitchInActivation(PixelmonWrapper pw, PixelmonWrapper former)