Class SingleVariantItemStorage<T extends TransferVariant<?>>
java.lang.Object
net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantItemStorage<T>
- Type Parameters:
T- The type of the stored transfer variant.
- All Implemented Interfaces:
SingleSlotStorage<T>,Storage<T>,StorageView<T>
@Experimental
@Deprecated
public abstract class SingleVariantItemStorage<T extends TransferVariant<?>>
extends Object
implements SingleSlotStorage<T>
Deprecated.
Experimental feature, we reserve the right to remove or change it without further notice.
The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
Base implementation of a fixed-capacity "continuous" storage for item-provided storage APIs.
The item may not change, so the data has to be stored in the NBT of the stacks.
This can be used for example to implement portable fluid tanks, fluid-containing jetpacks, and so on...
Continuous here means that they can store any integer amount between 0 and the capacity, unlike buckets or bottles.
To expose the storage API for an item, you need to register a provider for your item, and pass it an instance of this class:
- You must override
getBlankResource(), for examplereturn FluidVariant.blank();for fluids. - You must override
getResource(ItemVariant)andgetAmount(ItemVariant). Generally you will read the resource and the amount from the NBT of the item variant. - You must override
getCapacity(TransferVariant)to set the capacity of your storage. - You must override
getUpdatedVariant(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, T, long). It is used to change the resource and the amount of the item variant. Generally you will copy the NBT, modify it, and then create a new variant from that. Copying the NBT instead of recreating it from scratch is important to keep custom names or enchantments. - You may also override
canInsert(T)andcanExtract(T)if you want to restrict insertion and/or extraction.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanExtract(T resource)Deprecated.Returntrueif the passed non-blank variant can be extracted,falseotherwise.protected booleanDeprecated.Returntrueif the passed non-blank variant can be inserted,falseotherwise.longextract(T extractedResource, long maxAmount, TransactionContext transaction)Deprecated.Try to extract up to some amount of a resource from this storage.longDeprecated.protected abstract longgetAmount(ItemVariant currentVariant)Deprecated.Return the current amount by reading the NBT of the passed variant.protected abstract TDeprecated.Return the blank resource.longDeprecated.protected abstract longgetCapacity(T variant)Deprecated.Return the capacity of this storage for the passed resource.Deprecated.protected abstract TgetResource(ItemVariant currentVariant)Deprecated.Return the current resource by reading the NBT of the passed variant.protected abstract ItemVariantgetUpdatedVariant(ItemVariant currentVariant, T newResource, long newAmount)Deprecated.Return an updated variant with new resource and amount.longinsert(T insertedResource, long maxAmount, TransactionContext transaction)Deprecated.Try to insert up to some amount of a resource into this storage.booleanDeprecated.booleanDeprecated.Return false if callingStorage.extract(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)will absolutely always return 0, or true otherwise or in doubt.booleanDeprecated.Return false if callingStorage.insert(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)will absolutely always return 0, or true otherwise or in doubt.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage
iteratorMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, getVersion, iterable, simulateExtract, simulateInsert
-
Constructor Details
-
SingleVariantItemStorage
Deprecated.
-
-
Method Details
-
getBlankResource
Deprecated.Return the blank resource. -
getResource
Deprecated.Return the current resource by reading the NBT of the passed variant. -
getAmount
Deprecated.Return the current amount by reading the NBT of the passed variant. -
getCapacity
Deprecated.Return the capacity of this storage for the passed resource. An estimate should be returned if the passed resource is blank. -
getUpdatedVariant
protected abstract ItemVariant getUpdatedVariant(ItemVariant currentVariant, T newResource, long newAmount)Deprecated.Return an updated variant with new resource and amount. Implementors should generally convert the passedcurrentVariantto a stack, then edit the NBT of the stack so it contains the correct resource and amount.When the new amount is 0, it is recommended that the subtags corresponding to the resource and amount be removed, for example using
ItemStack.removeSubNbt(java.lang.String), so that newly-crafted containers can stack with emptied containers.- Parameters:
currentVariant- Variant to which the modification should be applied.newResource- Resource that should be contained in the returned variant.newAmount- Amount that should be contained in the returned variant.- Returns:
- A modified variant containing the new resource and amount.
-
canInsert
Deprecated.Returntrueif the passed non-blank variant can be inserted,falseotherwise. -
canExtract
Deprecated.Returntrueif the passed non-blank variant can be extracted,falseotherwise. -
supportsInsertion
public boolean supportsInsertion()Deprecated.Description copied from interface:StorageReturn false if callingStorage.insert(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)will absolutely always return 0, or true otherwise or in doubt.Note: This function is meant to be used by pipes or other devices that can transfer resources to know if they should interact with this storage at all.
- Specified by:
supportsInsertionin interfaceStorage<T extends TransferVariant<?>>
-
insert
Deprecated.Description copied from interface:StorageTry to insert up to some amount of a resource into this storage.- Specified by:
insertin interfaceStorage<T extends TransferVariant<?>>- Parameters:
insertedResource- 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 nonnegative integer not greater than maxAmount: the amount that was inserted.
-
supportsExtraction
public boolean supportsExtraction()Deprecated.Description copied from interface:StorageReturn false if callingStorage.extract(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)will absolutely always return 0, or true otherwise or in doubt.Note: This function is meant to be used by pipes or other devices that can transfer resources to know if they should interact with this storage at all.
- Specified by:
supportsExtractionin interfaceStorage<T extends TransferVariant<?>>
-
extract
Deprecated.Description copied from interface:StorageTry to extract up to some amount of a resource from this storage.- Specified by:
extractin interfaceStorage<T extends TransferVariant<?>>- Specified by:
extractin interfaceStorageView<T extends TransferVariant<?>>- Parameters:
extractedResource- 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 nonnegative integer not greater than maxAmount: the amount that was extracted.
-
isResourceBlank
public boolean isResourceBlank()Deprecated.- Specified by:
isResourceBlankin interfaceStorageView<T extends TransferVariant<?>>- Returns:
trueif theStorageView.getResource()contained in this storage view is blank, orfalseotherwise.
-
getResource
Deprecated.- Specified by:
getResourcein interfaceStorageView<T extends TransferVariant<?>>- Returns:
- The resource stored in this view. May not be blank if
StorageView.isResourceBlank()isfalse.
-
getAmount
public long getAmount()Deprecated.- Specified by:
getAmountin interfaceStorageView<T extends TransferVariant<?>>- Returns:
- The amount of
StorageView.getResource()stored in this view.
-
getCapacity
public long getCapacity()Deprecated.- Specified by:
getCapacityin interfaceStorageView<T extends TransferVariant<?>>- Returns:
- The total amount of
StorageView.getResource()that could be stored in this view, or an estimate of the number of resources that could be stored if this view has a blank resource.
-