Class PokemonStorage
java.lang.Object
com.pixelmonmod.pixelmon.api.storage.PokemonStorage
- Direct Known Subclasses:
PartyStorage
,PCBox
,PCStorage
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected boolean
protected final net.minecraft.resources.ResourceLocation
protected final UUID
-
Constructor Summary
ModifierConstructorDescriptionprotected
PokemonStorage
(net.minecraft.resources.ResourceLocation storageType, UUID uuid) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the given Pokemon to this storage in the first available position.addAndGetPosition
(Pokemon pokemon) Adds a Pokemon to the storage and returns theStoragePosition
that it was added to.boolean
canTransfer
(StoragePosition from, StoragePosition to) abstract void
clear()
Clears all the pokemon from the storageclone
(StoragePosition position) Clone the Pokemon stored in a position and add it to the storage.int
countAll()
int
int
int
abstract void
decode
(net.minecraft.network.FriendlyByteBuf buf) Reads the storage from the given bufferabstract void
encode
(net.minecraft.network.FriendlyByteBuf buffer) Writes the storage to the given bufferFinds the pokemon with the given UUIDfindAll
(PokemonSpecification spec) findAllPositions
(Predicate<Pokemon> condition) findOne
(PokemonSpecification spec) 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 positionabstract Pokemon[]
getAll()
Gets a array of all pokemon within this storage.abstract StoragePosition[]
Same asgetAll()
, but forStoragePosition
s.int[]
abstract StoragePosition
Gets the first position where there is no pokemon in the storage@Nullable net.minecraft.server.level.ServerPlayer
getOwner()
Gets the owner of the Pokemon storageabstract StoragePosition
getPosition
(Pokemon pokemon) Gets the position of the given pokemon in the storage
Will return null if the pokemon is not in the storageboolean
net.minecraft.resources.ResourceLocation
Gets 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 thePlayerPartyStorage
orPCStorage
boolean
hasSpace()
void
initialize
(net.minecraft.server.level.ServerPlayer player) Sends the contents of the storage to the given playerboolean
isTracking
(net.minecraft.server.level.ServerPlayer player) Checks if the given player is tracking the storageabstract int
maxSize()
void
notifyListeners
(StoragePosition position, Pokemon pokemon, EnumUpdateType... dataTypes) Notifies all the tracking players of a change in the storagevoid
open
(net.minecraft.server.level.ServerPlayer player) Opens the storage for the given playerabstract CompletableFuture<? extends PokemonStorage>
readFromNBT
(net.minecraft.nbt.CompoundTag nbt) Reads the storage from the given NBT tagvoid
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 safelyabstract void
set
(StoragePosition position, Pokemon pokemon) Sets the given pokemon at the given position in the storagevoid
setHasChanged
(boolean hasChanged) void
boolean
Gets if the storage should send updates to the tracking entitiesvoid
shouldSendUpdates
(boolean shouldSendUpdates) Sets if the storage should send updates to the tracking entities when changes are made to it's contentsabstract void
swap
(StoragePosition position1, StoragePosition position2) Swaps the pokemon at the given positions in the storagetoString()
void
track
(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 storageboolean
transfer
(PokemonStorage from, StoragePosition fromPosition, StoragePosition toPosition) void
untrack
(net.minecraft.server.level.ServerPlayer player) Removes a player from the list of players to update when changes are made to the storagevoid
updateSingleCurryData
(EnumCurryKey curryKey, EnumBerryFlavor cookingFlavor, EnumCurryRating rating) 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 trueabstract net.minecraft.nbt.CompoundTag
writeToNBT
(net.minecraft.nbt.CompoundTag nbt) Writes the storage to the given NBT tagMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 thePlayerPartyStorage
orPCStorage
- 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 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
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
Same asgetAll()
, but forStoragePosition
s. 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) 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
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
- TheStoragePosition
to clone- Returns:
- The
StoragePosition
of 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 aPlayerPartyStorage
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 fullPlayerPartyStorage
,true
if there was an empty space in the PC. Otherwisefalse
.
-
addAndGetPosition
Adds a Pokemon to the storage and returns theStoragePosition
that it was added to. Similarly toadd(Pokemon)
, if the storage is full, then in the case that it is aPlayerPartyStorage
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
-
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
-
findOne
-
findAll
-
findAll
-
findAllPositions
-
findAllPositions
-
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)
-