Class SimpleEnergyHandler.EnergyJournal

java.lang.Object
net.neoforged.neoforge.transfer.transaction.SnapshotJournal<Integer>
net.neoforged.neoforge.transfer.energy.SimpleEnergyHandler.EnergyJournal
Enclosing class:
SimpleEnergyHandler

private class SimpleEnergyHandler.EnergyJournal extends SnapshotJournal<Integer>
  • Constructor Details

    • EnergyJournal

      private EnergyJournal()
  • Method Details

    • createSnapshot

      protected Integer createSnapshot()
      Description copied from class: SnapshotJournal

      Returns a new object containing a copy of this journal's current state.

      One may settle for a partial copy of this journal's state, as long as the returned snapshot will be sufficient to rollback (via SnapshotJournal.revertToSnapshot(T)) all changes made to this journal's state since the snapshot was created.

      SnapshotJournal.isInTransaction() will return true inside this callback, and will continue to return true until all snapshots have either been reverted to or committed.

      Specified by:
      createSnapshot in class SnapshotJournal<Integer>
      Returns:
      a new object containing a copy of this journal's current state
    • revertToSnapshot

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

      protected void onRootCommit(Integer originalState)
      Description copied from class: SnapshotJournal
      Called after the root transaction was successfully committed, to perform irreversible actions such as setChanged() or neighbor updates. SnapshotJournal.isInTransaction() will return false inside this callback.

      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<Integer>
      Parameters:
      originalState - state of this journal before the transactional operations. This corresponds to the first snapshot that was created in the transactional operations.