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
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
canExtract(T resource)
Deprecated.Returntrue
if the passed non-blank variant can be extracted,false
otherwise.protected boolean
Deprecated.Returntrue
if the passed non-blank variant can be inserted,false
otherwise.long
extract(T extractedResource, long maxAmount, TransactionContext transaction)
Deprecated.Try to extract up to some amount of a resource from this storage.long
Deprecated.protected abstract long
getAmount(ItemVariant currentVariant)
Deprecated.Return the current amount by reading the NBT of the passed variant.protected abstract T
Deprecated.Return the blank resource.long
Deprecated.protected abstract long
getCapacity(T variant)
Deprecated.Return the capacity of this storage for the passed resource.Deprecated.protected abstract T
getResource(ItemVariant currentVariant)
Deprecated.Return the current resource by reading the NBT of the passed variant.protected abstract ItemVariant
getUpdatedVariant(ItemVariant currentVariant, T newResource, long newAmount)
Deprecated.Return an updated variant with new resource and amount.long
insert(T insertedResource, long maxAmount, TransactionContext transaction)
Deprecated.Try to insert up to some amount of a resource into this storage.boolean
Deprecated.boolean
Deprecated.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.boolean
Deprecated.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, wait
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage
iterator
Methods 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 passedcurrentVariant
to 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.Returntrue
if the passed non-blank variant can be inserted,false
otherwise. -
canExtract
Deprecated.Returntrue
if the passed non-blank variant can be extracted,false
otherwise. -
supportsInsertion
public boolean supportsInsertion()Deprecated.Description copied from interface:Storage
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.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:
supportsInsertion
in interfaceStorage<T extends TransferVariant<?>>
-
insert
Deprecated.Description copied from interface:Storage
Try to insert up to some amount of a resource into this storage.- Specified by:
insert
in 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:Storage
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.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:
supportsExtraction
in interfaceStorage<T extends TransferVariant<?>>
-
extract
Deprecated.Description copied from interface:Storage
Try to extract up to some amount of a resource from this storage.- Specified by:
extract
in interfaceStorage<T extends TransferVariant<?>>
- Specified by:
extract
in 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:
isResourceBlank
in interfaceStorageView<T extends TransferVariant<?>>
- Returns:
true
if theStorageView.getResource()
contained in this storage view is blank, orfalse
otherwise.
-
getResource
Deprecated.- Specified by:
getResource
in 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:
getAmount
in interfaceStorageView<T extends TransferVariant<?>>
- Returns:
- The amount of
StorageView.getResource()
stored in this view.
-
getCapacity
public long getCapacity()Deprecated.- Specified by:
getCapacity
in 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.
-