Class MultiLaneBattleController

java.lang.Object
com.pixelmonmod.pixelmon.battles.controller.MultiLaneBattleController
All Implemented Interfaces:
RegistryBacked, BattleController, BattleEvents, BattleMessaging, BattleRandomContext, BattleSimulationContext, BattleSpectating, BattleStateView, ContextHolder, LegacyBattleAISupport

public class MultiLaneBattleController extends Object implements BattleController
  • Constructor Details

  • Method Details

    • spinLane

      public BattleController spinLane(BattleParticipant opposition)
    • spinLaneWithoutRegistering

      public BattleController spinLaneWithoutRegistering(BattleParticipant opposition)
    • lanes

      public List<BattleController> lanes()
    • mainParticipant

      public BattleParticipant mainParticipant()
    • raidBossState

    • addTaskAtBattleEnd

      public void addTaskAtBattleEnd(BiConsumer<BattleEndCause,MultiLaneBattleController> task)
    • onLaneParticipantEnded

      public void onLaneParticipantEnded(BattleParticipant participant, BattleEndCause cause)
    • removePlayer

      public void removePlayer(net.minecraft.server.level.ServerPlayer player, BattleEndCause cause)
      Description copied from interface: BattleController
      Handles a player leaving the server while in this battle, such as by logging out or dying. By default this ends the battle.
      Specified by:
      removePlayer in interface BattleController
    • battleTicks

      public int battleTicks()
      Description copied from interface: BattleStateView
      Returns the number of times the current battle has been ticked.
      This may be incremented multiple times per-server tick depending on the controller's battle tick rate. So this is not necessarily equal to 20 times a second.
      To get the number of battle ticks per second, use BattleStateView.battleTicksPerSecond().
      Specified by:
      battleTicks in interface BattleStateView
      Returns:
      the current battle tick
    • waitTicks

      public int waitTicks()
      Description copied from interface: BattleSimulationContext
      Returns the number of battle ticks this battle must wait before normal turn progression can continue.
      Specified by:
      waitTicks in interface BattleSimulationContext
      Returns:
      remaining wait ticks
    • waitTicks

      public void waitTicks(int waitTicks)
      Description copied from interface: BattleSimulationContext
      Sets the number of battle ticks this battle must wait before normal turn progression can continue.
      Specified by:
      waitTicks in interface BattleSimulationContext
      Parameters:
      waitTicks - remaining wait ticks
    • update

      public void update()
      Description copied from interface: BattleController
      Updates the battle every tick.
      Specified by:
      update in interface BattleController
    • doTurnLogic

      public void doTurnLogic()
      Specified by:
      doTurnLogic in interface BattleController
    • endTurn

      public void endTurn()
      Description copied from interface: BattleController
      Handles end-of-turn effects.
      Specified by:
      endTurn in interface BattleController
    • sync

      public <T> void sync(ContextKey<T> key)
      Description copied from interface: BattleController
      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 the ContextKeys.TURN_TIME which is required by the clients to display the turn timer.
      Specified by:
      sync in interface BattleController
      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.
    • modifyStatsCancellable

      public void modifyStatsCancellable(PixelmonWrapper attacker)
      Description copied from interface: BattleController
      Modifies Pokémon stats during a turn after deciding which Pokémon gets to make a move.
      Specified by:
      modifyStatsCancellable in interface BattleController
      Parameters:
      attacker - The Pokémon using a move.
    • getLastAttack

      public Attack getLastAttack()
      Specified by:
      getLastAttack in interface BattleController
    • getLastTempAttack

      public Attack getLastTempAttack()
      Specified by:
      getLastTempAttack in interface BattleController
    • addBattleAnimation

      public void addBattleAnimation(ActiveBattleAnimation animation)
      Description copied from interface: BattleController
      Stores a battle animation that is currently running for this battle.
      Specified by:
      addBattleAnimation in interface BattleController
      Parameters:
      animation - The animation to store
    • battleAnimationLaneFor

      public BattleController battleAnimationLaneFor(PixelmonWrapper user, PixelmonWrapper target)
    • isBattleAnimationChannelBusy

      public boolean isBattleAnimationChannelBusy(String channel)
      Specified by:
      isBattleAnimationChannelBusy in interface BattleController
    • cleanUpBattleAnimationChannel

      public void cleanUpBattleAnimationChannel(String channel)
      Specified by:
      cleanUpBattleAnimationChannel in interface BattleController
    • acknowledgeBattleAnimation

      public void acknowledgeBattleAnimation(net.minecraft.server.level.ServerPlayer player, UUID acknowledgementId)
      Description copied from interface: BattleController
      Acknowledges completion of a client-side battle animation wait.
      Specified by:
      acknowledgeBattleAnimation in interface BattleController
      Parameters:
      player - the client that acknowledged the animation
      acknowledgementId - the acknowledgement token sent to the client
    • endBattle

      Description copied from interface: BattleController
      Ends the battle with the given cause and any precalculated results. This method is called by ALL other end of battle methods.
      Specified by:
      endBattle in interface BattleController
    • switchPokemon

      public void switchPokemon(UUID switchingPokemonUUID, UUID newPokemonUUID, boolean switchInstantly)
      Description copied from interface: BattleController
      Switches a Pokémon out for a different one.
      Specified by:
      switchPokemon in interface BattleController
      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

      public boolean hasSwitchedDuringThisMove()
      Description copied from interface: BattleController
      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.
      Specified by:
      hasSwitchedDuringThisMove in interface BattleController
      Returns:
      If a Pokémon has switched due to a move during this move.
    • hasSwitchedDuringThisMove

      public void hasSwitchedDuringThisMove(boolean hasSwitchedDuringThisMove)
      Description copied from interface: BattleController
      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.
      Specified by:
      hasSwitchedDuringThisMove in interface BattleController
      Parameters:
      hasSwitchedDuringThisMove - If a Pokémon has switched due to a move during this move.
    • turnList

      public List<PixelmonWrapper> turnList()
      Description copied from interface: BattleController
      This method returns the order of Pokémon moving during a battle turn.
      Specified by:
      turnList in interface BattleController
      Returns:
      The order of Pokémon moving during a battle turn.
    • turnList

      public void turnList(List<PixelmonWrapper> turnList)
      Description copied from interface: BattleController
      This method sets the order of Pokémon moving during a battle turn.
      Specified by:
      turnList in interface BattleController
      Parameters:
      turnList - The order of Pokémon moving during a battle turn.
    • setFlee

      public void setFlee(UUID fleeingUUID)
      Description copied from interface: BattleController
      Sets a Pokémon to flee in the turn.
      Specified by:
      setFlee in interface BattleController
      Parameters:
      fleeingUUID - The fleeing Pokémon.
    • duringSwitchAction

      public boolean duringSwitchAction()
      Description copied from interface: BattleController
      Checks whether the battle controller is performing hard swaps causing aligned switch-in effects
      Specified by:
      duringSwitchAction in interface BattleController
      Returns:
      whether the controller is occupied with hard switches
    • pauseBattle

      public void pauseBattle()
      Description copied from interface: BattleController
      Pauses the battle.
      Specified by:
      pauseBattle in interface BattleController
    • endPause

      public void endPause()
      Description copied from interface: BattleController
      Unpauses the battle.
      Specified by:
      endPause in interface BattleController
    • participantCanDynamax

      public boolean participantCanDynamax(BattleParticipant part)
      Description copied from interface: BattleController
      Checks if a participant is capable of dynamaxing and that it is their turn.
      Specified by:
      participantCanDynamax in interface BattleController
    • lastAttack

      public Attack lastAttack()
      Specified by:
      lastAttack in interface BattleController
    • lastAttack

      public void lastAttack(Attack attack)
      Specified by:
      lastAttack in interface BattleController
    • lastTempAttack

      public Attack lastTempAttack()
      Specified by:
      lastTempAttack in interface BattleController
    • lastTempAttack

      public void lastTempAttack(Attack attack)
      Specified by:
      lastTempAttack in interface BattleController
    • lastSimulatedAttack

      public Attack lastSimulatedAttack()
      Specified by:
      lastSimulatedAttack in interface BattleController
    • lastSimulatedAttack

      public void lastSimulatedAttack(Attack attack)
      Specified by:
      lastSimulatedAttack in interface BattleController
    • lastSimulatedTempAttack

      public Attack lastSimulatedTempAttack()
      Specified by:
      lastSimulatedTempAttack in interface BattleController
    • lastSimulatedTempAttack

      public void lastSimulatedTempAttack(Attack attack)
      Specified by:
      lastSimulatedTempAttack in interface BattleController
    • getPokemonOrderedByAbilityGain

      public List<PixelmonWrapper> getPokemonOrderedByAbilityGain()
      Specified by:
      getPokemonOrderedByAbilityGain in interface BattleController
    • timedAbilityStarted

      public void timedAbilityStarted(PixelmonWrapper pw)
      Description copied from interface: BattleController
      Moves pokemon to end of list of pokemon gaining their abilities
      Specified by:
      timedAbilityStarted in interface BattleController
    • checkedPokemon

      public Set<Pokemon> checkedPokemon()
      Description copied from interface: BattleController
      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.
      Specified by:
      checkedPokemon in interface BattleController
      Returns:
      A set of Pokémon that need to be evolved at the end of the turn.
    • reviveAfterDefeat

      public void reviveAfterDefeat(BattleParticipant p)
      Description copied from interface: BattleController
      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.
      Specified by:
      reviveAfterDefeat in interface BattleController
      Parameters:
      p - the trainer that needs to send out a now revived Pokémon.
    • checkPokemon

      public void checkPokemon()
      Description copied from interface: BattleController
      Checks the conditions of the active Pokémon.
      Specified by:
      checkPokemon in interface BattleController
    • currentlyActingPokemon

      public PixelmonWrapper currentlyActingPokemon()
      Specified by:
      currentlyActingPokemon in interface BattleController
    • currentlyActingPokemon

      public void currentlyActingPokemon(PixelmonWrapper currentlyActingPokemon)
      Specified by:
      currentlyActingPokemon in interface BattleController
    • storeSwitchInActivation

      public void storeSwitchInActivation(PixelmonWrapper pw, PixelmonWrapper former)
      Specified by:
      storeSwitchInActivation in interface BattleController
    • registryAccess

      public net.minecraft.core.RegistryAccess registryAccess()
      Description copied from interface: RegistryBacked
      Returns the backing registry access used to resolve registries and entries.
      Specified by:
      registryAccess in interface RegistryBacked
      Returns:
      the registry access for this object
    • addFunctionAtEvent

      public <E extends BattleEvent, A> CompletableFuture<A> addFunctionAtEvent(Class<E> eventClass, BiFunction<E,BattleController,A> task)
      Description copied from interface: BattleEvents
      Adds a one-shot function to run the next time the specified event type is published.

      The returned future is completed with the function result after the task has executed. Once executed, the task is removed and will not run for later events of the same type.

      Specified by:
      addFunctionAtEvent in interface BattleEvents
      Type Parameters:
      E - the battle event type
      A - the function result type
      Parameters:
      eventClass - the event type to wait for
      task - the function to execute when the event is published
      Returns:
      a future completed with the function result when the task runs
    • addTaskAtEvent

      public <E extends BattleEvent> CompletableFuture<Void> addTaskAtEvent(Class<E> eventClass, BiConsumer<E,BattleController> task)
      Description copied from interface: BattleEvents
      Adds a one-shot task to run the next time the specified event type is published.

      The returned future is completed after the task has executed. Once executed, the task is removed and will not run for later events of the same type.

      Specified by:
      addTaskAtEvent in interface BattleEvents
      Type Parameters:
      E - the battle event type
      Parameters:
      eventClass - the event type to wait for
      task - the task to execute when the event is published
      Returns:
      a future completed when the task has run
    • addPersistentTaskAtEvent

      public <E extends BattleEvent> void addPersistentTaskAtEvent(Class<E> eventClass, BiConsumer<E,BattleController> task)
      Description copied from interface: BattleEvents
      Adds a persistent task to run every time the specified event type is published.

      Persistent tasks are not removed after execution and do not expose a future, because they may run multiple times over the lifetime of the battle.

      Specified by:
      addPersistentTaskAtEvent in interface BattleEvents
      Type Parameters:
      E - the battle event type
      Parameters:
      eventClass - the event type to listen for
      task - the task to execute each time the event is published
    • publishEvent

      public <T extends BattleEvent> T publishEvent(T event)
      Description copied from interface: BattleEvents
      Publishes a battle event.

      Publishing an event should run any one-shot or persistent tasks waiting for that event type, and should also pass the event through the normal Pixelmon event pipeline where applicable. The returned event may have been modified by listeners.

      Specified by:
      publishEvent in interface BattleEvents
      Type Parameters:
      T - the battle event type
      Parameters:
      event - the event to publish
      Returns:
      the published event, potentially modified by listeners
    • broadcastPacket

      public void broadcastPacket(PixelmonPacket packet)
      Description copied from interface: BattleMessaging
      Broadcasts a battle packet to all relevant battle clients.

      Implementations should avoid sending packets when battle communication is disabled.

      Specified by:
      broadcastPacket in interface BattleMessaging
      Parameters:
      packet - the packet to broadcast
    • publishSwitchPokemonEvent

      public void publishSwitchPokemonEvent(PixelmonWrapper switchedOut, PixelmonWrapper switchedIn)
      Specified by:
      publishSwitchPokemonEvent in interface BattleController
    • publishRevivedPokemonEvent

      public void publishRevivedPokemonEvent(PixelmonWrapper revived)
      Specified by:
      publishRevivedPokemonEvent in interface BattleController
    • getAttackDamageCalculator

      public AttackDamageCalculator getAttackDamageCalculator()
      Description copied from interface: BattleRandomContext
      Returns the attack damage calculator used by this battle.

      The damage calculator controls how the attack damage random multiplier is resolved. Different implementations may use normal random damage rolls, average damage, minimum damage, maximum damage, or another deterministic strategy for simulations and tests.

      Specified by:
      getAttackDamageCalculator in interface BattleRandomContext
      Returns:
      the attack damage calculator
    • setAttackDamageCalculator

      public void setAttackDamageCalculator(AttackDamageCalculator attackDamageCalculator)
      Description copied from interface: BattleRandomContext
      Sets the attack damage calculator used by this battle.
      Specified by:
      setAttackDamageCalculator in interface BattleRandomContext
      Parameters:
      attackDamageCalculator - the attack damage calculator to use
    • randomness

      public BattleRandomness randomness()
      Description copied from interface: BattleRandomContext
      Returns the battle randomness provider used by this battle.

      The randomness provider should be used by battle logic for random battle behaviour so live battles, tests, and simulations can control randomness consistently.

      Specified by:
      randomness in interface BattleRandomContext
      Returns:
      the battle randomness provider
    • setRandomness

      public void setRandomness(BattleRandomness randomness)
      Description copied from interface: BattleRandomContext
      Sets the battle randomness provider used by this battle.
      Specified by:
      setRandomness in interface BattleRandomContext
      Parameters:
      randomness - the battle randomness provider to use
    • copy

      public BattleController copy()
      Description copied from interface: BattleSimulationContext
      Creates a copy of this battle controller.

      The returned battle is intended for systems that need to evaluate or simulate battle outcomes without directly mutating the original battle. The exact copied state depends on the backing BattleController implementation.

      Specified by:
      copy in interface BattleSimulationContext
      Returns:
      a copied battle controller
    • spectators

      public List<Spectator> spectators()
      Description copied from interface: BattleSpectating
      Returns the spectators currently watching this battle.

      The returned list may be backed by the live battle state. Callers should avoid mutating it directly unless they are part of battle-controller internals.

      Specified by:
      spectators in interface BattleSpectating
      Returns:
      the current battle spectators
    • spectate

      public void spectate(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.entity.Entity target)
      Description copied from interface: BattleSpectating
      Adds a player as a spectator of this battle.

      The target entity is used as the entity the player is spectating from or tracking when they begin watching the battle.

      Specified by:
      spectate in interface BattleSpectating
      Parameters:
      player - the player to add as a spectator
      target - the battle-related entity being spectated or tracked
    • isSpectating

      public boolean isSpectating(net.minecraft.world.entity.player.Player player)
      Description copied from interface: BattleSpectating
      Returns whether the specified player is currently spectating this battle.
      Specified by:
      isSpectating in interface BattleSpectating
      Parameters:
      player - the player to check
      Returns:
      true if the player is spectating this battle; false otherwise
    • removeSpectator

      public boolean removeSpectator(net.minecraft.server.level.ServerPlayer player)
      Description copied from interface: BattleSpectating
      Removes a player from this battle's spectators.
      Specified by:
      removeSpectator in interface BattleSpectating
      Parameters:
      player - the spectator to remove
      Returns:
      true if the player was spectating this battle and was removed; false otherwise
    • battleLog

      public BattleLog battleLog()
      Description copied from interface: BattleStateView
      Returns the battle log for this battle.
      Specified by:
      battleLog in interface BattleStateView
      Returns:
      the battle log
    • outcome

      public BattleOutcome outcome()
      Description copied from interface: BattleStateView
      Returns whether this battle has ended.
      Specified by:
      outcome in interface BattleStateView
      Returns:
      true if the battle has ended; false otherwise
    • battleTurn

      public int battleTurn()
      Description copied from interface: BattleStateView
      Returns the current battle turn number.
      Specified by:
      battleTurn in interface BattleStateView
      Returns:
      the current battle turn
    • actionIndex

      public int actionIndex()
      Description copied from interface: BattleStateView
      Returns the current action index within the active turn.

      This is used while resolving turn actions to identify which action or Pokémon is currently being processed.

      Specified by:
      actionIndex in interface BattleStateView
      Returns:
      the current action index
    • battleIndex

      public int battleIndex()
      Description copied from interface: BattleStateView
      Returns this battle's index.
      Specified by:
      battleIndex in interface BattleStateView
      Returns:
      the battle index
    • battleIndex

      public void battleIndex(int battleIndex)
      Description copied from interface: BattleStateView
      Sets this battle's index.
      Specified by:
      battleIndex in interface BattleStateView
      Parameters:
      battleIndex - the battle index
    • getStage

      public BattleStage getStage()
      Description copied from interface: BattleStateView
      Returns the current stage of the battle.
      Specified by:
      getStage in interface BattleStateView
      Returns:
      the current battle stage
    • globalStatusController

      public GlobalStatusController globalStatusController()
      Description copied from interface: BattleStateView
      Returns the controller for global battle statuses.
      Specified by:
      globalStatusController in interface BattleStateView
      Returns:
      the global status controller
    • participants

      public List<BattleParticipant> participants()
      Description copied from interface: BattleStateView
      Returns the participants in this battle.

      The returned list may be backed by the live battle state. Callers should avoid mutating it unless they are part of battle-controller internals.

      Specified by:
      participants in interface BattleStateView
      Returns:
      the battle participants
    • teams

      public List<List<BattleParticipant>> teams()
      Description copied from interface: BattleStateView
      Returns the battle participants grouped by team.

      The returned lists may be backed by the live battle state. Callers should avoid mutating them unless they are part of battle-controller internals.

      Specified by:
      teams in interface BattleStateView
      Returns:
      the battle teams
    • hasInitialized

      public boolean hasInitialized()
    • oldGen

      public Quadstate oldGen()
      Description copied from interface: BattleStateView
      Returns the old-generation rules state for this battle.
      Specified by:
      oldGen in interface BattleStateView
      Returns:
      the old-generation rules state
    • oldGen

      public void oldGen(Quadstate oldGen)
      Description copied from interface: BattleStateView
      Sets the old-generation rules state for this battle.
      Specified by:
      oldGen in interface BattleStateView
      Parameters:
      oldGen - the old-generation rules state
    • simulateMode

      public boolean simulateMode()
      Description copied from interface: LegacyBattleAISupport
      Returns whether this battle is currently running in the legacy AI simulation mode.

      This flag is only used by the legacy BattleAI.ADVANCED, BattleAI.TACTICAL, and BattleAI.AGGRESSIVE implementations. New simulation-aware code should use the battle context instead.

      Specified by:
      simulateMode in interface LegacyBattleAISupport
      Returns:
      true if the battle is being simulated by legacy AI logic; false otherwise
    • simulateMode

      public void simulateMode(boolean simulateMode)
      Description copied from interface: LegacyBattleAISupport
      Sets whether this battle is currently running in the legacy AI simulation mode.
      Specified by:
      simulateMode in interface LegacyBattleAISupport
      Parameters:
      simulateMode - whether the battle should be treated as simulated by legacy AI logic
    • simulateStats

      public boolean simulateStats()
      Description copied from interface: LegacyBattleAISupport
      Returns whether the legacy AI should use simulated stat handling for this battle.

      This is an artifact of the older battle AI system. It is separate from the modern battle context simulation flag and does not represent a general-purpose battle state setting.

      Specified by:
      simulateStats in interface LegacyBattleAISupport
      Returns:
      true if legacy AI stat simulation handling is enabled; false otherwise
    • simulateStats

      public void simulateStats(boolean simulateStats)
      Description copied from interface: LegacyBattleAISupport
      Sets whether the legacy AI should use simulated stat handling for this battle.
      Specified by:
      simulateStats in interface LegacyBattleAISupport
      Parameters:
      simulateStats - whether legacy AI stat simulation handling should be enabled
    • getContext

      public StoredContext getContext()
      Specified by:
      getContext in interface ContextHolder
    • startMainParticipant

      public void startMainParticipant()