Class ComposterWrapper
ResourceHandler<ItemResource> implementation for the composter block.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate classprivate static final recordTo make sure multiple accesses to the same composter return the same wrapper, we maintain a(Level, BlockPos) -> Wrappercache. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ItemResourceprivate final ResourceHandler<ItemResource> private final ComposterWrapper.WrapperLocationprivate final ResourceHandler<ItemResource> private final TransactionalRandomprivate static final Map<ComposterWrapper.WrapperLocation, ComposterWrapper> Wrapper map, similar toVanillaContainerWrapper.wrappers. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate -
Method Summary
Modifier and TypeMethodDescriptionprotected BlockStateReturn a new nonnull object containing the current state of this journal.static @Nullable ResourceHandler<ItemResource> private static floatgetComposterValue(ItemResource resource) protected voidonRootCommit(BlockState originalState) Called after the root transaction was successfully committed, to perform irreversible actions such assetChanged()or neighbor updates.protected voidrevertToSnapshot(BlockState snapshot) Roll back to a state previously created bySnapshotJournal.createSnapshot().private voidsetLevel(BlockState state, int newLevel) Sets the composter's level, without sending notifications, which are deferred untilonRootCommit(net.minecraft.world.level.block.state.BlockState).Methods inherited from class net.neoforged.neoforge.transfer.transaction.SnapshotJournal
releaseSnapshot, updateSnapshots
-
Field Details
-
wrappers
Wrapper map, similar toVanillaContainerWrapper.wrappers. We need the composter wrapper to hold a strong reference to the wrapper location to avoid the weak key being cleared too early, and we need each sub-handler to hold a strong reference to the composter wrapper to avoid the weak value being cleared too early. -
BONE_MEAL
-
location
-
transactionalRandom
-
topHandler
-
bottomHandler
-
-
Constructor Details
-
ComposterWrapper
-
-
Method Details
-
get
@Nullable public static @Nullable ResourceHandler<ItemResource> get(Level level, BlockPos pos, @Nullable @Nullable Direction direction) -
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<BlockState>
-
revertToSnapshot
Description copied from class:SnapshotJournalRoll back to a state previously created bySnapshotJournal.createSnapshot().- Specified by:
revertToSnapshotin classSnapshotJournal<BlockState>
-
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<BlockState>- 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
-
getComposterValue
-
setLevel
Sets the composter's level, without sending notifications, which are deferred untilonRootCommit(net.minecraft.world.level.block.state.BlockState).
-