Class PokemonStorage

java.lang.Object
com.pixelmonmod.pixelmon.api.storage.PokemonStorage
All Implemented Interfaces:
Iterable<Pokemon>
Direct Known Subclasses:
PartyStorage, PCBox, PCStorage

public abstract class PokemonStorage extends Object implements Iterable<Pokemon>
  • Field Details

    • uuid

      protected final UUID uuid
    • storageType

      protected final net.minecraft.resources.ResourceLocation storageType
    • shouldSendUpdates

      protected transient boolean shouldSendUpdates
    • hasChanged

      protected transient boolean hasChanged
    • trackingPlayers

      protected transient Set<UUID> trackingPlayers
  • Constructor Details

    • PokemonStorage

      protected PokemonStorage(net.minecraft.resources.ResourceLocation storageType, UUID uuid)
  • Method Details

    • getOwner

      @Nullable public @Nullable net.minecraft.server.level.ServerPlayer getOwner()
      Gets the owner of the Pokemon storage
      Returns:
      the owner of the Pokemon storage
    • getUniqueId

      public UUID getUniqueId()
      Gets the unique identifier of the Pokemon storage
      Note that this will likely be the owning player's UUID in the case of a player storage, such as the PlayerPartyStorage or PCStorage
      Returns:
      the unique identifier of the Pokemon storage
    • getStorageType

      public net.minecraft.resources.ResourceLocation getStorageType()
      Gets the type of storage this represents from the PixelmonRegistry.getStorageType() registry
      Returns:
      The key of the storage type
    • getAll

      public abstract Pokemon[] getAll()
      Gets a array of all pokemon within this storage. May not be the implementations array (e.g it could be copy). So don't expect to be able to edit this. the size of the array should always match the maximum capacity and will obviously contain null elements for slots that are not full.
      Returns:
      An array of all pokemon within this storage. By convention this is not the implementation's array (thus this is a copy). This is preferred because it forces modifications to go through the relevant methods which fire events and flip hasChanged.
    • shouldSendUpdates

      public void shouldSendUpdates(boolean shouldSendUpdates)
      Sets if the storage should send updates to the tracking entities when changes are made to it's contents
      Parameters:
      shouldSendUpdates - if the storage should send updates
    • shouldSendUpdates

      public boolean shouldSendUpdates()
      Gets if the storage should send updates to the tracking entities
      Returns:
      if the storage should send updates
    • track

      public void track(net.minecraft.server.level.ServerPlayer player)
      Adds a player to the list of players to update when changes are made to the storage
      Parameters:
      player - the player to track
    • untrack

      public void untrack(net.minecraft.server.level.ServerPlayer player)
      Removes a player from the list of players to update when changes are made to the storage
      Parameters:
      player - the player to untrack
    • isTracking

      public boolean isTracking(net.minecraft.server.level.ServerPlayer player)
      Checks if the given player is tracking the storage
      Parameters:
      player - the player to check
      Returns:
      if the player is tracking the storage
    • trackingPlayers

      public List<net.minecraft.server.level.ServerPlayer> trackingPlayers()
      Gets the list of players that are tracking the storage
      Returns:
      the list of players that are tracking the storage
    • encode

      public abstract void encode(net.minecraft.network.FriendlyByteBuf buffer)
      Writes the storage to the given buffer
      Parameters:
      buffer - the buffer to write to
    • decode

      public abstract void decode(net.minecraft.network.FriendlyByteBuf buf)
      Reads the storage from the given buffer
      Parameters:
      buf - the buffer to read from
    • initialize

      public void initialize(net.minecraft.server.level.ServerPlayer player)
      Sends the contents of the storage to the given player
      Parameters:
      player - the player to send the contents to
    • open

      public void open(net.minecraft.server.level.ServerPlayer player)
      Opens the storage for the given player
      Parameters:
      player - the player to open the storage for
    • getAllPositions

      public abstract StoragePosition[] getAllPositions()
      Same as getAll(), but for StoragePositions. Note that this will return every position, regardless of whether or not it contains a Pokemon, for flexibility.
    • maxSize

      public abstract int maxSize()
      Returns:
      The maximum capacity of the Storage (or the individual containers, in cases like PCStorage)
    • getFirstEmptyPosition

      @Nullable public abstract StoragePosition getFirstEmptyPosition()
      Gets the first position where there is no pokemon in the storage
      Returns:
      the first empty position in the storage
    • set

      public abstract void set(StoragePosition position, Pokemon pokemon)
      Sets the given pokemon at the given position in the storage
      Parameters:
      position - the position to set the pokemon
      pokemon - the pokemon to set
    • get

      @Nullable public abstract Pokemon get(StoragePosition position)
      Gets the pokemon at the given position in the storage
      Will return null if there is no pokemon at the given position
      Parameters:
      position - the position to get the pokemon from
      Returns:
      the pokemon at the given position
    • swap

      public abstract void swap(StoragePosition position1, StoragePosition position2)
      Swaps the pokemon at the given positions in the storage
      Parameters:
      position1 - the first position to swap
      position2 - the second position to swap
    • writeToNBT

      public abstract net.minecraft.nbt.CompoundTag writeToNBT(net.minecraft.nbt.CompoundTag nbt)
      Writes the storage to the given NBT tag
      Parameters:
      nbt - the NBT tag to write to
      Returns:
      the NBT tag with the storage written to it
    • readFromNBT

      public abstract CompletableFuture<? extends PokemonStorage> readFromNBT(net.minecraft.nbt.CompoundTag nbt)
      Reads the storage from the given NBT tag
      Parameters:
      nbt - the NBT tag to read from
      Returns:
      a future that completes when the storage has been read from the NBT tag
    • getPosition

      @Nullable public abstract StoragePosition getPosition(Pokemon pokemon)
      Gets the position of the given pokemon in the storage
      Will return null if the pokemon is not in the storage
      Parameters:
      pokemon - the pokemon to get the position of
      Returns:
      the position of the given pokemon in the storage
    • clone

      @Nullable public StoragePosition clone(StoragePosition position)
      Clone the Pokemon stored in a position and add it to the storage.
      Parameters:
      position - The StoragePosition to clone
      Returns:
      The StoragePosition of the cloned Pokemon. Null if cloning was not completed.
    • add

      public boolean add(Pokemon pokemon)
      Adds the given Pokemon to this storage in the first available position. If the storage is full, then in the case that it is a PlayerPartyStorage then it will attempt to add to the PC and pass back the return value from there.
      Parameters:
      pokemon - The Pokemon to add to the storage.
      Returns:
      true if it was able to add to this storage, or in the case of this being a full PlayerPartyStorage, true if there was an empty space in the PC. Otherwise false.
    • addAndGetPosition

      @Nullable public StoragePosition addAndGetPosition(Pokemon pokemon)
      Adds a Pokemon to the storage and returns the StoragePosition that it was added to. Similarly to add(Pokemon), if the storage is full, then in the case that it is a PlayerPartyStorage then it will attempt to add to the PC and pass back the return value from there.
      Parameters:
      pokemon - The Pokemon to add to the storage.
      Returns:
      The position that the Pokemon was added to. Null if the Pokemon could not be added.
    • transfer

      public boolean transfer(PokemonStorage from, StoragePosition fromPosition, StoragePosition toPosition)
      Returns:
      Whether the action has been completed or not.
    • hasSpace

      public boolean hasSpace()
      Returns:
      true if this storage has at least one free slot.
    • clear

      public abstract void clear()
      Clears all the pokemon from the storage
    • canTransfer

      public boolean canTransfer(StoragePosition from, StoragePosition to)
    • countPokemon

      public int countPokemon()
      Returns:
      The number of Pokémon this storage holds. Excluding eggs.
    • countEggs

      public int countEggs()
      Returns:
      The number of eggs this storage holds.
    • countEmpty

      public int countEmpty()
      Returns:
      The number of free slots in this storage.
    • countAll

      public int countAll()
      Returns:
      The number of Pokémon and eggs this storage holds. 0 if empty.
    • findOne

      public Pokemon findOne(Predicate<Pokemon> condition)
    • findOne

      public Pokemon findOne(PokemonSpecification spec)
    • findAll

      public List<Pokemon> findAll(Predicate<Pokemon> condition)
    • findAll

      public List<Pokemon> findAll(PokemonSpecification spec)
    • findAllPositions

      public List<StoragePosition> findAllPositions(Predicate<Pokemon> condition)
    • findAllPositions

      public List<StoragePosition> findAllPositions(PokemonSpecification spec)
    • find

      public Pokemon find(UUID uuid)
      Finds the pokemon with the given UUID
      Parameters:
      uuid - the UUID to find
      Returns:
      the pokemon with the given UUID
    • validate

      public boolean validate(StoragePosition position, UUID pokemonUUID)
      Validates that the pokemon at the given position has the given UUID
      If the pokemon at the given position is null and the given UUID is null, this will return true
      Parameters:
      position - the position to validate
      pokemonUUID - the UUID to validate
      Returns:
      if the pokemon at the given position has the given UUID
    • notifyListeners

      public void notifyListeners(StoragePosition position, Pokemon pokemon, EnumUpdateType... dataTypes)
      Notifies all the tracking players of a change in the storage
      Parameters:
      position - the position of the change
      pokemon - the pokemon that was changed
      dataTypes - the types of data that was changed
    • retrieveAll

      public void retrieveAll(String pokemonRetrievedEventReason)
      Gets all the pokemon in the storage and removes them from the world so that any operations made on the storage can be done safely
      Parameters:
      pokemonRetrievedEventReason - the reason for retrieving the pokemon
    • getShouldSave

      public boolean getShouldSave()
    • setHasChanged

      public void setHasChanged(boolean hasChanged)
    • setNeedsSaving

      public void setNeedsSaving()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCurryData

      public int[] getCurryData()
    • updateSingleCurryData

      public void updateSingleCurryData(EnumCurryKey curryKey, EnumBerryFlavor cookingFlavor, EnumCurryRating rating)