Interface BattleStateView
- All Superinterfaces:
ContextHolder
- All Known Subinterfaces:
BattleController,BattleMessaging,BattleRandomContext,BattleSimulationContext
- All Known Implementing Classes:
MultiLaneBattleController,StandardBattleController
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 Summary
Modifier and TypeMethodDescriptionintReturns the current action index within the active turn.default booleanintReturns this battle's index.voidbattleIndex(int battleIndex) Sets this battle's index.Returns the battle log for this battle.intReturns the number of times the current battle has been ticked.default intReturns the number of battle ticks that occur per second for this controller.intReturns the current battle turn number.default booleancontainsParticipantType(Class<? extends BattleParticipant> participantType) Returns whether this battle contains a participant with the exact supplied class.default List<PixelmonWrapper> Returns all active Pokémon that have fainted.default List<PixelmonWrapper> Returns all Pokémon currently active in the battle.default List<PixelmonWrapper> Returns all active Pokémon that have not fainted.default BattleTypeReturns the type of this battle.default BattleParticipantgetParticipantForEntity(net.minecraft.world.entity.Entity entity) Finds the battle participant represented by the specified entity.default BattleParticipantgetParticipantFromPokemon(Pokemon pokemon) Finds the battle participant that owns the specified Pokémon.default List<BattleParticipant> getParticipants(Predicate<BattleParticipant> filter) Returns all battle participants matching the supplied filter.default PixelmonWrappergetPartyPokemonFromUUID(UUID uuid) Finds a party Pokémon wrapper by Pokémon UUID.default PlayerParticipantFinds a player participant by the player's display name.default PlayerParticipantgetPlayer(net.minecraft.world.entity.player.Player player) Finds the player participant represented by the specified player entity.default List<net.minecraft.world.entity.player.Player> Returns all player entities participating in this battle.default List<PlayerParticipant> Returns all player participants in this battle.default PixelmonWrappergetPokemonFromUUID(UUID uuid) Finds an active or battle-tracked Pokémon wrapper by Pokémon UUID.getStage()Returns the current stage of the battle.Returns the controller for global battle statuses.default booleanReturns whether this battle uses inverse type effectiveness.default booleanisPvE()Returns whether this battle is between player and non-player teams.default booleanisPvP()Returns whether this battle is exclusively between player participants.default booleanisRaid()Returns whether this battle is a raid battle.default booleanisTeamDefeated(BattleParticipant participant) Returns whether the supplied participant's allied side has been defeated.default booleanReturns whether all participants on the given team are the same participant type category.default booleanReturns whether any participant is currently waiting.oldGen()Returns the old-generation rules state for this battle.voidSets the old-generation rules state for this battle.default booleanonBattlefield(PixelmonWrapper pokemon) Returns whether the specified Pokémon is currently active on the battlefield.default BattleParticipantotherParticipant(BattleParticipant participant) Returns the first participant that is not the supplied participant.outcome()Returns whether this battle has ended.Returns the participants in this battle.default intCounts the number of player participants in this battle.default List<BattleParticipant> team(int teamId) Returns the participants on the specified team.teams()Returns the battle participants grouped by team.default longtimeElapsed(TimeUnit timeUnit) Returns the elapsed battle time in the specified time unit.Methods inherited from interface com.pixelmonmod.pixelmon.battles.controller.context.ContextHolder
get, getContext, getOrDefault, has, remove, set, update
-
Method Details
-
battleLog
BattleLog battleLog()Returns the battle log for this battle.- Returns:
- the battle log
-
outcome
Returns whether this battle has ended.- Returns:
trueif the battle has ended;falseotherwise
-
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, usebattleTicksPerSecond().- 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 rulePixelmonGameRules.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
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
List<List<BattleParticipant>> 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
Sets the old-generation rules state for this battle.- Parameters:
oldGen- the old-generation rules state
-
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 toBattleType.SINGLE.- Returns:
- the battle type
-
isRaid
default boolean isRaid()Returns whether this battle is a raid battle.- Returns:
trueif this is a raid battle;falseotherwise
-
isInverseBattle
default boolean isInverseBattle()Returns whether this battle uses inverse type effectiveness.- Returns:
trueif this is an inverse battle;falseotherwise
-
team
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
Returns all battle participants matching the supplied filter.- Parameters:
filter- the participant filter- Returns:
- a list of matching participants
-
otherParticipant
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
nullif none exists
-
getActivePokemon
Returns all Pokémon currently active in the battle.- Returns:
- a list of active Pokémon wrappers
-
getActiveUnfaintedPokemon
Returns all active Pokémon that have not fainted.- Returns:
- a list of active unfainted Pokémon wrappers
-
getActiveFaintedPokemon
Returns all active Pokémon that have fainted.- Returns:
- a list of active fainted Pokémon wrappers
-
onBattlefield
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:
trueif the Pokémon is currently active;falseotherwise
-
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
nullif the entity isnullor is not participating in this battle
-
getParticipantFromPokemon
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
nullif the Pokémon is not present in this battle
-
getPokemonFromUUID
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
nullif no participant has a Pokémon with that UUID
-
getPartyPokemonFromUUID
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
nullif none exists
-
getPlayer
Finds a player participant by the player's display name.- Parameters:
name- the display name to look up- Returns:
- the matching player participant, or
nullif no player participant has that display name
-
getPlayer
Finds the player participant represented by the specified player entity.- Parameters:
player- the player entity to look up- Returns:
- the matching player participant, or
nullif the player is not participating in this battle
-
getPlayers
Returns all player participants in this battle.- Returns:
- a list of player participants
-
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:
trueif every participant is a player participant;falseotherwise
-
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:
trueif this battle is player-versus-environment;falseotherwise
-
isTeamHomogeneous
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:
trueif the team is homogeneous;falseotherwise
-
isTeamDefeated
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:
trueif all allies are defeated;falseotherwise
-
playerCount
default int playerCount()Counts the number of player participants in this battle.- Returns:
- the number of player participants
-
containsParticipantType
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:
trueif a participant has exactly the supplied class;falseotherwise
-
isWaiting
default boolean isWaiting()Returns whether any participant is currently waiting.- Returns:
trueif at least one participant is waiting;falseotherwise
-