Class ComposterWrapper

java.lang.Object
net.neoforged.neoforge.transfer.transaction.SnapshotJournal<BlockState>
net.neoforged.neoforge.transfer.item.ComposterWrapper

@Internal public class ComposterWrapper extends SnapshotJournal<BlockState>
ResourceHandler<ItemResource> implementation for the composter block.
  • Field Details

  • Constructor Details

  • Method Details

    • get

      @Nullable public static @Nullable ResourceHandler<ItemResource> get(Level level, BlockPos pos, @Nullable @Nullable Direction direction)
    • createSnapshot

      protected BlockState 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<BlockState>
    • revertToSnapshot

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

      protected void onRootCommit(BlockState 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<BlockState>
      Parameters:
      originalState - state of this journal before the transactional operations. This corresponds to the first snapshot that was created in the transactional operations.
    • getComposterValue

      private static float getComposterValue(ItemResource resource)
    • setLevel

      private void setLevel(BlockState state, int newLevel)
      Sets the composter's level, without sending notifications, which are deferred until onRootCommit(net.minecraft.world.level.block.state.BlockState).