Class SnapshotParticipant<T>

java.lang.Object
net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant<T>
Type Parameters:
T - The objects that this participant uses to save its state snapshots.
All Implemented Interfaces:
TransactionContext.CloseCallback, TransactionContext.OuterCloseCallback
Direct Known Subclasses:
SingleStackStorage, SingleVariantStorage

public abstract class SnapshotParticipant<T> extends Object implements TransactionContext.CloseCallback, TransactionContext.OuterCloseCallback
A base participant implementation that modifies itself during transactions, saving snapshots of its state in objects of type T in case it needs to revert to a previous state.

How to use from subclasses

More technical explanation

updateSnapshots(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext) should be called before any modification. This will save the state of this participant using createSnapshot() if no state was already saved for that transaction. When the transaction is aborted and changes need to be rolled back, readSnapshot(T) will be called to signal that the current state should revert to that of the snapshot. The snapshot object is then released, and can be cached for subsequent use, or discarded.

When an outer transaction is committed, readSnapshot(T) will not be called so that the current state of this participant is retained. releaseSnapshot(T) will be called because the snapshot is not necessary anymore, and onFinalCommit() will be called after the transaction is closed.