Class PokemonStorage
java.lang.Object
com.pixelmonmod.pixelmon.api.storage.PokemonStorage
- Direct Known Subclasses:
PartyStorage,PCBox,PCStorage
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected final net.minecraft.resources.ResourceLocationprotected final UUID -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPokemonStorage(net.minecraft.resources.ResourceLocation storageType, UUID uuid) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the given Pokemon to this storage in the first available position.addAndGetPosition(Pokemon pokemon) Adds a Pokemon to the storage and returns theStoragePositionthat it was added to.booleancanTransfer(StoragePosition from, StoragePosition to) abstract voidclear()Clears all the pokemon from the storageclone(StoragePosition position) Clone the Pokemon stored in a position and add it to the storage.intcountAll()intcountAll(PokemonSpecification spec) Counts the number of pokemon in the storage that match the given specificationintCounts the number of pokemon in the storage that match the given conditionintCounts the number of eggs in this storage.intCounts the number of empty slots in this storage.intCounts the number of Pokémon in this storage.abstract voiddecode(net.minecraft.network.RegistryFriendlyByteBuf buf) Reads the storage from the given bufferabstract voidencode(net.minecraft.network.RegistryFriendlyByteBuf buffer) Writes the storage to the given bufferFinds the pokemon with the given UUIDfindAll(PokemonSpecification spec) Finds all the pokemon in the storage that match the given specificationFinds all the pokemon in the storage that match the given conditionFinds all the positions in the storage that match the given specificationfindAllPositions(Predicate<Pokemon> condition) Finds all the positions in the storage that match the given conditionfindOne(PokemonSpecification spec) Finds the first pokemon in the storage that matches the given specificationFinds the first pokemon in the storage that matches the given conditionabstract Pokemonget(StoragePosition position) Gets the pokemon at the given position in the storage
Will return null if there is no pokemon at the given positionabstract Pokemon[]getAll()Gets an array of all Pokémon within this storage.Pokemon[]Gets an array of all Pokémon within this storage.abstract StoragePosition[]Same asgetAll(), but forStoragePositions.int[]abstract StoragePositionGets the first position where there is no pokemon in the storage@Nullable net.minecraft.server.level.ServerPlayergetOwner()Gets the owner of the Pokemon storageabstract StoragePositiongetPosition(Pokemon pokemon) Gets the position of the given pokemon in the storage
Will return null if the pokemon is not in the storageabstract Pokemon[]Gets a raw array of all pokemon within this storage.booleannet.minecraft.resources.ResourceLocationGets the type of storage this represents from thePixelmonRegistry.getStorageType()registryGets 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 thePlayerPartyStorageorPCStoragebooleanhasSpace()voidinitialize(net.minecraft.server.level.ServerPlayer player) Sends the contents of the storage to the given playerbooleanisTracking(net.minecraft.server.level.ServerPlayer player) Checks if the given player is tracking the storageabstract intmaxSize()voidnotifyListeners(StoragePosition position, Pokemon pokemon, EnumUpdateType... dataTypes) Notifies all the tracking players of a change in the storagevoidopen(net.minecraft.server.level.ServerPlayer player) Opens the storage for the given playerabstract CompletableFuture<? extends PokemonStorage> readFromNBT(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider registryAccess) Reads the storage from the given NBT tagvoidretrieveAll(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 safelyabstract voidset(StoragePosition position, Pokemon pokemon) Sets the given pokemon at the given position in the storagevoidsetHasChanged(boolean hasChanged) voidbooleanGets if the storage should send updates to the tracking entitiesvoidshouldSendUpdates(boolean shouldSendUpdates) Sets if the storage should send updates to the tracking entities when changes are made to it's contentsabstract voidswap(StoragePosition position1, StoragePosition position2) Swaps the pokemon at the given positions in the storagetoString()voidtrack(net.minecraft.server.level.ServerPlayer player) Adds a player to the list of players to update when changes are made to the storageList<net.minecraft.server.level.ServerPlayer> Gets the list of players that are tracking the storagebooleantransfer(PokemonStorage from, StoragePosition fromPosition, StoragePosition toPosition) voiduntrack(net.minecraft.server.level.ServerPlayer player) Removes a player from the list of players to update when changes are made to the storagevoidupdateSingleCurryData(EnumCurryKey curryKey, EnumBerryFlavor cookingFlavor, EnumCurryRating rating) booleanvalidate(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 trueabstract net.minecraft.nbt.CompoundTagwriteToNBT(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider registryAccess) Writes the storage to the given NBT tagMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Field Details
-
uuid
-
storageType
protected final net.minecraft.resources.ResourceLocation storageType -
shouldSendUpdates
protected transient boolean shouldSendUpdates -
hasChanged
protected transient boolean hasChanged -
trackingPlayers
-
-
Constructor Details
-
PokemonStorage
-
-
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
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 thePlayerPartyStorageorPCStorage- Returns:
- the unique identifier of the Pokemon storage
-
getStorageType
public net.minecraft.resources.ResourceLocation getStorageType()Gets the type of storage this represents from thePixelmonRegistry.getStorageType()registry- Returns:
- The key of the storage type
-
getAll
Gets an array of all Pokémon within this storage. This may not be the implementation's backing array (e.g. it could be a copy), so don't expect to be able to edit this. The size of the array should always match the maximum capacity and will contain null elements for slots that are not full.- Returns:
- An array of all Pokémon 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.
-
getAllNonNull
Gets an array of all Pokémon within this storage. This will not be the implementation's backing array, as this will return an array with any nulls removed. As such, this will not necessarily have the size of the maximum capacity.- Returns:
- An array of all Pokémon within this storage, without nulls.
-
getRawAll
Gets a raw array of all pokemon within this storage. This is the implementation's array and should not be modified.
This is useful for when you need to iterate over the array and don't need to modify it.- Returns:
- An array of all pokemon within this storage. This is the implementation's array and should not be modified.
-
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
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.RegistryFriendlyByteBuf buffer) Writes the storage to the given buffer- Parameters:
buffer- the buffer to write to
-
decode
public abstract void decode(net.minecraft.network.RegistryFriendlyByteBuf 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
Same asgetAll(), but forStoragePositions. 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
Gets the first position where there is no pokemon in the storage- Returns:
- the first empty position in the storage
-
set
Sets the given pokemon at the given position in the storage- Parameters:
position- the position to set the pokemonpokemon- the pokemon to set
-
get
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
Swaps the pokemon at the given positions in the storage- Parameters:
position1- the first position to swapposition2- the second position to swap
-
writeToNBT
public abstract net.minecraft.nbt.CompoundTag writeToNBT(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider registryAccess) 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, net.minecraft.core.HolderLookup.Provider registryAccess) 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
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
Clone the Pokemon stored in a position and add it to the storage.- Parameters:
position- TheStoragePositionto clone- Returns:
- The
StoragePositionof the cloned Pokemon. Null if cloning was not completed.
-
add
Adds the given Pokemon to this storage in the first available position. If the storage is full, then in the case that it is aPlayerPartyStoragethen 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:
trueif it was able to add to this storage, or in the case of this being a fullPlayerPartyStorage,trueif there was an empty space in the PC. Otherwisefalse.
-
addAndGetPosition
Adds a Pokemon to the storage and returns theStoragePositionthat it was added to. Similarly toadd(Pokemon), if the storage is full, then in the case that it is aPlayerPartyStoragethen 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
-
countPokemon
public int countPokemon()Counts the number of Pokémon in this storage. Excluding eggs.- Returns:
- The number of Pokémon this storage holds. Excluding eggs.
-
countEggs
public int countEggs()Counts the number of eggs in this storage.- Returns:
- The number of eggs this storage holds.
-
countEmpty
public int countEmpty()Counts the number of empty slots in this storage.- 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.
-
countAll
Counts the number of pokemon in the storage that match the given specification- Parameters:
spec- The specification to match- Returns:
- The number of pokemon in the storage that match the given specification
-
countAll
Counts the number of pokemon in the storage that match the given condition- Parameters:
condition- The condition to match- Returns:
- The number of pokemon in the storage that match the given condition
-
findOne
Finds the first pokemon in the storage that matches the given condition- Parameters:
condition- The condition to match- Returns:
- The first pokemon in the storage that matches the given condition
-
findOne
Finds the first pokemon in the storage that matches the given specification- Parameters:
spec- The specification to match- Returns:
- The first pokemon in the storage that matches the given specification
-
findAll
Finds all the pokemon in the storage that match the given condition- Parameters:
condition- The condition to match- Returns:
- All the pokemon in the storage that match the given condition
-
findAll
Finds all the pokemon in the storage that match the given specification- Parameters:
spec- The specification to match- Returns:
- All the pokemon in the storage that match the given specification
-
findAllPositions
Finds all the positions in the storage that match the given condition- Parameters:
condition- The condition to match- Returns:
- All the positions in the storage that match the given condition
-
findAllPositions
Finds all the positions in the storage that match the given specification- Parameters:
spec- The specification to match- Returns:
- All the positions in the storage that match the given specification
-
find
Finds the pokemon with the given UUID- Parameters:
uuid- the UUID to find- Returns:
- the pokemon with the given UUID
-
validate
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 validatepokemonUUID- the UUID to validate- Returns:
- if the pokemon at the given position has the given UUID
-
notifyListeners
Notifies all the tracking players of a change in the storage- Parameters:
position- the position of the changepokemon- the pokemon that was changeddataTypes- the types of data that was changed
-
retrieveAll
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
-
getCurryData
public int[] getCurryData() -
updateSingleCurryData
public void updateSingleCurryData(EnumCurryKey curryKey, EnumBerryFlavor cookingFlavor, EnumCurryRating rating)
-