java.lang.Object
com.pixelmonmod.pixelmon.battles.controller.participants.BattleParticipant
All Implemented Interfaces:
BattleViewer
Direct Known Subclasses:
EntityParticipant, PlayerParticipant, RaidPixelmonParticipant, TestParticipant, TrainerParticipant, WildPixelmonParticipant

public abstract class BattleParticipant extends Object implements BattleViewer
A participant in a battle.
  • Field Details

    • entity

      protected final net.minecraft.world.entity.Entity entity
    • bc

      public BattleController bc
      The battle the participant is in.
    • team

      public int team
      The side of the battle that the participant is on.
    • wait

      protected boolean wait
    • controlledPokemon

      public final List<PixelmonWrapper> controlledPokemon
      The active Pokémon of the participant.
    • allPokemon

      public PixelmonWrapper[] allPokemon
      All Pokémon in the participant's party during battle.
    • isDefeated

      public boolean isDefeated
      Whether the participant has been defeated in battle.
    • lastMoveTime

      protected long lastMoveTime
      The time when the participant last made a move.
    • numControlledPokemon

      public int numControlledPokemon
      The number of Pokémon the participant is controlling in battle at once.
    • lastFaintedTurn

      protected int lastFaintedTurn
      The last turn the participant's Pokémon fainted in.
    • totalFainted

      protected int totalFainted
      How many of the participant's Pokémon have fainted total in the battle.
    • lastFailedCapture

      public PokeBall lastFailedCapture
      The last pokeball type that failed to catpure a pokemon, Used by the Ball Fetch ability
    • switchingIn

      public List<UUID> switchingIn
      Keeps track of Pokémon switching.
    • switchingOut

      public List<PixelmonWrapper> switchingOut
      The Pokémon that are switching out after fainting.
    • evolution

      public UUID evolution
      Whether the participant can currently Mega Evolve a Pokémon.
    • ultraBurst

      public UUID ultraBurst
    • ashNinja

      public UUID ashNinja
    • dynamax

      public UUID dynamax
    • usedZ

      public boolean usedZ
  • Constructor Details

    • BattleParticipant

      protected BattleParticipant(net.minecraft.world.entity.Entity entity, int numControlledPokemon, PixelmonWrapper... pokemon)
    • BattleParticipant

      protected BattleParticipant(net.minecraft.world.entity.Entity entity, int numControlledPokemon, Pokemon... pokemon)
    • BattleParticipant

      protected BattleParticipant(net.minecraft.world.entity.Entity entity, int numControlledPokemon, PixelmonEntity... entities)
  • Method Details

    • convertPokemonToWrapper

      protected static PixelmonWrapper[] convertPokemonToWrapper(Pokemon... pokemon)
    • convertEntitiesToWrapper

      protected static PixelmonWrapper[] convertEntitiesToWrapper(PixelmonEntity... entities)
    • resetMoveTimer

      public void resetMoveTimer()
      Resets the timer for the participant making a move.
    • getTurnTimeSeconds

      public long getTurnTimeSeconds()
      Gets the time since the participant last made a move.
      Returns:
      The time since the participant last made a move.
    • waiting

      public boolean waiting()
    • setWait

      public void setWait(boolean wait)
    • clearMovement

      protected void clearMovement(PixelmonWrapper pw)
    • getUniqueId

      public UUID getUniqueId()
      Gets the UUID of the participant.
      Returns:
      The UUID of the participant.
    • isWild

      public boolean isWild()
      If the participant is a wild Pokémon.
      Returns:
      Whether the participant is a wild Pokémon.
    • isPlayer

      public boolean isPlayer()
      If the participant is a player.
      Returns:
      Whether the participant is a player.
    • isTrainer

      public boolean isTrainer()
      If the participant is a trainer.
      Returns:
      Whether the participant is a trainer.
    • isRaid

      public boolean isRaid()
      If the participant is a raid.
      Returns:
      Whether the participant is a raid.
    • hasMorePokemon

      public boolean hasMorePokemon()
      Checks if the participant has Pokémon that can battle
      Returns:
      True if the player has a Pokémon that can battle.
    • hasMorePokemonReserve

      public boolean hasMorePokemonReserve()
      For use with switching in new Pokémon. Checks if they have Pokémon in reserve.
      Returns:
      True if the player has a Pokémon in reserve.
    • isOnField

      protected boolean isOnField(PixelmonWrapper pw)
    • startBattle

      public void startBattle()
    • preBattleChecks

      public void preBattleChecks()
      Adds the participant to a battle.
    • releasePokemon

      protected void releasePokemon(PixelmonWrapper pixelmonWrapper)
      Attempts to spawn the entity for the provided wrapper.
      Parameters:
      pixelmonWrapper - The wrapper to spawn the entity for.
    • getLevelCap

      protected int getLevelCap()
      Gets the level cap for the participant.
      This may be different for boss related entities.
      Returns:
      The level cap for the participant.
    • getTeamPokemonUUIDs

      public List<UUID> getTeamPokemonUUIDs()
      Finds all Pokémon in the battle allied with the player.
      Returns:
      An array of Pokémon allied with the player.
    • endBattle

      public abstract void endBattle(BattleEndCause cause)
      Ends the battle the participant is in.
    • getName

      public net.minecraft.network.chat.Component getName()
      Gets the name of the participant.
      Returns:
      The name of the participant.
    • getMove

      public MoveChoice getMove(PixelmonWrapper pixelmonWrapper)
      Gets the move to be used by the specified Pokémon.
      Parameters:
      pixelmonWrapper - The Pokémon to get a move for.
      Returns:
      The move to be used by the specified Pokémon.
    • switchPokemon

      public PixelmonWrapper switchPokemon(PixelmonWrapper pw, UUID newPixelmonUUID)
      Switches the participant's Pokémon for another one.
      Parameters:
      pw - The Pokémon to switch out.
      newPixelmonUUID - The UUID of the Pokémon's to switch in.
      Returns:
      The Pokémon who switched in.
    • sendBattleMessage

      public void sendBattleMessage(String message, Object... args)
      Sends a battle message to this participant.
      Specified by:
      sendBattleMessage in interface BattleViewer
      Parameters:
      message - The message to send.
      args - The arguments to format the message with.
    • sendBattleMessage

      public void sendBattleMessage(net.minecraft.network.chat.Component component)
      Sends a battle message to this participant.
      Specified by:
      sendBattleMessage in interface BattleViewer
      Parameters:
      component - The message to send.
    • checkAndHandleBossTier

      public void checkAndHandleBossTier(PixelmonWrapper wrapper)
      Checks if the participant is a boss and then applies the boss tier logic to the provided wrapper.
      Parameters:
      wrapper - The wrapper to apply the boss tier logic to.
    • getHighestLevel

      public int getHighestLevel()
      Gets the highest level of the participant's Pokémon.
      Returns:
      The highest level
    • checkPokemon

      public boolean checkPokemon()
      Checks if the participant's Pokémon are in a valid state.
      Returns:
      Whether the participant's Pokémon are in a valid state.
    • getEntity

      @Nullable public net.minecraft.world.entity.Entity getEntity()
      Gets the entity that this participant is representing.
      Specified by:
      getEntity in interface BattleViewer
      Returns:
      The entity that this participant is representing.
    • updateBattlingPokemon

      public void updateBattlingPokemon()
      Updates the opponent's Pokémon client-side.
    • getNextPokemon

      public void getNextPokemon(int position)
      Sends out the next unfainted Pokémon in the participant's party.
      Parameters:
      position - The position to send out the Pokémon at.
    • countAblePokemon

      public int countAblePokemon()
      Calculated number of unfainted Pokémon in the entire team.
      Returns:
      The number of unfainted Pokémon, sent out or not.
    • countHealthPercent

      public float countHealthPercent()
      Counts the percentage of health remaining in the participant's party.
      Returns:
      The percentage of health remaining in the participant's party.
    • getAllyData

      public List<PixelmonWrapper> getAllyData()
      Gets data about the player's allied Pokémon.
      Returns:
      Data about the player's allied Pokémon.
    • tick

      public void tick()
      Updates the participant every tick.
    • clearTurnVariables

      public void clearTurnVariables()
      Resets turn-specific variables for the participant's Pokémon.
    • selectAction

      public void selectAction()
      Chooses an action for the participant's Pokémon.
    • getWait

      public boolean getWait()
      Checks if the participant is waiting in battle.
      Returns:
      Whether the participant is waiting in battle.
    • getFaintedPokemon

      public PixelmonWrapper getFaintedPokemon()
      Gets the first fainted Pokémon in the participant's party.
      Returns:
      The first fainted Pokémon in the participant's party.
    • hasRemainingPokemon

      public boolean hasRemainingPokemon()
      Checks if the participant has unfainted Pokémon remaining.
      Returns:
      Whether the participant has unfainted Pokémon remaining.
    • faintedLastTurn

      public boolean faintedLastTurn()
      Returns whether one of the participant's pokemon fainted last turn.
      Returns:
      Whether one of the participant's pokemon fainted in the previous turn.
    • updateLastFaintedTurn

      public void updateLastFaintedTurn()
    • getTotalFainted

      public int getTotalFainted()
      Returns the number of Pokémon that have fainted for this participant this battle.
      Returns:
      Number of total fainted, including revived pokemon.
    • incrementFaintCount

      public void incrementFaintCount()
      Increments the number of fainted pokemon. To be called when a Pokémon faints.
    • sendDamagePacket

      public void sendDamagePacket(PixelmonWrapper target, int damage)
      Updates the client when a Pokémon takes damage.
      Specified by:
      sendDamagePacket in interface BattleViewer
      Parameters:
      target - The Pokémon who took damage.
      damage - The amount of damage dealt.
    • sendHealPacket

      public void sendHealPacket(PixelmonWrapper target, int amount)
      Updates the client when a Pokémon heals.
      Specified by:
      sendHealPacket in interface BattleViewer
      Parameters:
      target - The Pokémon who healed.
      amount - The amount of hp healed.
    • getDisplayName

      public net.minecraft.network.chat.MutableComponent getDisplayName()
      Returns the name of the entity the participant is representing.
      Returns:
      The name of the entity the participant is representing.
    • canSwitch

      public static boolean[] canSwitch(PixelmonWrapper p)
      Checks if Pokémon can switch or flee.
      Parameters:
      p - The Pokémon to check.
      Returns:
      A boolean array containing whether the Pokémon can switch and whether it can flee.
    • getStorage

      public PartyStorage getStorage()
      Returns the Pokémon storage of the participant.
      Returns:
      The Pokémon storage of the participant.
    • getOpponents

      public List<BattleParticipant> getOpponents()
      Finds the participants on the opposing side of the battle.
      Returns:
      The participant's opponents.
    • getAllies

      public List<BattleParticipant> getAllies()
      Finds the participants on the allied side of the battle.
      Returns:
      The participant's allies.
    • getOpponentPokemon

      public List<PixelmonWrapper> getOpponentPokemon()
      Returns all Pokemon on the opposite side of the battle that the participant is on.
      Returns:
      A list of all Pokemon on the opposite of the battle that the participant is on.
    • getTeamPokemon

      public List<PixelmonWrapper> getTeamPokemon()
      Returns all Pokemon on the side of the battle that the participant is on.
      Returns:
      A list of all Pokemon on the side of the battle that the participant is on.
    • getActiveUnfaintedPokemon

      public List<PixelmonWrapper> getActiveUnfaintedPokemon()
      Returns all active, unfainted Pokémon that the participant is controlling.
      Returns:
      A list of all active, unfainted Pokémon that the participant is controlling.
    • getPokemonFromUUID

      public PixelmonWrapper getPokemonFromUUID(UUID uuid)
      Gets a controlled Pokémon 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 has the UUID.
    • getPartyPokemonFromUUID

      public PixelmonWrapper getPartyPokemonFromUUID(UUID uuid)
      Gets a Pokémon 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 has the UUID.
    • getPartyPosition

      public int getPartyPosition(PixelmonWrapper pokemon)
      Gets the base position of the Pokémon in the participant's party.
      Parameters:
      pokemon - The Pokémon to get the position of.
      Returns:
      The base position of the Pokémon in the participant's party.
    • loadParty

      protected void loadParty(PartyStorage party)
      Loads all Pokémon in the participant's party.
      Parameters:
      party - The storage to load Pokémon from.
    • loadParty

      protected void loadParty(List<Pokemon> party)
      Loads all Pokémon in the participant's party.
      Parameters:
      party - The Pokémon to use for the participant's party.
    • loadSingle

      protected void loadSingle(Pokemon pokemon)
      Loads just one Pokémon in the participant's party.
      Parameters:
      pokemon - The Pokémon to use for the participant's party.
    • getPokemonFromParty

      public PixelmonWrapper getPokemonFromParty(UUID uuid)
      Gets the Pokémon from the participant's party who matches the given Pokémon UUID.
      Parameters:
      uuid - The UUID to get a Pokémon with.
      Returns:
      The Pokémon from the participant's party who matches the given Pokémon UUID.
    • getWorld

      public net.minecraft.world.level.Level getWorld()
      Gets the world that the participant is in.
      Returns:
      The world that the participant is in.
    • addSwitchingOut

      public boolean addSwitchingOut(PixelmonWrapper pw)
      Adds a Pokémon to the list of Pokémon switching out.
      Parameters:
      pw - The Pokémon to add to the list.
      Returns:
      Whether the participant has Pokémon in reserve to switch out with.
    • switchAllFainted

      public void switchAllFainted()
      Switches out all fainted Pokémon for their replacements.
    • getRandomPartyPokemon

      public PixelmonWrapper getRandomPartyPokemon()
      Gets a random Pokémon from the participant's party that isn't already sent out.
      Returns:
      A random Pokémon from the participant's party that isn't already sent out, or null if there aren't any.
    • canMegaEvolve

      public boolean canMegaEvolve()
      Checks if the participant is allowed to Mega Evolve Pokémon.
      Returns:
      Whether the participant is allowed to Mega Evolve Pokémon.
    • canDynamax

      public boolean canDynamax()
      Checks if the participant is allowed to Dynamax Pokémon.
      Returns:
      Whether the participant is allowed to Dynamax Pokémon.
    • getBattleAI

      public BattleAIBase getBattleAI()
    • setBattleAI

      public void setBattleAI(BattleAIBase ai)
    • revivePokemon

      public void revivePokemon(float healthPercentage)
    • revivePokemon

      protected void revivePokemon(PixelmonWrapper pokemon, float healthPercentage)
    • countFaintedPokemon

      public int countFaintedPokemon()
      Counts the number of fainted Pokémon in the participant's party.
      Returns:
      The number of fainted Pokémon in the participant's party.
    • countPartyPokemon

      public int countPartyPokemon(Predicate<PixelmonWrapper> predicate)
      Counts the number of Pokémon in the participant's party that match the provided predicate.
      Parameters:
      predicate - The predicate to match Pokémon against.
      Returns:
      The number of Pokémon in the participant's party that match the provided predicate.
    • sendPacket

      public void sendPacket(PixelmonPacket message)
      Sends a packet to this participant, wont do anything if its not a player.
      Specified by:
      sendPacket in interface BattleViewer
      Parameters:
      message - The packet to send to this player
    • onEndTurn

      public void onEndTurn(BattleController bc)
    • onTakeTurn

      public boolean onTakeTurn(BattleController bc, PixelmonWrapper pw)
    • onUseAttack

      public boolean onUseAttack(BattleController bc, PixelmonWrapper pw)
    • onUseAttackPost

      public void onUseAttackPost(BattleController bc, PixelmonWrapper pw)
    • onAddStatus

      public boolean onAddStatus(BattleController bc, PixelmonWrapper user, PixelmonWrapper target, StatusBase status)
    • onHit

      public float onHit(PixelmonWrapper source, float damage, DamageTypeEnum damageType)
    • onOpponentKO

      public void onOpponentKO(BattleController bc, PixelmonWrapper pw)
    • onTargeted

      public boolean onTargeted(PixelmonWrapper user, Attack attack)
    • onUseAttackOther

      public boolean onUseAttackOther(BattleController bc, Attack attack, BattleParticipant bp, PixelmonWrapper user)
    • onSwitchIn

      public void onSwitchIn(BattleController bc, PixelmonWrapper pw)
    • retrieveEntityDuringBattleUnlessRiding

      public void retrieveEntityDuringBattleUnlessRiding(PixelmonWrapper pw)
      If a player/trainer is riding their Pokémon and gets in a battle while riding it, they shouldn't be knocked off their Pokémon.
      Parameters:
      pw - The Pokémon that is currently in battle that the player may or may not be riding upon.