Class BattleRules

java.lang.Object
com.pixelmonmod.pixelmon.battles.api.rules.BattleRules
All Implemented Interfaces:
IEncodeable, Cloneable

public class BattleRules extends Object implements IEncodeable, Cloneable
Customizable rules for restricting battles.
  • Field Details

  • Constructor Details

    • BattleRules

      public BattleRules()
      Initializes a set of default rules.
    • BattleRules

      public BattleRules(BattleType battleType)
      Initializes a set of rules with a specified battle type.
      Parameters:
      battleType - The type of battle to use.
    • BattleRules

      public BattleRules(String text)
      Initializes a set of rules from an importable string.
      Parameters:
      text - The string to import battle rules from.
  • Method Details

    • set

      public <T> BattleRules set(BattleProperty<T> property, Object o)
    • get

      public <T> Optional<T> get(BattleProperty<T> property)
    • getOrDefault

      public <T> T getOrDefault(BattleProperty<T> property)
    • clone

      public BattleRules clone()
      Overrides:
      clone in class Object
    • exportText

      public String exportText()
      Exports the rules as human-readable text.
      Returns:
      A text exportable of the rules.
    • importText

      public String importText(String text)
      Imports a set of rules from text.
      Parameters:
      text - The text to import rules from.
      Returns:
      Null if the text was parsed correctly. An error code if there was a parsing error.
    • encodeInto

      public void encodeInto(net.minecraft.network.FriendlyByteBuf buf)
      Exports the rules as a byte array.
      Specified by:
      encodeInto in interface IEncodeable
      Parameters:
      buf - The byte buffer to write to.
    • decodeInto

      public void decodeInto(net.minecraft.network.FriendlyByteBuf buf)
      Imports rules from a byte array.
      Specified by:
      decodeInto in interface IEncodeable
      Parameters:
      buf - The byte buffer to read from.
    • writeToNBT

      public void writeToNBT(net.minecraft.nbt.CompoundTag nbt)
      Writes rule data to NBT.
      Parameters:
      nbt - The NBT tag to write to.
    • readFromNBT

      public void readFromNBT(net.minecraft.nbt.CompoundTag nbt)
      Reads rules from NBT data.
      Parameters:
      nbt - The NBT data to read from.
    • getClauseList

      public List<BattleClause> getClauseList()
      Gets a sorted list of clauses.
      Returns:
      A sorted list of clauses.
    • getClauseIDs

      public List<String> getClauseIDs()
      Gets a sorted list of clauses by their IDs.
      Returns:
      A sorted list of clauses by their IDs.
    • hasClause

      public boolean hasClause(BattleClause clause)
      Check if the rules have the given clause as a setting
      Parameters:
      clause - The clause being checked
      Returns:
      True if it has this clause applied
    • hasClause

      public boolean hasClause(String id)
      Check if the rules have a clause with a certain ID.
      Parameters:
      id - The clause ID to look for.
      Returns:
      Whether the rules have a clause with the specified ID.
    • setNewClauses

      public void setNewClauses(List<BattleClause> newClauses)
      Adds a new set of clauses to the rules. Replaces the current set of clauses.
      Parameters:
      newClauses - The new clauses to add.
    • isDefault

      public boolean isDefault()
      Checks if the rules are the default set of battle rules.
      Returns:
      Whether the rules are the default set of battle rules.
    • validateSingle

      public String validateSingle(Pokemon pokemon)
      Checks if the rules allow a Pokémon to be chosen for battle.
      Parameters:
      pokemon - The Pokémon to check.
      Returns:
      Whether the rules allow the given Pokémon to be chosen for battle.
    • validateTeam

      public String validateTeam(List<Pokemon> team)
      Checks if the rules allow a list of Pokémon to be chosen for battle.
      Parameters:
      team - The Pokémon to check.
      Returns:
      Whether the rules allow the given Pokémon to be chosen for battle.