Class BattleController
java.lang.Object
com.pixelmonmod.pixelmon.battles.controller.BattleController
Controls flow of battles.
-
Field Summary
Modifier and TypeFieldDescriptionint
Turn counter for individual Pokémon moving within a battle turn.boolean
Whether the battle has ended.int
The battle's index in the battle registry.The battle log for the battle.protected int
Controls when the battle state is checked.int
The number of turns the battle has lasted.The Pokemon that need to be evolvedprotected List<AttackAnimation>
The currently acting pokemon.protected DynamaxController
Controller tracking dynamax potential during multi-battles.protected boolean
protected boolean
protected final List<FutureBattleTask<?,
?>> Global conditions (e.g., weather) currently active in the battle.boolean
Whether a Pokémon has switched due to a move.The most recent attack used during the battle.The most recent attack used while simulating the battle.The most recent temp attack while simulating the battle.The most recent temp attack used during the battle.int
The number of fainted Pokémon ready to be switched out.Whether the battle is old gen or not.The participants in the battle.int
The number of players in the battle.protected BattleRandomSource
The battle rules that are in effect for the battle.boolean
Whether to send battle messages to the participants.boolean
Whether simulate mode is turned on.boolean
Backup for simulateMode, which sometimes must be disabled while evaluating statuses and stat copying.Spectators of the battleList of teams in the battle.The order of Pokémon moving during a battle turn. -
Constructor Summary
ConstructorDescriptionBattleController
(BattleParticipant[] team1, BattleParticipant[] team2, BattleRules rules) Sets up a battle with participants. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnimation
(AttackAnimation animation) Stores an attack animation that is currently running for this battle.<E extends BattleEvent,
A>
CompletableFuture<A>addFunctionAtEvent
(Class<E> eventClass, BiFunction<E, BattleController, A> task) Adds a task to the battle controller which will execute next time the given event fires and then be removed from the list of future tasks.<E extends BattleEvent>
voidaddPersistentTaskAtEvent
(Class<E> eventClass, BiConsumer<E, BattleController> task) Adds a task to the battle controller which will execute every time the given event fires.<E extends BattleEvent>
CompletableFuture<Void>addTaskAtEvent
(Class<E> eventClass, BiConsumer<E, BattleController> task) Adds a task to the battle controller which will execute next time the given event fires and then be removed from the list of future tasks.void
boolean
arePokemonAdjacent
(PixelmonWrapper pw, PixelmonWrapper other) void
broadcastPacket
(PixelmonPacket packet) boolean
canSpawnEntity
(Pokemon pokemon) Checks if an entity can spawn for this battlevoid
Checks if a participant has been defeated.void
Checks if a Pokémon can be sent out after being revived.boolean
Checks whether the battle is in a valid state.void
Resets the hurt timers of all Pokémon in battle.void
consumeAllItems
(List<PixelmonWrapper> consumed) Consumes all the Pokémon's held items simultaneously.boolean
containsParticipantType
(Class<? extends BattleParticipant> participantType) void
void
boolean
Checks whether the battle controller is performing hard swaps causing aligned switch-in effectsvoid
enableReturnHeldItems
(PixelmonWrapper attacker, PixelmonWrapper target) Enables returning held items for participants of the attacker and target of an action.void
Concludes the battle and determines a victor.endBattle
(BattleEndCause cause) Ends the battle with the given cause.endBattle
(BattleEndCause cause, Map<BattleParticipant, BattleResults> results) Ends the battle with the given cause and any precalculated results.void
Concludes the battles and determines a victor.void
endPause()
Unpauses the battle.void
endTurn()
Handles end-of-turn effects.void
Sets chance checks to be skippedvoid
forceChance
(boolean force) Sets if chance checks should be skippedvoid
forfeitBattleForPlayerAndTheirTeam
(BattleEndCause battleEndCause, net.minecraft.world.entity.player.Player player) void
freeze()
Sets the battle into a frozen state - readisFrozen()
for why you might want to freeze a battlegetAbilityIfPresent
(Class<? extends AbstractAbility> abilityClass) Gets an instance of an ability if it is present in the battle.Returns all fainted Pokémon currently in battle.Returns all Pokémon currently in battle.Returns all unfainted Pokémon currently in battle.getAdjacentOpponents
(PixelmonWrapper pokemon) Gets all opposing Pokémon in the battle adjacent to a certain PokémongetAdjacentPokemon
(PixelmonWrapper adjacentTo) Gets all Pokémon in the battle adjacent to a certain PokémongetAdjacentPokemonAndSelf
(PixelmonWrapper pokemon) Gets all Pokémon in the battle adjacent to a certain Pokémon, including the targetGets the turn order of Pokémon in the battle without accounting for priority.getFirstMover
(PixelmonWrapper... pokemonList) Gets the first Pokémon to move in the turn order from the given list.getFirstMover
(List<PixelmonWrapper> pokemonList) Gets the first Pokémon to move in the turn order from the given list.getLastMover
(PixelmonWrapper... pokemonList) Gets the last Pokémon to move in the turn order from the given list.getLastMover
(List<PixelmonWrapper> pokemonList) Gets the last Pokémon to move in the turn order from the given list.getOpponentPokemon
(BattleParticipant participant) Returns all Pokemon on the opposite side of the battle that the specified participant is on.Returns all Pokemon on the opposite side of the battle that the specified Pokemon is on.getOpponents
(BattleParticipant participant) Finds the participants on the opposing side of the battle.Finds the Pokémon directly opposite of the specified Pokémon.getParticipantForEntity
(net.minecraft.world.entity.Entity entity) Finds the battle participant from the specified entity.getPartyPokemonFromUUID
(UUID uuid) Gets a Pokémon in the battle from its UUID.Gets a player in the battle.getPlayer
(net.minecraft.world.entity.player.Player player) Gets a player in the battle.List<net.minecraft.server.level.ServerPlayer>
Returns a list of the player entities in the battleReturns a list of player participants in the battle.getPokemonAtPosition
(int position) Returns the Pokémon at the specified position in the battle.getPokemonFromUUID
(UUID uuid) Gets a Pokémon in the battle from its UUID.getPokemonWithAbility
(Class<? extends AbstractAbility> abilityClass) Gets pokemon with an ability if they are present in the battle.int
Returns the position of the specified Pokémon in battle.int
Returns the position of a certain Pokémon in a participant's lineup.boolean
getRandomChance
(float chance) boolean
getRandomChance
(int chance) Gets a list of all the spectators of a battlegetStage()
Returns the current stage of the battle.getTeam
(BattleParticipant participant) Finds the participants on the same side of the battle.getTeamPokemon
(BattleParticipant participant) Returns all Pokemon on the side of the battle that the specified participant is on.getTeamPokemon
(PixelmonWrapper pokemon) Returns all allied Pokemon on the side of the battle that the specified Pokémon is on.getTeamPokemon
(PixelmonEntity pokemon) Returns all allied Pokemon on the side of the battle that the specified Pokémon is on.getTeamPokemonExcludeSelf
(PixelmonWrapper pokemon) Returns all allied Pokémon on the side of the battle that the specified Pokémon is on, except for the specified Pokémon itself.int
getTurn
(PixelmonWrapper pixelmonWrapper) Gets the ID of the turn for the pokemonint
getTurnForPokemon
(PixelmonWrapper pokemon) Gets the position of the specified Pokémon in the turn order.List<net.minecraft.server.level.ServerPlayer>
Gets a list of all players that are viewing the battle
This includes all players that are in the battle as well as spectatorsprotected void
Initiates the battle.boolean
isFrozen()
If the battle is in a frozen state When the battle is frozen this means that turns will not be taken, and attacks or moves will not be taken.boolean
Checks whether the current ply is the last Pokémon in turn order.boolean
Checks if any settings disable Pokémon from leveling up in the battle.boolean
isOneAlive
(List<PixelmonWrapper> teamPokemon) Checks whether there is a non-fainted Pokémon among the given Pokémon list.boolean
isPvP()
Determines whether the battle is between players.boolean
isRaid()
boolean
boolean
isSpectating
(net.minecraft.world.entity.player.Player player) boolean
isTeamDefeated
(BattleParticipant participant) Checks if the participant's team has been defeated.boolean
Determines whether a battle participant is waiting.void
Modifies Pokémon stats during a turn.void
Call every version of the modifyStats function, using the Pokémon's base stats.void
modifyStats
(PixelmonWrapper pw, int[] stats) Call every version of the modifyStats function, using the given stats.void
modifyStatsCancellable
(PixelmonWrapper attacker) Modifies Pokémon stats during a turn after deciding which Pokémon gets to make a move.boolean
onBattlefield
(PixelmonWrapper pokemon) Checks if a Pokémon is currently in the battle.otherParticipant
(BattleParticipant participant) Get the other participant in the battle.boolean
Checks if a participant is capable of dynamaxing and that it is their turn.void
Alerted from a packet received from a participant that they have viewed all the battle messages and the next sub-turn can begin.void
Pauses the battle.void
postSpawnEntity
(Pokemon pokemon, PixelmonEntity entity) Method for after the entity has been spawned in battlerandom()
Gets this battle'sBattleRandomSource
, which supplies all random values needed for the battle.void
Removes a Pokémon from the turn list if the Pokémon has not made a move yet.boolean
removeSpectator
(net.minecraft.server.level.ServerPlayer player) Removes a spectator from the battle.void
void
sendDamagePacket
(PixelmonWrapper target, int damage) Sends a damage packet to the participant clients.void
sendHealPacket
(PixelmonWrapper target, int amount) Sends a healing packet to the participant clients.void
sendSwitchPacket
(UUID oldUUID, PixelmonWrapper newPokemon) Updates all clients with a Pokémon switch.void
Sends a battle message to all participants in the battle.void
sendToAll
(net.minecraft.network.chat.Component message) Sends a battle message to all participants in the battle.void
sendToOthers
(String string, BattleParticipant battleParticipant, Object... data) Sends a battle message to all participants besides the given participant.void
sendToPlayer
(net.minecraft.world.entity.player.Player player, String string, Object... data) Sends a battle message to a player.void
sendToPlayer
(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message) Sends a battle message to a player.void
Sets all players as ready.void
Sets a Pokémon to flee in the turn.boolean
This function first checks if there is no weather (i.e.void
setRandom
(BattleRandomSource random) Sets this battle'sBattleRandomSource
to a provided instance.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.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.boolean
If chance checks should be skippedvoid
spectate
(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.entity.Entity target) void
storeSwitchInActivation
(PixelmonWrapper pw, PixelmonWrapper former) void
switchPokemon
(UUID switchingPokemonUUID, UUID newPokemonUUID, boolean switchInstantly) Switches a Pokémon out for a different one.void
void
takeFullTurn
(Runnable moveSelection) void
Moves pokemon to end of list of pokemon gaining their abilitiesboolean
Checks whether the specified Pokémon will try to flee.boolean
tryFlee
(PixelmonWrapper p, boolean turnEnd) Checks if the given Pokemon will try to flee.void
unfreeze()
Un-freezes the battle - readisFrozen()
for why you might want to freeze a battlevoid
update()
Updates the battle every tick.void
updateFormChange
(PixelmonWrapper pokemon) Updates the battle GUI when a Pokémon changes form.void
updateFormChange
(PixelmonEntity pokemon) Updates the battle GUI when a Pokémon changes form.void
Updates players when a Pokémon is removed from battle and not replaced.void
Updates the battle every tick.
-
Field Details
-
participants
The participants in the battle. -
teams
List of teams in the battle. -
globalStatusController
Global conditions (e.g., weather) currently active in the battle. -
spectators
Spectators of the battle -
battleTicks
protected int battleTicksControls when the battle state is checked. -
battleTurn
public int battleTurnThe number of turns the battle has lasted. -
playerNumber
public int playerNumberThe number of players in the battle. -
battleEnded
public boolean battleEndedWhether the battle has ended. -
battleIndex
public int battleIndexThe battle's index in the battle registry. -
battleLog
The battle log for the battle. -
lastAttack
The most recent attack used during the battle. -
lastSimulatedAttack
The most recent attack used while simulating the battle. -
lastTempAttack
The most recent temp attack used during the battle. -
lastSimulatedTempAttack
The most recent temp attack while simulating the battle. -
numFainted
public int numFaintedThe number of fainted Pokémon ready to be switched out. -
rules
The battle rules that are in effect for the battle. -
simulateMode
public boolean simulateModeWhether simulate mode is turned on. Used to calculate move results for the battle AI without affecting the actual battle. -
simulateStats
public boolean simulateStatsBackup for simulateMode, which sometimes must be disabled while evaluating statuses and stat copying. -
sendMessages
public boolean sendMessagesWhether to send battle messages to the participants. Used for simulating certain effects for the battle AI. -
oldGen
Whether the battle is old gen or not. -
dynamaxController
Controller tracking dynamax potential during multi-battles. -
hasSwitchedDuringThisMove
public boolean hasSwitchedDuringThisMoveWhether a Pokémon has switched due to a move. Only one Pokémon may switch per move. -
currentAnimations
-
checkedPokemon
The Pokemon that need to be evolved -
frozen
protected boolean frozen -
forceChance
protected boolean forceChance -
futureTasks
-
random
-
actionIndex
public int actionIndexTurn counter for individual Pokémon moving within a battle turn. -
currentlyActingPokemon
The currently acting pokemon. -
turnList
The order of Pokémon moving during a battle turn.
-
-
Constructor Details
-
BattleController
Sets up a battle with participants.- Parameters:
team1
- One side of the battle.team2
- The other side of the battle.rules
- The rules of the battle.
-
-
Method Details
-
initBattle
Initiates the battle.- Throws:
IllegalStateException
- If any participants have invalid pokemon this will get thro0wn
-
doLater
-
update
public void update()Updates the battle every tick. -
takeFullTurn
public void takeFullTurn() -
advanceToMoves
public void advanceToMoves() -
takeFullTurn
-
doTurnLogic
public void doTurnLogic() -
updateTurnZero
public void updateTurnZero()Updates the battle every tick. Called before any Pokémon makes an attack for that turn. -
modifyStats
public void modifyStats()Modifies Pokémon stats during a turn. -
modifyStats
Call every version of the modifyStats function, using the Pokémon's base stats.- Parameters:
pw
- The Pokémon whose stats are being modified.
-
modifyStats
Call every version of the modifyStats function, using the given stats.- Parameters:
pw
- The Pokémon whose stats are being modified.
-
modifyStatsCancellable
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.
-
participantReady
Alerted from a packet received from a participant that they have viewed all the battle messages and the next sub-turn can begin.- Parameters:
p
- The player.
-
setAllReady
public void setAllReady()Sets all players as ready. -
endTurn
public void endTurn()Handles end-of-turn effects. -
checkReviveSendOut
Checks if a Pokémon can be sent out after being revived.- Parameters:
p
- The participant to check for sending out a revived Pokémon.
-
reviveAfterDefeat
-
endBattle
Ends the battle with the given cause. -
endBattle
public Map<BattleParticipant,BattleResults> endBattle(BattleEndCause cause, Map<BattleParticipant, BattleResults> results) Ends the battle with the given cause and any precalculated results. This method is called by ALL other end of battle methods. -
endBattle
public void endBattle()Concludes the battle and determines a victor. -
endBattleWithoutXP
public void endBattleWithoutXP()Concludes the battles and determines a victor. Does not reward any experience. -
participantCanDynamax
Checks if a participant is capable of dynamaxing and that it is their turn. -
timedAbilityStarted
Moves pokemon to end of list of pokemon gaining their abilities -
getPokemonOrderedByAbilityGain
-
isPvP
public boolean isPvP()Determines whether the battle is between players.- Returns:
- Whether the battle is between players.
-
pauseBattle
public void pauseBattle()Pauses the battle. -
isWaiting
public boolean isWaiting()Determines whether a battle participant is waiting.- Returns:
- Whether a battle participant is waiting.
-
endPause
public void endPause()Unpauses the battle. -
tryFlee
Checks whether the specified Pokémon will try to flee.- Parameters:
p
- The Pokémon to check.- Returns:
- Whether the Pokémon will try to flee.
-
tryFlee
Checks if the given Pokemon will try to flee.- Parameters:
p
- The pokemon being checkedturnEnd
- If it's turn end (i.e. don't look back to see if they've already had their turn)- Returns:
- true if the pokemon will try fleeing
-
updateRemovedPokemon
Updates players when a Pokémon is removed from battle and not replaced.- Parameters:
poke
- The Pokémon to remove.
-
isOneAlive
Checks whether there is a non-fainted Pokémon among the given Pokémon list.- Parameters:
teamPokemon
- The list of Pokémon to check.- Returns:
- Whether there is a non-fainted Pokémon.
-
checkDefeated
Checks if a participant has been defeated.- Parameters:
p
- The participant to check.poke
- The Pokémon that just fainted.
-
sendToAll
Sends a battle message to all participants in the battle.- Parameters:
string
- The lang string to be translated.data
- Any parameters for the lang string.
-
sendToAll
public void sendToAll(net.minecraft.network.chat.Component message) Sends a battle message to all participants in the battle.- Parameters:
message
- The message to send.
-
sendToOthers
Sends a battle message to all participants besides the given participant.- Parameters:
string
- The lang string to be translated.battleParticipant
- The participant to exclude when sending the message.data
- Any parameters for the lang string.
-
sendToPlayer
public void sendToPlayer(net.minecraft.world.entity.player.Player player, String string, Object... data) Sends a battle message to a player.- Parameters:
player
- The player to send the message to.string
- The lang string to be translated.data
- Any parameters for the lang string.
-
sendToPlayer
public void sendToPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message) Sends a battle message to a player.- Parameters:
player
- The player to send the message to.message
- The message to send.
-
clearHurtTimer
public void clearHurtTimer()Resets the hurt timers of all Pokémon in battle. -
setUseItem
public 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
public 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.
-
switchPokemon
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.
-
storeSwitchInActivation
-
setFlee
Sets a Pokémon to flee in the turn.- Parameters:
fleeingUUID
- The fleeing Pokémon.
-
getOpponents
Finds the participants on the opposing side of the battle.- Parameters:
participant
- The participant to find opponents for.- Returns:
- The specified participant's opponents.
-
getTeam
Finds the participants on the same side of the battle.- Parameters:
participant
- The participant to find teammates for.- Returns:
- The specified participant's teammates.
-
getActivePokemon
Returns all Pokémon currently in battle.- Returns:
- A list of all Pokémon currently in battle.
-
getActiveUnfaintedPokemon
Returns all unfainted Pokémon currently in battle.- Returns:
- A list of all unfainted Pokémon currently in battle.
-
getActiveFaintedPokemon
Returns all fainted Pokémon currently in battle.- Returns:
- A list of all fainted Pokémon currently in battle.
-
getAdjacentPokemon
Gets all Pokémon in the battle adjacent to a certain Pokémon- Parameters:
adjacentTo
- The Pokémon to get adjacent Pokémon for.- Returns:
- The Pokémon adjacent to the specified Pokémon in battle.
-
getAdjacentOpponents
Gets all opposing Pokémon in the battle adjacent to a certain Pokémon- Parameters:
pokemon
- The Pokémon to get adjacent Pokémon for.- Returns:
- The opposing Pokémon adjacent to the specified Pokémon in battle.
-
arePokemonAdjacent
-
getAdjacentPokemonAndSelf
Gets all Pokémon in the battle adjacent to a certain Pokémon, including the target- Parameters:
pokemon
- The Pokémon to get adjacent Pokémon for.- Returns:
- The Pokémon adjacent to the specified Pokémon in battle, and the specificed Pokémon
-
getTeamPokemon
Returns all Pokemon on the side of the battle that the specified participant is on.- Parameters:
participant
- The participant to find team Pokemon for.- Returns:
- A list of all Pokemon on the side of the battle that the participant is on.
-
getTeamPokemon
Returns all allied Pokemon on the side of the battle that the specified Pokémon is on.- Parameters:
pokemon
- The Pokémon to find allied Pokemon for.- Returns:
- A list of all allied Pokemon on the side of the battle that the specified Pokémon is on.
-
getTeamPokemon
Returns all allied Pokemon on the side of the battle that the specified Pokémon is on.- Parameters:
pokemon
- The Pokémon to find allied Pokemon for.- Returns:
- A list of all allied Pokemon on the side of the battle that the specified Pokémon is on.
-
getTeamPokemonExcludeSelf
Returns all allied Pokémon on the side of the battle that the specified Pokémon is on, except for the specified Pokémon itself.- Parameters:
pokemon
- The Pokémon to find allied Pokemon for.- Returns:
- A list of all allied Pokemon on the side of the battle that the specified Pokémon is on, except for the specified Pokémon itself.
-
getOpponentPokemon
Returns all Pokemon on the opposite side of the battle that the specified participant is on.- Parameters:
participant
- The participant to find opponent Pokemon for.- Returns:
- A list of all Pokemon on the opposite of the battle that the participant is on.
-
getOpponentPokemon
Returns all Pokemon on the opposite side of the battle that the specified Pokemon is on.- Parameters:
pw
- The Pokemon to find opponent Pokemon for.- Returns:
- A list of all Pokemon on the opposite of the battle that the Pokemon is on.
-
onBattlefield
Checks if a Pokémon is currently in the battle.- Parameters:
pokemon
- The Pokémon to find.- Returns:
- Whether the specified Pokémon is currently in the battle.
-
getParticipantForEntity
@Nullable public BattleParticipant getParticipantForEntity(net.minecraft.world.entity.Entity entity) Finds the battle participant from the specified entity.- Parameters:
entity
- The entity to find the battle participant for.- Returns:
- The battle participant from the entity.
-
consumeAllItems
Consumes all the Pokémon's held items simultaneously. -
sendDamagePacket
Sends a damage packet to the participant clients.- Parameters:
target
- The Pokémon being damaged.damage
- The amount of damage dealt.
-
sendHealPacket
Sends a healing packet to the participant clients.- Parameters:
target
- The Pokémon being healed.amount
- The amount of healing.
-
getSpectators
Gets a list of all the spectators of a battle- Returns:
- A list of all the spectators of a battle
-
getViewingPlayers
Gets a list of all players that are viewing the battle
This includes all players that are in the battle as well as spectators- Returns:
- A list of all players that are viewing the battle
-
broadcastPacket
-
getOppositePokemon
Finds the Pokémon directly opposite of the specified Pokémon.- Parameters:
pw
- The Pokémon to get the opposite Pokémon for.- Returns:
- The opposite Pokémon.
-
getPokemonAtPosition
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
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.
-
getPositionOfPokemon
Returns the position of a certain Pokémon in a participant's lineup.- Parameters:
poke
- The Pokémon to get the position of.bp
- The participant with the Pokémon.- Returns:
- The Pokémon's position, or -1 if the Pokémon is not in the participant's team.
-
getStage
Returns the current stage of the battle.- Returns:
- The current stage of the battle.
-
enableReturnHeldItems
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.
-
checkValid
public boolean checkValid()Checks whether the battle is in a valid state. End the battle if it is not.- Returns:
- Whether the battle is valid.
-
getPlayer
Gets a player in the battle.- Parameters:
name
- The name of the player to look for.- Returns:
- The player participant with the given name in the battle, or null if no player in the battle has the given name.
-
getPlayer
Gets a player in the battle.- Parameters:
player
- The player to look for.- Returns:
- The player participant representing the given player, or null if the player is not in this battle.
-
getPlayers
Returns a list of player participants in the battle.- Returns:
- A list of player participants in the battle.
-
getPlayerEntities
Returns a list of the player entities in the battle- Returns:
- The players
-
isTeamDefeated
Checks if the participant's team has been defeated.- Parameters:
participant
- The participant whose team to check.- Returns:
- Whether the participant's team is defeated.
-
getTurnForPokemon
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.
-
otherParticipant
Get the other participant in the battle.- Parameters:
participant
- Your participant Object to get the other participant from.- Returns:
- BattleParticipant to return.
-
getFirstMover
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
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
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
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.
-
getAbilityIfPresent
Gets an instance of an ability if it is present in the battle.- Returns:
- If present, the instance of the ability.
-
getPokemonWithAbility
Gets pokemon with an ability if they are present in the battle.- Returns:
- The pokemon with the specified ability, or an empty list.
-
sendSwitchPacket
Updates all clients with a Pokémon switch.- Parameters:
oldUUID
- The ID of the Pokémon switching out.newPokemon
- The Pokémon switching in.
-
spectate
public void spectate(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.entity.Entity target) -
getBattleType
-
isSpectating
public boolean isSpectating(net.minecraft.world.entity.player.Player player) -
removeSpectator
public boolean removeSpectator(net.minecraft.server.level.ServerPlayer player) Removes a spectator from the battle.- Parameters:
player
- The spectator to remove from the battle.- Returns:
- Whether the spectator was in the battle.
-
getPokemonFromUUID
Gets a Pokémon in the battle from its UUID.- Parameters:
uuid
- The UUID of the Pokémon to get.- Returns:
- The Pokémon with the specified UUID, or null if no Pokémon have the UUID.
-
getPartyPokemonFromUUID
Gets a Pokémon in the battle from its UUID.- Parameters:
uuid
- The UUID of the Pokémon to get.- Returns:
- The Pokémon with the specified UUID, or null if no Pokémon have the UUID.
-
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.
-
removeFromTurnList
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.
-
getTurn
Gets the ID of the turn for the pokemon- Parameters:
pixelmonWrapper
- The pokemon- Returns:
- The turn ID
-
isLastMover
public 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.
-
duringSwitchAction
public 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
-
containsParticipantType
-
updateFormChange
Updates the battle GUI when a Pokémon changes form.- Parameters:
pokemon
- The Pokémon who changed form.
-
updateFormChange
Updates the battle GUI when a Pokémon changes form.- Parameters:
pokemon
- The Pokémon who changed form.
-
isLevelingDisabled
public boolean isLevelingDisabled()Checks if any settings disable Pokémon from leveling up in the battle.- Returns:
- Whether any settings disable Pokémon from leveling up in the battle.
-
isRaid
public boolean isRaid() -
isSimulation
public boolean isSimulation() -
getLastAttack
-
getLastTempAttack
-
setOverworldWeatherAsBattleWeatherDuringBattle
public boolean setOverworldWeatherAsBattleWeatherDuringBattle()This function first checks if there is no weather (i.e. the weather is Clear) or if the current battle weather represented the Minecraft Overworld. If either of those conditions are true, it rechecks what the current Minecraft weather is and changes the battle weather to that if necessary.- Returns:
- Whether the weather was changed mid-battle.
-
addFunctionAtEvent
public <E extends BattleEvent,A> CompletableFuture<A> addFunctionAtEvent(Class<E> eventClass, BiFunction<E, BattleController, A> task) Adds a task to the battle controller which will execute next time the given event fires and then be removed from the list of future tasks. This method returns a future which is completed when the task is executed.- Type Parameters:
E
- The battle event type- Parameters:
eventClass
- The class of the event to wait fortask
- The task to execute when the event occurs- Returns:
- The future for when the task is executed
-
addTaskAtEvent
public <E extends BattleEvent> CompletableFuture<Void> addTaskAtEvent(Class<E> eventClass, BiConsumer<E, BattleController> task) Adds a task to the battle controller which will execute next time the given event fires and then be removed from the list of future tasks. This method returns a future which is completed when the task is executed.- Type Parameters:
E
- The battle event type- Parameters:
eventClass
- The class of the event to wait fortask
- The task to execute when the event occurs- Returns:
- The future for when the task is executed
-
addPersistentTaskAtEvent
public <E extends BattleEvent> void addPersistentTaskAtEvent(Class<E> eventClass, BiConsumer<E, BattleController> task) Adds a task to the battle controller which will execute every time the given event fires. Because this fires multiple times there is no future for when this executes- Type Parameters:
E
- The event type- Parameters:
eventClass
- The class of the event being waited fortask
- The task that will execute
-
isFrozen
public boolean isFrozen()If the battle is in a frozen state When the battle is frozen this means that turns will not be taken, and attacks or moves will not be taken. This is only really useful for unit testing where we need to dictate exactly what happens and control the battle very precisely so that we know nothing else is going on- Returns:
- True if the battle is frozen
-
freeze
public void freeze()Sets the battle into a frozen state - readisFrozen()
for why you might want to freeze a battle -
forceChance
public void forceChance()Sets chance checks to be skipped -
forceChance
public void forceChance(boolean force) Sets if chance checks should be skipped- Parameters:
force
- Whether the controller should skip chance checks
-
shouldForceChance
public boolean shouldForceChance()If chance checks should be skipped- Returns:
- True if all chance checks should be skipped
-
getRandomChance
public boolean getRandomChance(int chance) -
getRandomChance
public boolean getRandomChance(float chance) -
unfreeze
public void unfreeze()Un-freezes the battle - readisFrozen()
for why you might want to freeze a battle -
addAnimation
Stores an attack animation that is currently running for this battle.- Parameters:
animation
- The animation to store
-
random
Gets this battle'sBattleRandomSource
, which supplies all random values needed for the battle.- Returns:
- This battle's
BattleRandomSource
.
-
setRandom
Sets this battle'sBattleRandomSource
to a provided instance.- Parameters:
random
- The newBattleRandomSource
to use for this battle.
-
canSpawnEntity
Checks if an entity can spawn for this battle- Parameters:
pokemon
- The pokemon to check- Returns:
- True if the entity can spawn
-
postSpawnEntity
Method for after the entity has been spawned in battle- Parameters:
pokemon
- The pokemonentity
- The entity that was spawned
-
forfeitBattleForPlayerAndTheirTeam
public void forfeitBattleForPlayerAndTheirTeam(BattleEndCause battleEndCause, net.minecraft.world.entity.player.Player player)
-