Class SingleVariantStorage<T extends TransferVariant<?>>
java.lang.Object
net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant<ResourceAmount<T>>
net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage<T>
- All Implemented Interfaces:
- Iterable<StorageView<T>>,- SingleSlotStorage<T>,- SlottedStorage<T>,- Storage<T>,- StorageView<T>,- TransactionContext.CloseCallback,- TransactionContext.OuterCloseCallback
- Direct Known Subclasses:
- SingleFluidStorage,- SingleItemStorage
public abstract class SingleVariantStorage<T extends TransferVariant<?>>
extends SnapshotParticipant<ResourceAmount<T>>
implements SingleSlotStorage<T>
A storage that can store a single transfer variant at any given time.
 Implementors should at least override 
getCapacity(TransferVariant),
 and probably SnapshotParticipant.onFinalCommit() as well for markDirty() and similar calls.
 canInsert(T) and canExtract(T) can be used for more precise control over which variants may be inserted or extracted.
 If one of these two functions is overridden to always return false, implementors may also wish to override
 Storage.supportsInsertion() and/or Storage.supportsExtraction().
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected booleancanExtract(T variant) protected booleanprotected ResourceAmount<T> Return a new nonnull object containing the current state of this participant.longextract(T extractedVariant, long maxAmount, TransactionContext transaction) Try to extract up to some amount of a resource from this storage.longprotected abstract TReturn the blank variant.longprotected abstract longgetCapacity(T variant) Return the maximum capacity of this storage for the passed transfer variant.longinsert(T insertedVariant, long maxAmount, TransactionContext transaction) Try to insert up to some amount of a resource into this storage.booleanReturntrueif theStorageView.getResource()contained in this storage view is blank, orfalseotherwise.static <T extends TransferVariant<?>>
 voidreadNbt(SingleVariantStorage<T> storage, com.mojang.serialization.Codec<T> codec, Supplier<T> fallback, NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) Read aSingleVariantStoragefrom NBT.protected voidreadSnapshot(ResourceAmount<T> snapshot) Roll back to a state previously created bySnapshotParticipant.createSnapshot().toString()static <T extends TransferVariant<?>>
 voidwriteNbt(SingleVariantStorage<T> storage, com.mojang.serialization.Codec<T> codec, NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) Write aSingleVariantStorageto NBT.Methods inherited from class net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipantafterOuterClose, onClose, onFinalCommit, releaseSnapshot, updateSnapshotsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliteratorMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStoragegetSlot, getSlotCount, iteratorMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.SlottedStoragegetSlotsMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.StoragegetVersion, nonEmptyIterator, nonEmptyViews, supportsExtraction, supportsInsertionMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.StorageViewgetUnderlyingView
- 
Field Details- 
variant
- 
amountpublic long amount
 
- 
- 
Constructor Details- 
SingleVariantStoragepublic SingleVariantStorage()
 
- 
- 
Method Details- 
getBlankVariantReturn the blank variant.Note: this is called very early in the constructor. If fields need to be accessed from this function, make sure to re-initialize variantyourself.
- 
getCapacityReturn the maximum capacity of this storage for the passed transfer variant. If the passed variant is blank, an estimate should be returned.
- 
canInsert- Returns:
- trueif the passed non-blank variant can be inserted,- falseotherwise.
 
- 
canExtract- Returns:
- trueif the passed non-blank variant can be extracted,- falseotherwise.
 
- 
insertDescription copied from interface:StorageTry to insert up to some amount of a resource into this storage.- Specified by:
- insertin interface- Storage<T extends TransferVariant<?>>
- Parameters:
- insertedVariant- The resource to insert. May not be blank.
- maxAmount- The maximum amount of resource to insert. May not be negative.
- transaction- The transaction this operation is part of.
- Returns:
- A non-negative integer not greater than maxAmount: the amount that was inserted.
 
- 
extractDescription copied from interface:StorageTry to extract up to some amount of a resource from this storage.- Specified by:
- extractin interface- Storage<T extends TransferVariant<?>>
- Specified by:
- extractin interface- StorageView<T extends TransferVariant<?>>
- Parameters:
- extractedVariant- The resource to extract. May not be blank.
- maxAmount- The maximum amount of resource to extract. May not be negative.
- transaction- The transaction this operation is part of.
- Returns:
- A non-negative integer not greater than maxAmount: the amount that was extracted.
 
- 
isResourceBlankpublic boolean isResourceBlank()Description copied from interface:StorageViewReturntrueif theStorageView.getResource()contained in this storage view is blank, orfalseotherwise.This function is mostly useful when dealing with storages of arbitrary types. For transfer variant storages, this should always be equivalent to getResource().isBlank().- Specified by:
- isResourceBlankin interface- StorageView<T extends TransferVariant<?>>
 
- 
getResource- Specified by:
- getResourcein interface- StorageView<T extends TransferVariant<?>>
- Returns:
- The resource stored in this view. May not be blank if StorageView.isResourceBlank()isfalse.
 
- 
getAmountpublic long getAmount()- Specified by:
- getAmountin interface- StorageView<T extends TransferVariant<?>>
- Returns:
- The amount of StorageView.getResource()stored in this view.
 
- 
getCapacitypublic long getCapacity()- Specified by:
- getCapacityin interface- StorageView<T extends TransferVariant<?>>
- Returns:
- The total amount of StorageView.getResource()that could be stored in this view, or an estimated upper bound on the number of resources that could be stored if this view has a blank resource.
 
- 
createSnapshotDescription copied from class:SnapshotParticipantReturn a new nonnull object containing the current state of this participant.nullmay not be returned, or an exception will be thrown!- Specified by:
- createSnapshotin class- SnapshotParticipant<ResourceAmount<T extends TransferVariant<?>>>
 
- 
readSnapshotDescription copied from class:SnapshotParticipantRoll back to a state previously created bySnapshotParticipant.createSnapshot().- Specified by:
- readSnapshotin class- SnapshotParticipant<ResourceAmount<T extends TransferVariant<?>>>
 
- 
toString
- 
readNbtpublic static <T extends TransferVariant<?>> void readNbt(SingleVariantStorage<T> storage, com.mojang.serialization.Codec<T> codec, Supplier<T> fallback, NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) Read aSingleVariantStoragefrom NBT.- Type Parameters:
- T- the type of the item variant
- Parameters:
- storage- the- SingleVariantStorageto read into
- codec- the item variant codec
- fallback- the fallback item variant, used when the NBT is invalid
- nbt- the NBT to read from
- wrapperLookup- the- RegistryWrapper.WrapperLookupinstance
 
- 
writeNbtpublic static <T extends TransferVariant<?>> void writeNbt(SingleVariantStorage<T> storage, com.mojang.serialization.Codec<T> codec, NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) Write aSingleVariantStorageto NBT.- Type Parameters:
- T- the type of the item variant
- Parameters:
- storage- the- SingleVariantStorageto write from
- codec- the item variant codec
- nbt- the NBT to write to
- wrapperLookup- the- RegistryWrapper.WrapperLookupinstance
 
 
-