Class BattleController

java.lang.Object
com.pixelmonmod.pixelmon.battles.controller.BattleController

public class BattleController extends Object
Controls flow of battles.
  • Field Details

    • participants

      public List<BattleParticipant> participants
      The participants in the battle.
    • globalStatusController

      public GlobalStatusController globalStatusController
      Global conditions (e.g., weather) currently active in the battle.
    • spectators

      public List<Spectator> spectators
      Spectators of the battle
    • battleTicks

      protected int battleTicks
      Controls when the battle state is checked.
    • battleTurn

      public int battleTurn
      The number of turns the battle has lasted.
    • playerNumber

      public int playerNumber
      The number of players in the battle.
    • battleEnded

      public boolean battleEnded
      Whether the battle has ended.
    • battleIndex

      public int battleIndex
      The battle's index in the battle registry.
    • battleLog

      public BattleLog battleLog
      The battle log for the battle.
    • lastAttack

      public Attack lastAttack
      The most recent attack used during the battle.
    • lastSimulatedAttack

      public Attack lastSimulatedAttack
      The most recent attack used while simulating the battle.
    • lastTempAttack

      public Attack lastTempAttack
      The most recent temp attack used during the battle.
    • lastSimulatedTempAttack

      public Attack lastSimulatedTempAttack
      The most recent temp attack while simulating the battle.
    • numFainted

      public int numFainted
      The number of fainted Pokémon ready to be switched out.
    • rules

      public BattleRules rules
      The battle rules that are in effect for the battle.
    • simulateMode

      public boolean simulateMode
      Whether simulate mode is turned on. Used to calculate move results for the battle AI without affecting the actual battle.
    • simulateStats

      public boolean simulateStats
      Backup for simulateMode, which sometimes must be disabled while evaluating statuses and stat copying.
    • sendMessages

      public boolean sendMessages
      Whether to send battle messages to the participants. Used for simulating certain effects for the battle AI.
    • wasFishing

      public boolean wasFishing
      Whether the battle was started via fishing.
    • oldGen

      public Quadstate oldGen
      Whether the battle is old gen or not.
    • currentAnimations

      protected List<AttackAnimation> currentAnimations
    • checkedPokemon

      public Set<Pokemon> checkedPokemon
      The Pokemon that need to be evolved
    • frozen

      protected boolean frozen
    • forceChance

      protected boolean forceChance
    • futureTasks

      protected final List<FutureBattleTask<?,?>> futureTasks
    • random

      protected BattleRandomSource random
    • actionIndex

      public int actionIndex
      Turn counter for individual Pokémon moving within a battle turn.
    • turnList

      public List<PixelmonWrapper> turnList
      The order of Pokémon moving during a battle turn.
  • Constructor Details

    • BattleController

      public BattleController(BattleParticipant[] team1, BattleParticipant[] team2, BattleRules rules)
      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

      protected void initBattle() throws IllegalStateException
      Initiates the battle.
      Throws:
      IllegalStateException - If any participants have invalid pokemon this will get thro0wn
    • doLater

      public void doLater(Runnable runnable, int ticks)
    • update

      public void update()
      Updates the battle every tick.
    • takeFullTurn

      public void takeFullTurn()
    • advanceToMoves

      public void advanceToMoves()
    • takeFullTurn

      public void takeFullTurn(Runnable moveSelection)
    • 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

      public void modifyStats(PixelmonWrapper pw)
      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

      public void modifyStats(PixelmonWrapper pw, int[] stats)
      Call every version of the modifyStats function, using the given stats.
      Parameters:
      pw - The Pokémon whose stats are being modified.
    • modifyStatsCancellable

      public 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.
    • participantReady

      public void participantReady(PlayerParticipant p)
      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

      public void checkReviveSendOut(BattleParticipant p)
      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

      public void reviveAfterDefeat(BattleParticipant p)
    • endBattle

      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.
    • 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.
    • timedAbilityStarted

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

      public List<PixelmonWrapper> 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

      public boolean tryFlee(PixelmonWrapper p)
      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

      public boolean tryFlee(PixelmonWrapper p, boolean turnEnd)
      Checks if the given Pokemon will try to flee.
      Parameters:
      p - The pokemon being checked
      turnEnd - 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

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

      public boolean isOneAlive(List<PixelmonWrapper> teamPokemon)
      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

      public void checkDefeated(BattleParticipant p, PixelmonWrapper poke)
      Checks if a participant has been defeated.
      Parameters:
      p - The participant to check.
      poke - The Pokémon that just fainted.
    • sendToAll

      public void sendToAll(String string, Object... data)
      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

      public void sendToOthers(String string, BattleParticipant battleParticipant, Object... data)
      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.
    • sendToPlayers

      public void sendToPlayers(PixelmonPacket message)
    • 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

      public 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.
    • storeSwitchInActivation

      public void storeSwitchInActivation(PixelmonWrapper pw, PixelmonWrapper former)
    • setFlee

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

      public ParticipantType[][] getBattleType(BattleParticipant teammate)
      Gets the types of participants in the battle.
      Parameters:
      teammate - The participant whose side will be listed first in the returned 2D array.
      Returns:
      The types of participants in the battle as a 2D array, with the teammate's side first.
    • updatePokemonHealth

      public void updatePokemonHealth()
      Update Pokémon's health.
    • getOpponents

      public List<BattleParticipant> getOpponents(BattleParticipant participant)
      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

      public List<BattleParticipant> getTeam(BattleParticipant participant)
      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

      public List<PixelmonWrapper> getActivePokemon()
      Returns all Pokémon currently in battle.
      Returns:
      A list of all Pokémon currently in battle.
    • getActiveUnfaintedPokemon

      public List<PixelmonWrapper> getActiveUnfaintedPokemon()
      Returns all unfainted Pokémon currently in battle.
      Returns:
      A list of all unfainted Pokémon currently in battle.
    • getActiveFaintedPokemon

      public List<PixelmonWrapper> getActiveFaintedPokemon()
      Returns all fainted Pokémon currently in battle.
      Returns:
      A list of all fainted Pokémon currently in battle.
    • getAdjacentPokemon

      public List<PixelmonWrapper> getAdjacentPokemon(PixelmonWrapper adjacentTo)
      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

      public List<PixelmonWrapper> getAdjacentOpponents(PixelmonWrapper pokemon)
      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

      public boolean arePokemonAdjacent(PixelmonWrapper pw, PixelmonWrapper other)
    • getAdjacentPokemonAndSelf

      public List<PixelmonWrapper> getAdjacentPokemonAndSelf(PixelmonWrapper pokemon)
      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

      public List<PixelmonWrapper> getTeamPokemon(BattleParticipant participant)
      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

      public List<PixelmonWrapper> getTeamPokemon(PixelmonWrapper pokemon)
      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

      public List<PixelmonWrapper> getTeamPokemon(PixelmonEntity pokemon)
      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

      public List<PixelmonWrapper> 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.
      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

      public List<PixelmonWrapper> getOpponentPokemon(BattleParticipant participant)
      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

      public List<PixelmonWrapper> getOpponentPokemon(PixelmonWrapper pw)
      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.
    • isInBattle

      public boolean isInBattle(PixelmonWrapper pokemon)
      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

      public BattleParticipant getParticipantForEntity(net.minecraft.world.entity.LivingEntity 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.
    • sendDamagePacket

      public void sendDamagePacket(PixelmonWrapper target, int damage)
      Sends a damage packet to the participant clients.
      Parameters:
      target - The Pokémon being damaged.
      damage - The amount of damage dealt.
    • sendHealPacket

      public void sendHealPacket(PixelmonWrapper target, int amount)
      Sends a healing packet to the participant clients.
      Parameters:
      target - The Pokémon being healed.
      amount - The amount of healing.
    • getOppositePokemon

      @Nullable public PixelmonWrapper getOppositePokemon(PixelmonWrapper pw)
      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

      public 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

      public 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.
    • getPositionOfPokemon

      public int getPositionOfPokemon(PixelmonWrapper poke, BattleParticipant bp)
      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

      public BattleStage getStage()
      Returns the current stage of the battle.
      Returns:
      The current stage of the battle.
    • enableReturnHeldItems

      public 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.
    • 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

      public PlayerParticipant getPlayer(String name)
      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

      public PlayerParticipant getPlayer(net.minecraft.world.entity.player.Player player)
      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

      public List<PlayerParticipant> getPlayers()
      Returns a list of player participants in the battle.
      Returns:
      A list of player participants in the battle.
    • getPlayerEntities

      public List<net.minecraft.server.level.ServerPlayer> getPlayerEntities()
      Returns a list of the player entities in the battle
      Returns:
      The players
    • isTeamDefeated

      public boolean isTeamDefeated(BattleParticipant participant)
      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

      public 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.
    • otherParticipant

      public BattleParticipant otherParticipant(BattleParticipant participant)
      Get the other participant in the battle.
      Parameters:
      participant - Your participant Object to get the other participant from.
      Returns:
      BattleParticipant to return.
    • getFirstMover

      public 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

      public 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

      public 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

      public 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.
    • getAbilityIfPresent

      public 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.
    • sendSwitchPacket

      public void sendSwitchPacket(UUID oldUUID, PixelmonWrapper newPokemon)
      Updates all clients with a Pokémon switch.
      Parameters:
      oldUUID - The ID of the Pokémon switching out.
      newPokemon - The Pokémon switching in.
    • addSpectator

      public void addSpectator(Spectator spectator)
      Adds a spectator to the battle.
      Parameters:
      spectator - The spectator to add to the battle.
    • removeSpectator

      public void removeSpectator(Spectator spectator)
      Removes a spectator from the battle.
      Parameters:
      spectator - The spectator to remove from the battle.
    • hasSpectator

      public boolean hasSpectator(net.minecraft.world.entity.player.Player player)
      Checks if the battle has a certain player spectating it.
      Parameters:
      player - The player to look for.
      Returns:
      Whether the specified player is spectating the battle.
    • 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.
    • getPlayerSpectators

      public List<Spectator> getPlayerSpectators(PlayerParticipant player)
      Gets the spectators that are watching a particular player.
      Parameters:
      player - The player to get spectators for.
    • getPokemonFromUUID

      public PixelmonWrapper getPokemonFromUUID(UUID uuid)
      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

      public 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.
    • removeFromTurnList

      public 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.
    • getTurn

      public int getTurn(PixelmonWrapper pixelmonWrapper)
      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

      public boolean containsParticipantType(Class<? extends BattleParticipant> participantType)
    • updateFormChange

      public void updateFormChange(PixelmonEntity pokemon)
      Updates the battle GUI when a Pokémon changes form.
      Parameters:
      pokemon - The Pokémon who changed form.
    • updateFormChange

      public void updateFormChange(PixelmonWrapper pokemon)
      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

      public Attack getLastAttack()
    • getLastTempAttack

      public Attack 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 for
      task - 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 for
      task - 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 for
      task - 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 - read isFrozen() 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 - read isFrozen() for why you might want to freeze a battle
    • addAnimation

      public void addAnimation(AttackAnimation animation)
      Stores an attack animation that is currently running for this battle.
      Parameters:
      animation - The animation to store
    • random

      public BattleRandomSource random()
      Gets this battle's BattleRandomSource, which supplies all random values needed for the battle.
      Returns:
      This battle's BattleRandomSource.
    • setRandom

      public void setRandom(BattleRandomSource random)
      Sets this battle's BattleRandomSource to a provided instance.
      Parameters:
      random - The new BattleRandomSource to use for this battle.
    • forfeitBattleForPlayerAndTheirTeam

      public void forfeitBattleForPlayerAndTheirTeam(BattleEndCause battleEndCause, net.minecraft.world.entity.player.Player player)