Class VanillaContainerWrapper.SlotWrapper
- All Implemented Interfaces:
ValueIOSerializable, ResourceHandler<ItemResource>
- Direct Known Subclasses:
PlayerInventoryWrapper.ArmorSlotWrapper
- Enclosing class:
VanillaContainerWrapper
-
Field Summary
FieldsFields inherited from class ItemStackResourceHandler
VALUE_IO_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintextract(int index, ItemResource resource, int amount, TransactionContext transaction) Extracts up to the given amount of a resource from the handler at the given index.protected intgetCapacity(ItemResource resource) Special cases because vanilla checks the current stack in the following functions (which it shouldn't):AbstractFurnaceBlockEntity.canPlaceItem(int, ItemStack).BrewingStandBlockEntity.canPlaceItem(int, ItemStack).protected ItemStackgetStack()Return the stack of this handler.intinsert(int index, ItemResource resource, int amount, TransactionContext transaction) Inserts up to the given amount of a resource into the handler at the given index.protected booleanisValid(ItemResource resource) Returntrueif the passed non-empty item resource can fit in this handler,falseotherwise.protected voidonRootCommit(ItemStack original) Called after the root transaction was successfully committed, to perform irreversible actions such assetChanged()or neighbor updates.protected voidSet the stack of this handler.toString()voidupdateSnapshots(TransactionContext transaction) Update the stored snapshots so that the changes happening as part of the passed transaction can be correctly committed or rolled back.Methods inherited from class ItemStackResourceHandler
createSnapshot, deserialize, getAmountAsLong, getCapacityAsLong, getResource, isValid, revertToSnapshot, serialize, sizeMethods inherited from class SnapshotJournal
releaseSnapshotMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceHandler
extract, getAmountAsInt, getCapacityAsInt, insert
-
Field Details
-
index
private final int index
-
-
Constructor Details
-
SlotWrapper
SlotWrapper(int index)
-
-
Method Details
-
getStack
Description copied from class:ItemStackResourceHandlerReturn the stack of this handler. It will be modified directly sometimes to avoid needless copies. However, any mutation of the stack will directly be followed by a call toItemStackResourceHandler.setStack(ItemStack). This means that either returning the backing stack directly or a copy is safe. If returning a copy, consider overridingItemStackResourceHandler.getAmountAsLong(int)andItemStackResourceHandler.getResource(int)to avoid unnecessary copies.- Specified by:
getStackin classItemStackResourceHandler- Returns:
- The current stack.
-
setStack
Description copied from class:ItemStackResourceHandlerSet the stack of this handler.- Specified by:
setStackin classItemStackResourceHandler
-
isValid
Description copied from class:ItemStackResourceHandlerReturntrueif the passed non-empty item resource can fit in this handler,falseotherwise.The result of this function is used in the provided implementations of:
ItemStackResourceHandler.isValid(int, ItemResource), to report which items are valid;ItemStackResourceHandler.getCapacityAsLong(int, ItemResource), to report a capacity of0for invalid items;ItemStackResourceHandler.insert(int, ItemResource, int, TransactionContext), to reject items that cannot fit in this handler.
- Overrides:
isValidin classItemStackResourceHandler
-
getCapacity
Special cases because vanilla checks the current stack in the following functions (which it shouldn't):AbstractFurnaceBlockEntity.canPlaceItem(int, ItemStack).BrewingStandBlockEntity.canPlaceItem(int, ItemStack).
Should these extra checks cause performance issues, we can switch to subclasses.
- Overrides:
getCapacityin classItemStackResourceHandler- Returns:
- The maximum capacity of this handler for the passed item resource.
-
insert
Description copied from interface:ResourceHandlerInserts up to the given amount of a resource into the handler at the given index.Changes to the handler are made in the context of a transaction.
- Specified by:
insertin interfaceResourceHandler<ItemResource>- Overrides:
insertin classItemStackResourceHandler- Parameters:
index- The index to insert the resource into.resource- The resource to insert. Must be non-empty.amount- The maximum amount of the resource to insert. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was inserted. Between
0(inclusive, nothing was inserted) andamount(inclusive, everything was inserted). - See Also:
-
extract
Description copied from interface:ResourceHandlerExtracts up to the given amount of a resource from the handler at the given index.Changes to the handler are made in the context of a transaction.
- Specified by:
extractin interfaceResourceHandler<ItemResource>- Overrides:
extractin classItemStackResourceHandler- Parameters:
index- The index to extract the resource from.resource- The resource to extract. Must be non-empty.amount- The maximum amount of the resource to extract. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was extracted. Between
0(inclusive, nothing was extracted) andamount(inclusive, everything was extracted). - See Also:
-
updateSnapshots
Description copied from class:SnapshotJournalUpdate the stored snapshots so that the changes happening as part of the passed transaction can be correctly committed or rolled back. This function should be called every time the journal is about to change its internal state as part of a transaction. However, only the first snapshot taken of that depth will be taken.- Overrides:
updateSnapshotsin classSnapshotJournal<ItemStack>
-
onRootCommit
Description copied from class:SnapshotJournalCalled after the root transaction was successfully committed, to perform irreversible actions such assetChanged()or neighbor updates.When a root transaction is being closed, all journals for which
onRootCommitwill be called are stored in a global thread-local queue. The processing of this queue starts immediately after the root transaction is closed. As such, new root transactions can safely be opened from this method.When a root transaction is opened from
onRootCommit, any journal might be modified, leading to moreonRootCommitcallbacks being enqueued:- A journal that is already enqueued for
onRootCommitwill not be enqueued a second time. It will thus be notified a single time for changes that spanned multiple transactions. TheoriginalStatewill be the state at the beginning of the first of these transactions. - A journal whose
onRootCommitwas already processed will be enqueued again. The journal will be notified a second time, withoriginalStatethe state at the beginning of the second transaction. - In particular, a journal is removed from the queue immediately before
onRootCommitis called. Should the journal be modified again from its ownonRootCommit, it will be added to the queue, andonRootCommitwill be called again later.
Given the large amount of actions that can happen between the last modification and the call to
onRootCommit, journals should not depend ononRootCommitbeing called immediately for correctness, and implementations of this method should be careful (e.g. in case the journal got removed from the level). For example, skipping block change notifications because the block was removed from the level is preferable than crashing or silently overwriting the block.- Overrides:
onRootCommitin classSnapshotJournal<ItemStack>- Parameters:
original- state of this journal before the transactional operations. This corresponds to the firstsnapshotthat was created in the transactional operations.
- A journal that is already enqueued for
-
toString
- Overrides:
toStringin classItemStackResourceHandler
-