Class CauldronWrapper
- All Implemented Interfaces:
ResourceHandler<FluidResource>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final recordTo make sure multiple accesses to the same cauldron return the same wrapper, we maintain a(Level, BlockPos) -> Wrappercache. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CauldronWrapper.WrapperLocationprivate static final Map<CauldronWrapper.WrapperLocation, CauldronWrapper> Wrapper map, similar toVanillaContainerWrapper.wrappers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BlockStateReturn a new nonnull object containing the current state of this journal.intextract(int index, FluidResource resource, int amount, TransactionContext transaction) Extracts up to the given amount of a resource from the handler at the given index.static CauldronWrapperlonggetAmountAsLong(int index) Returns the amount of the currently stored resource at the given index, as along.longgetCapacityAsLong(int index, FluidResource resource) Returns the capacity of the handler at the given index and for the given resource, irrespective of the current amount or resource currently at that index, as along.private CauldronFluidContentgetContent(BlockState state) getResource(int index) Returns the resource at the given index, which may be empty.intinsert(int index, FluidResource resource, int amount, TransactionContext transaction) Inserts up to the given amount of a resource into the handler at the given index.booleanisValid(int index, FluidResource resource) Returns whether the given resource is generally allowed to be contained at the given index, irrespective of the current amount or resource currently at that index.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(CauldronFluidContent newContent, int fluidLevel, TransactionContext transaction) Temporarily updates the block state in the level in a transactional way.intsize()Returns the current number of indices in this resource handler.Methods inherited from class net.neoforged.neoforge.transfer.transaction.SnapshotJournal
releaseSnapshot, updateSnapshotsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.transfer.ResourceHandler
extract, getAmountAsInt, getCapacityAsInt, insert
-
Field Details
-
wrappers
Wrapper map, similar toVanillaContainerWrapper.wrappers. We need the cauldron wrapper to hold a strong reference to the wrapper location to avoid the weak keys being cleared too early. -
location
-
-
Constructor Details
-
CauldronWrapper
-
-
Method Details
-
get
-
getContent
-
size
public int size()Description copied from interface:ResourceHandlerReturns the current number of indices in this resource handler.This size provides a bound on the valid indices for this handler, see the documentation of
ResourceHandler.- Specified by:
sizein interfaceResourceHandler<FluidResource>- Returns:
- The size of the resource handler. Can be
0if the handler currently has no indices.
-
getResource
Description copied from interface:ResourceHandlerReturns the resource at the given index, which may be empty.If the resource is empty, the stored amount must be 0.
- Specified by:
getResourcein interfaceResourceHandler<FluidResource>- Parameters:
index- The index to get the resource from.- Returns:
- the resource at the given index, which may be empty
-
getAmountAsLong
public long getAmountAsLong(int index) Description copied from interface:ResourceHandlerReturns the amount of the currently stored resource at the given index, as along.In general, resource handlers can report
longamounts. However, if the handler is known to only support amounts up toInteger.MAX_VALUE, or if the caller prefers to deal inints only, the int-returning overload can be used instead.The returned amount must be non-negative. If the stored resource is empty, the amount must be 0.
- Specified by:
getAmountAsLongin interfaceResourceHandler<FluidResource>- Parameters:
index- The index to get the amount from.- Returns:
- the amount at the given index, as a long
- See Also:
-
getCapacityAsLong
Description copied from interface:ResourceHandlerReturns the capacity of the handler at the given index and for the given resource, irrespective of the current amount or resource currently at that index, as along.In general, resource handlers can report
longcapacities. However, if the handler is known to only support capacities up toInteger.MAX_VALUE, or if the caller prefers to deal inints only, the int-returning overload can be used instead.This function serves as a hint on the maximum amount the resource handler might contain, for example the handler can be considered full if
amount >= capacity. Note that the returned capacity may overestimate the actual allowed amount, and it might be smaller than the current amount. The only way to know if a handler will accept a resource, is to try toinsertit.- Specified by:
getCapacityAsLongin interfaceResourceHandler<FluidResource>- Parameters:
index- The index to get the capacity for.resource- The resource to get the capacity for. May be empty to get the general capacity at the index.- Returns:
- the capacity at the given index, as a long
- See Also:
-
isValid
Description copied from interface:ResourceHandlerReturns whether the given resource is generally allowed to be contained at the given index, irrespective of the current amount or resource currently at that index.This function serves as a hint on whether the resource handler can contain the resource or not. The only way to know if a handler will accept a resource, is to try to
insertit.- Specified by:
isValidin interfaceResourceHandler<FluidResource>- Parameters:
index- The index to check.resource- The resource to check. Must be non-empty.- Returns:
- whether the given resource is generally allowed to be contained at the given index, irrespective of the current amount or resource currently at that index
-
setLevel
private void setLevel(CauldronFluidContent newContent, int fluidLevel, TransactionContext transaction) Temporarily updates the block state in the level in a transactional way. SeeonRootCommit(net.minecraft.world.level.block.state.BlockState)for the final modification. -
insert
Description copied from interface:ResourceHandlerInserts up to the given amount of a resource into the handler at the given index.Changes to the handler are made in the context of a transaction.
- Specified by:
insertin interfaceResourceHandler<FluidResource>- Parameters:
index- The index to insert the resource into.resource- The resource to insert. Must be non-empty.amount- The maximum amount of the resource to insert. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was inserted. Between
0(inclusive, nothing was inserted) andamount(inclusive, everything was inserted). - See Also:
-
extract
Description copied from interface:ResourceHandlerExtracts up to the given amount of a resource from the handler at the given index.Changes to the handler are made in the context of a transaction.
- Specified by:
extractin interfaceResourceHandler<FluidResource>- Parameters:
index- The index to extract the resource from.resource- The resource to extract. Must be non-empty.amount- The maximum amount of the resource to extract. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was extracted. Between
0(inclusive, nothing was extracted) andamount(inclusive, everything was extracted). - See Also:
-
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
-