Class LivingEntityEquipmentWrapper.SlotWrapper
- All Implemented Interfaces:
ValueIOSerializable,ResourceHandler<ItemResource>
- Enclosing class:
LivingEntityEquipmentWrapper
EquipmentSlot, used as a building block.-
Field Summary
FieldsFields inherited from class net.neoforged.neoforge.transfer.item.ItemStackResourceHandler
VALUE_IO_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intgetCapacity(ItemResource resource) Return the maximum capacity of this handler for the passed item resource.protected ItemStackgetStack()Return the stack of this handler.protected booleanisValid(ItemResource resource) Returntrueif the passed non-empty item resource can fit in this handler,falseotherwise.protected voidonRootCommit(ItemStack originalState) 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()Methods inherited from class net.neoforged.neoforge.transfer.item.ItemStackResourceHandler
createSnapshot, deserialize, extract, getAmountAsLong, getCapacityAsLong, getResource, insert, isValid, revertToSnapshot, serialize, sizeMethods inherited from class net.neoforged.neoforge.transfer.transaction.SnapshotJournal
releaseSnapshot, updateSnapshotsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.transfer.ResourceHandler
extract, getAmountAsInt, getCapacityAsInt, insert
-
Field Details
-
slot
-
-
Constructor Details
-
SlotWrapper
-
-
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(net.minecraft.world.item.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
Description copied from class:ItemStackResourceHandlerReturn the maximum capacity of this handler for the passed item resource. If the passed item resource is empty, an estimate should be returned.If the capacity should be limited by the max stack size of the item, this function must take it into account. Additionally, the empty resource should be special-cased to return the intended maximum capacity of the handler, as it will otherwise report a max stack size of 1. For example, a handler with a maximum count of 4, or less for items that have a smaller max stack size, should override this to return
resource.isEmpty() ? 4 : Math.min(resource.getMaxStackSize(), 4).- Overrides:
getCapacityin classItemStackResourceHandler- Returns:
- The maximum capacity of this handler for the passed item resource.
-
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:
originalState- 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
-