Class RootCommitJournal

java.lang.Object
net.neoforged.neoforge.transfer.transaction.SnapshotJournal<@Nullable Void>
net.neoforged.neoforge.transfer.transaction.RootCommitJournal

public final class RootCommitJournal extends SnapshotJournal<@Nullable Void>
A journal that can be added to a transaction with SnapshotJournal.updateSnapshots(TransactionContext), and will invoke a callback if/when the root transaction is committed.

This journal does not save any state snapshot by itself, so it should be used in conjunction with other journals that handle the actual state.

  • Field Details

    • rootCommitCallback

      private final Runnable rootCommitCallback
  • Constructor Details

    • RootCommitJournal

      public RootCommitJournal(Runnable rootCommitCallback)
  • Method Details

    • createSnapshot

      protected @Nullable Void createSnapshot()
      Description copied from class: SnapshotJournal
      Return a new nonnull object containing the current state of this journal. null may not be returned, or an exception will be thrown!
      Specified by:
      createSnapshot in class SnapshotJournal<@Nullable Void>
    • revertToSnapshot

      protected void revertToSnapshot(@Nullable Void snapshot)
      Description copied from class: SnapshotJournal
      Roll back to a state previously created by SnapshotJournal.createSnapshot().
      Specified by:
      revertToSnapshot in class SnapshotJournal<@Nullable Void>
    • onRootCommit

      protected void onRootCommit(@Nullable Void originalState)
      Description copied from class: SnapshotJournal
      Called after the root transaction was successfully committed, to perform irreversible actions such as setChanged() or neighbor updates.

      When a root transaction is being closed, all journals for which onRootCommit will 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 more onRootCommit callbacks being enqueued:

      • A journal that is already enqueued for onRootCommit will not be enqueued a second time. It will thus be notified a single time for changes that spanned multiple transactions. The originalState will be the state at the beginning of the first of these transactions.
      • A journal whose onRootCommit was already processed will be enqueued again. The journal will be notified a second time, with originalState the state at the beginning of the second transaction.
      • In particular, a journal is removed from the queue immediately before onRootCommit is called. Should the journal be modified again from its own onRootCommit, it will be added to the queue, and onRootCommit will 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 on onRootCommit being 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:
      onRootCommit in class SnapshotJournal<@Nullable Void>
      Parameters:
      originalState - state of this journal before the transactional operations. This corresponds to the first snapshot that was created in the transactional operations.