Interface BattleStateView

All Superinterfaces:
ContextHolder
All Known Subinterfaces:
BattleController, BattleMessaging, BattleRandomContext, BattleSimulationContext
All Known Implementing Classes:
MultiLaneBattleController, StandardBattleController

public interface BattleStateView extends ContextHolder
Provides read-oriented access to the current state of a battle.

This interface exposes the common state and lookup operations needed by systems that inspect a battle without necessarily driving the battle lifecycle. This includes AI evaluation, battle helpers, participant lookup, team lookup, and battle-type checks.

Implementations may still expose live mutable objects such as participants, teams, or Pokémon wrappers. Callers should treat this interface as a state view, not as a guarantee that the returned objects are immutable.

  • Method Details

    • battleLog

      BattleLog battleLog()
      Returns the battle log for this battle.
      Returns:
      the battle log
    • outcome

      @Nullable BattleOutcome outcome()
      Returns whether this battle has ended.
      Returns:
      true if the battle has ended; false otherwise
    • battleEnded

      default boolean battleEnded()
    • battleTurn

      int battleTurn()
      Returns the current battle turn number.
      Returns:
      the current battle turn
    • battleTicks

      int battleTicks()
      Returns the number of times the current battle has been ticked.
      This may be incremented multiple times per-server tick depending on the controller's battle tick rate. So this is not necessarily equal to 20 times a second.
      To get the number of battle ticks per second, use battleTicksPerSecond().
      Returns:
      the current battle tick
    • battleTicksPerSecond

      default int battleTicksPerSecond()
      Returns the number of battle ticks that occur per second for this controller.
      The default implementation follows the game rule PixelmonGameRules.BATTLE_TICK_RATE, but custom controllers can override this if they use a different rate source.
      Returns:
      the number of battle ticks per second
    • timeElapsed

      default long timeElapsed(TimeUnit timeUnit)
      Returns the elapsed battle time in the specified time unit.

      This is calculated based on the number of battle ticks and the battle tick rate. It is not based on real-world time, so it may not correspond to actual elapsed time if the server is experiencing lag or if the battle tick rate is modified.

      Parameters:
      timeUnit - the time unit to return
      Returns:
      the elapsed battle time in the specified time unit
    • actionIndex

      int actionIndex()
      Returns the current action index within the active turn.

      This is used while resolving turn actions to identify which action or Pokémon is currently being processed.

      Returns:
      the current action index
    • battleIndex

      int battleIndex()
      Returns this battle's index.
      Returns:
      the battle index
    • battleIndex

      void battleIndex(int battleIndex)
      Sets this battle's index.
      Parameters:
      battleIndex - the battle index
    • getStage

      BattleStage getStage()
      Returns the current stage of the battle.
      Returns:
      the current battle stage
    • globalStatusController

      GlobalStatusController globalStatusController()
      Returns the controller for global battle statuses.
      Returns:
      the global status controller
    • participants

      List<BattleParticipant> participants()
      Returns the participants in this battle.

      The returned list may be backed by the live battle state. Callers should avoid mutating it unless they are part of battle-controller internals.

      Returns:
      the battle participants
    • teams

      Returns the battle participants grouped by team.

      The returned lists may be backed by the live battle state. Callers should avoid mutating them unless they are part of battle-controller internals.

      Returns:
      the battle teams
    • oldGen

      Quadstate oldGen()
      Returns the old-generation rules state for this battle.
      Returns:
      the old-generation rules state
    • oldGen

      void oldGen(Quadstate oldGen)
      Sets the old-generation rules state for this battle.
      Parameters:
      oldGen - the old-generation rules state
    • getBattleType

      default BattleType getBattleType()
      Returns the type of this battle.

      The battle type is stored in the battle context using ContextKeys.BATTLE_TYPE. If no battle type has been set, this defaults to BattleType.SINGLE.

      Returns:
      the battle type
    • isRaid

      default boolean isRaid()
      Returns whether this battle is a raid battle.
      Returns:
      true if this is a raid battle; false otherwise
    • isInverseBattle

      default boolean isInverseBattle()
      Returns whether this battle uses inverse type effectiveness.
      Returns:
      true if this is an inverse battle; false otherwise
    • team

      default List<BattleParticipant> team(int teamId)
      Returns the participants on the specified team.

      If the supplied team ID is outside the valid team range, an empty list is returned.

      Parameters:
      teamId - the team ID
      Returns:
      the participants on the specified team, or an empty list if the team ID is invalid
    • getParticipants

      default List<BattleParticipant> getParticipants(Predicate<BattleParticipant> filter)
      Returns all battle participants matching the supplied filter.
      Parameters:
      filter - the participant filter
      Returns:
      a list of matching participants
    • otherParticipant

      default BattleParticipant otherParticipant(BattleParticipant participant)
      Returns the first participant that is not the supplied participant.

      This helper is only meaningful for simple two-participant battles. In multi-participant battles, the returned participant is not guaranteed to be an opponent or the only other participant.

      Parameters:
      participant - the participant to exclude
      Returns:
      the first other participant, or null if none exists
    • getActivePokemon

      default List<PixelmonWrapper> getActivePokemon()
      Returns all Pokémon currently active in the battle.
      Returns:
      a list of active Pokémon wrappers
    • getActiveUnfaintedPokemon

      default List<PixelmonWrapper> getActiveUnfaintedPokemon()
      Returns all active Pokémon that have not fainted.
      Returns:
      a list of active unfainted Pokémon wrappers
    • getActiveFaintedPokemon

      default List<PixelmonWrapper> getActiveFaintedPokemon()
      Returns all active Pokémon that have fainted.
      Returns:
      a list of active fainted Pokémon wrappers
    • onBattlefield

      default boolean onBattlefield(PixelmonWrapper pokemon)
      Returns whether the specified Pokémon is currently active on the battlefield.

      Pokémon are compared by their Pokémon UUID rather than by wrapper instance.

      Parameters:
      pokemon - the Pokémon to check
      Returns:
      true if the Pokémon is currently active; false otherwise
    • getParticipantForEntity

      @Nullable default BattleParticipant getParticipantForEntity(net.minecraft.world.entity.Entity entity)
      Finds the battle participant represented by the specified entity.
      Parameters:
      entity - the entity to look up
      Returns:
      the matching battle participant, or null if the entity is null or is not participating in this battle
    • getParticipantFromPokemon

      @Nullable default BattleParticipant getParticipantFromPokemon(Pokemon pokemon)
      Finds the battle participant that owns the specified Pokémon.

      If the supplied Pokémon is already a PixelmonWrapper, its participant is returned directly. Otherwise, the battle is searched for a wrapper with the same Pokémon UUID.

      Parameters:
      pokemon - the Pokémon to look up
      Returns:
      the owning battle participant, or null if the Pokémon is not present in this battle
    • getPokemonFromUUID

      @Nullable default PixelmonWrapper getPokemonFromUUID(UUID uuid)
      Finds an active or battle-tracked Pokémon wrapper by Pokémon UUID.
      Parameters:
      uuid - the Pokémon UUID to look up
      Returns:
      the matching Pokémon wrapper, or null if no participant has a Pokémon with that UUID
    • getPartyPokemonFromUUID

      @Nullable default PixelmonWrapper getPartyPokemonFromUUID(UUID uuid)
      Finds a party Pokémon wrapper by Pokémon UUID.

      This searches each participant's party Pokémon, not only the currently active controlled Pokémon.

      Parameters:
      uuid - the Pokémon UUID to look up
      Returns:
      the matching party Pokémon wrapper, or null if none exists
    • getPlayer

      @Nullable default PlayerParticipant getPlayer(String name)
      Finds a player participant by the player's display name.
      Parameters:
      name - the display name to look up
      Returns:
      the matching player participant, or null if no player participant has that display name
    • getPlayer

      @Nullable default PlayerParticipant getPlayer(net.minecraft.world.entity.player.Player player)
      Finds the player participant represented by the specified player entity.
      Parameters:
      player - the player entity to look up
      Returns:
      the matching player participant, or null if the player is not participating in this battle
    • getPlayers

      default List<PlayerParticipant> getPlayers()
      Returns all player participants in this battle.
      Returns:
      a list of player participants
    • getPlayerEntities

      default List<net.minecraft.world.entity.player.Player> getPlayerEntities()
      Returns all player entities participating in this battle.
      Returns:
      a list of player entities
    • isPvP

      default boolean isPvP()
      Returns whether this battle is exclusively between player participants.
      Returns:
      true if every participant is a player participant; false otherwise
    • isPvE

      default boolean isPvE()
      Returns whether this battle is between player and non-player teams.

      Each team must be homogeneous: a team may contain only player participants or only non-player participants. The battle is considered PvE when at least one player-only team and one non-player-only team are present and they are on different sides.

      Returns:
      true if this battle is player-versus-environment; false otherwise
    • isTeamHomogeneous

      default boolean isTeamHomogeneous(List<BattleParticipant> team)
      Returns whether all participants on the given team are the same participant type category.

      An empty team is considered homogeneous. Otherwise, all participants must either be player participants or non-player participants.

      Parameters:
      team - the team to check
      Returns:
      true if the team is homogeneous; false otherwise
    • isTeamDefeated

      default boolean isTeamDefeated(BattleParticipant participant)
      Returns whether the supplied participant's allied side has been defeated.

      The team is considered defeated when all of the participant's allies are marked as defeated.

      Parameters:
      participant - the participant whose allied side should be checked
      Returns:
      true if all allies are defeated; false otherwise
    • playerCount

      default int playerCount()
      Counts the number of player participants in this battle.
      Returns:
      the number of player participants
    • containsParticipantType

      default boolean containsParticipantType(Class<? extends BattleParticipant> participantType)
      Returns whether this battle contains a participant with the exact supplied class.

      This checks exact runtime class equality rather than Class.isInstance(Object). Subclasses of the supplied type will not match.

      Parameters:
      participantType - the participant class to look for
      Returns:
      true if a participant has exactly the supplied class; false otherwise
    • isWaiting

      default boolean isWaiting()
      Returns whether any participant is currently waiting.
      Returns:
      true if at least one participant is waiting; false otherwise