Class SimpleEnergyHandler.EnergyJournal
- Enclosing class:
SimpleEnergyHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected IntegerReturn a new nonnull object containing the current state of this journal.protected voidonRootCommit(Integer originalState) Called after the root transaction was successfully committed, to perform irreversible actions such assetChanged()or neighbor updates.protected voidrevertToSnapshot(Integer snapshot) Roll back to a state previously created bySnapshotJournal.createSnapshot().Methods inherited from class net.neoforged.neoforge.transfer.transaction.SnapshotJournal
releaseSnapshot, updateSnapshots
-
Constructor Details
-
EnergyJournal
private EnergyJournal()
-
-
Method Details
-
createSnapshot
Description copied from class:SnapshotJournalReturn a new nonnull object containing the current state of this journal.nullmay not be returned, or an exception will be thrown!- Specified by:
createSnapshotin classSnapshotJournal<Integer>
-
revertToSnapshot
Description copied from class:SnapshotJournalRoll back to a state previously created bySnapshotJournal.createSnapshot().- Specified by:
revertToSnapshotin classSnapshotJournal<Integer>
-
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<Integer>- 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
-