Interface BattleController
- All Superinterfaces:
BattleEvents,BattleMessaging,BattleRandomContext,BattleSimulationContext,BattleSpectating,BattleStateView,ContextHolder,LegacyBattleAISupport,RegistryBacked
- All Known Implementing Classes:
MultiLaneBattleController,StandardBattleController
public interface BattleController
extends ContextHolder, RegistryBacked, BattleStateView, BattleSimulationContext, BattleRandomContext, BattleSpectating, BattleMessaging, BattleEvents, LegacyBattleAISupport
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidacknowledgeBattleAnimation(net.minecraft.server.level.ServerPlayer player, UUID acknowledgementId) Acknowledges completion of a client-side battle animation wait.voidaddBattleAnimation(ActiveBattleAnimation animation) Stores a battle animation that is currently running for this battle.default voiddefault Stringdefault voidbattleAnimationChannelId(String battleAnimationChannelId) This method returns a set of Pokémon that need to be evolved at the end of the turn.voidChecks the conditions of the active Pokémon.default booleanChecks whether the battle is in a valid state.default voidcleanUpBattleAnimationChannel(String channel) default voidResets the hurt timers of all Pokémon in battle.default voidconsumeAllItems(List<PixelmonWrapper> consumed) Consumes all the Pokémon's held items simultaneously.voidcurrentlyActingPokemon(PixelmonWrapper currentlyActingPokemon) voidbooleanChecks whether the battle controller is performing hard swaps causing aligned switch-in effectsdefault voidenableReturnHeldItems(PixelmonWrapper attacker, PixelmonWrapper target) Enables returning held items for participants of the attacker and target of an action.default Map<BattleParticipant, BattleResults> Concludes the battle and determines a victor.default Map<BattleParticipant, BattleResults> 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.default Map<BattleParticipant, BattleResults> Concludes the battles and determines a victor.voidendPause()Unpauses the battle.voidendTurn()Handles end-of-turn effects.default Map<BattleParticipant, BattleResults> forfeitBattleForPlayerAndTheirTeam(BattleEndCause battleEndCause, net.minecraft.world.entity.player.Player player) getAbilityIfPresent(Class<? extends AbstractAbility> abilityClass) Gets an instance of an ability if it is present in the battle.default List<PixelmonWrapper> Gets the turn order of Pokémon in the battle without accounting for priority.default PixelmonWrappergetFirstMover(PixelmonWrapper... pokemonList) Gets the first Pokémon to move in the turn order from the given list.default PixelmonWrappergetFirstMover(List<PixelmonWrapper> pokemonList) Gets the first Pokémon to move in the turn order from the given list.default PixelmonWrappergetLastMover(PixelmonWrapper... pokemonList) Gets the last Pokémon to move in the turn order from the given list.default PixelmonWrappergetLastMover(List<PixelmonWrapper> pokemonList) Gets the last Pokémon to move in the turn order from the given list.default PixelmonWrappergetPokemonAtPosition(int position) Returns the Pokémon at the specified position in the battle.default List<PixelmonWrapper> getPokemonWithAbility(Class<? extends AbstractAbility> abilityClass) Gets pokemon with an ability if they are present in the battle.default intReturns the position of the specified Pokémon in battle.default intReturns the battle position of a Pokémon.default intgetTurn(PixelmonWrapper pixelmonWrapper) Gets the ID of the turn for the pokemondefault intgetTurnForPokemon(PixelmonWrapper pokemon) Gets the position of the specified Pokémon in the turn order.booleanThis method returns if a Pokémon has switched due to a move during this move.voidhasSwitchedDuringThisMove(boolean hasSwitchedDuringThisMove) This method sets whether a Pokémon has switched due to a move during this move.default booleanisBattleAnimationChannelBusy(String channel) default booleanChecks whether the current ply is the last Pokémon in turn order.voidlastAttack(Attack attack) voidlastSimulatedAttack(Attack attack) voidlastSimulatedTempAttack(Attack attack) voidlastTempAttack(Attack attack) default voidModifies Pokémon stats during a turn.voidmodifyStatsCancellable(PixelmonWrapper attacker) Modifies Pokémon stats during a turn after deciding which Pokémon gets to make a move.booleanChecks if a participant is capable of dynamaxing and that it is their turn.voidPauses the battle.default voidpublishPokemonHealthUpdate(PixelmonWrapper pokemon, int previousHealth) default voiddefault voidpublishSwitchPokemonEvent(PixelmonWrapper switchedOut, PixelmonWrapper switchedIn) default voidrecordFaintOrder(PixelmonWrapper target, PixelmonWrapper source, DamageTypeEnum damageType) Records a faint after all cancellable faint hooks have completed successfully.default voidRemoves a Pokémon from the turn list if the Pokémon has not made a move yet.default voidremovePlayer(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.default voidreserveFaintOrder(PixelmonWrapper target, PixelmonWrapper source, DamageTypeEnum damageType) Reserves this position in the faint order for effects whose user faints before their target, such as Self-Destruct and Final Gambit.default voidreserveFaintOrderBefore(PixelmonWrapper target, PixelmonWrapper beforeTarget, PixelmonWrapper source, DamageTypeEnum damageType) Reserves a faint immediately before an existing faint.voidFinds any statuses affecting the whole team and determines where a Pokémon being sent into battle should be positioned.default voidsendBattleScenePacket(net.minecraft.server.level.ServerPlayer player) Sends the context-selected battle scene to one player, if one is configured.default voidSends the context-selected battle scene to each player in this battle, if one is configured.default voidSets all players as ready.voidSets a Pokémon to flee in the turn.default voidsetUseItem(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.default voidsetUseItem(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.default booleanDetermines whether participant initialization should emit battle start packets directly.default voidshouldSendBattleStartPackets(boolean shouldSendBattleStartPackets) Sets whether participant initialization should emit battle start packets directly.default PixelmonEntityspawnEntityForBattle(PixelmonWrapper wrapper) This method spawns a PixelmonEntity for the given PixelmonWrapper if entities should be spawned for this battle.voidstoreSwitchInActivation(PixelmonWrapper pw, PixelmonWrapper former) voidswitchPokemon(UUID switchingPokemonUUID, UUID newPokemonUUID, boolean switchInstantly) Switches a Pokémon out for a different one.default <T> voidsync(ContextKey<T> key) This method synchronizes the value stored in the battle context for the given key to all clients participating in the battle.default voiddefault voidtakeFullTurn(Runnable moveSelection) voidMoves pokemon to end of list of pokemon gaining their abilitiesturnList()This method returns the order of Pokémon moving during a battle turn.voidturnList(List<PixelmonWrapper> turnList) This method sets the order of Pokémon moving during a battle turn.voidupdate()Updates the battle every tick.default voidUpdates players when a Pokémon is removed from battle and not replaced.Methods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleEvents
addFunctionAtEvent, addPersistentTaskAtEvent, addTaskAtEvent, publishEventMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleMessaging
broadcastPacket, sendToAll, sendToAll, sendToOthers, sendToOthers, sendToPlayer, updateFormChangeMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleRandomContext
forceChance, forceChance, getAttackDamageCalculator, randomness, setAttackDamageCalculator, setRandom, setRandomness, shouldForceChanceMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleSimulationContext
copy, disableCommunication, freeze, isFrozen, isLevelingDisabled, isSimulatedBattle, shouldSpawnEntities, unfreeze, waitTicks, waitTicksMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleSpectating
isSpectating, removeSpectator, spectate, spectatorsMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.BattleStateView
actionIndex, battleEnded, battleIndex, battleIndex, battleLog, battleTicks, battleTicksPerSecond, battleTurn, containsParticipantType, getActiveFaintedPokemon, getActivePokemon, getActiveUnfaintedPokemon, getBattleType, getParticipantForEntity, getParticipantFromPokemon, getParticipants, getPartyPokemonFromUUID, getPlayer, getPlayer, getPlayerEntities, getPlayers, getPokemonFromUUID, getStage, globalStatusController, isInverseBattle, isPvE, isPvP, isRaid, isTeamDefeated, isTeamHomogeneous, isWaiting, oldGen, oldGen, onBattlefield, otherParticipant, outcome, participants, playerCount, team, teams, timeElapsedMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.context.ContextHolder
get, getContext, getOrDefault, has, remove, set, updateMethods inherited from interface com.pixelmonmod.pixelmon.battles.controller.LegacyBattleAISupport
simulateMode, simulateMode, simulateStats, simulateStatsMethods inherited from interface com.pixelmonmod.pixelmon.api.registry.RegistryBacked
holder, registry, registryAccess, registryValue
-
Method Details
-
update
void update()Updates the battle every tick. -
doTurnLogic
void doTurnLogic() -
advanceToMoves
default void advanceToMoves() -
takeFullTurn
-
takeFullTurn
default void takeFullTurn() -
endTurn
void endTurn()Handles end-of-turn effects. -
modifyStats
default void modifyStats()Modifies Pokémon stats during a turn. -
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.
-
sync
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 theContextKeys.TURN_TIMEwhich 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
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
Stores a battle animation that is currently running for this battle.- Parameters:
animation- The animation to store
-
battleAnimationChannelId
-
battleAnimationChannelId
-
isBattleAnimationChannelBusy
-
cleanUpBattleAnimationChannel
-
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 animationacknowledgementId- the acknowledgement token sent to the client
-
endBattle
Concludes the battle and determines a victor. -
endBattleWithoutXP
Concludes the battles and determines a victor. Does not reward any experience. -
endBattle
Ends the battle with the given cause. -
endBattle
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. -
removePlayer
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
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
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
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
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
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.
-
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.
-
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
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
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 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
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
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
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.
-
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
Checks if a participant is capable of dynamaxing and that it is their turn. -
lastAttack
Attack lastAttack() -
lastAttack
-
lastTempAttack
Attack lastTempAttack() -
lastTempAttack
-
lastSimulatedAttack
Attack lastSimulatedAttack() -
lastSimulatedAttack
-
lastSimulatedTempAttack
Attack lastSimulatedTempAttack() -
lastSimulatedTempAttack
-
getPokemonOrderedByAbilityGain
List<PixelmonWrapper> getPokemonOrderedByAbilityGain() -
timedAbilityStarted
Moves pokemon to end of list of pokemon gaining their abilities -
updateRemovedPokemon
Updates players when a Pokémon is removed from battle and not replaced.- Parameters:
poke- The Pokémon to remove.
-
publishSwitchPokemonEvent
-
publishRevivedPokemonEvent
-
publishPokemonHealthUpdate
-
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
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
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
Consumes all the Pokémon's held items simultaneously. -
currentlyActingPokemon
PixelmonWrapper currentlyActingPokemon() -
currentlyActingPokemon
-
storeSwitchInActivation
-