Class PositionedAddonsNetworkIngredients<T,M>
java.lang.Object
org.cyclops.integrateddynamics.core.network.PositionedAddonsNetwork
org.cyclops.integrateddynamics.core.network.PositionedAddonsNetworkIngredients<T,M>
- Type Parameters:
T
- The instance type.M
- The matching condition parameter, may be Void. Instances MUST properly implement the equals method.
- All Implemented Interfaces:
IIngredientComponentStorageObservable<T,
,M> IIngredientComponentStorageObservable.IIndexChangeObserver<T,
,M> IFullNetworkListener
,IPositionedAddonsNetwork
,IPositionedAddonsNetworkIngredients<T,
M>
- Direct Known Subclasses:
EnergyNetwork
public abstract class PositionedAddonsNetworkIngredients<T,M>
extends PositionedAddonsNetwork
implements IPositionedAddonsNetworkIngredients<T,M>, IFullNetworkListener, IIngredientComponentStorageObservable.IIndexChangeObserver<T,M>
An ingredient network that can hold prioritized positions.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cyclops.integrateddynamics.api.ingredient.IIngredientComponentStorageObservable
IIngredientComponentStorageObservable.Change, IIngredientComponentStorageObservable.IIndexChangeObserver<T,
M>, IIngredientComponentStorageObservable.StorageChangeEvent<T, M> -
Field Summary
Fields inherited from interface org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork
DEFAULT_CHANNEL, WILDCARD_CHANNEL
-
Constructor Summary
ConstructorDescriptionPositionedAddonsNetworkIngredients
(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T, M> component) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addNetworkElement
(INetworkElement element, boolean networkPreinit) Add a given network element to the network Also checks if it can tick and will handle it accordingly.void
Add an observer for listing to index change events.boolean
addPosition
(PartPos pos, int priority, int channel) Add the given position.void
Called when the server loaded this network.protected void
applyChangesToChannel
(IIngredientComponentStorageObservable.StorageChangeEvent<T, M> event, int channel) void
Called when the server will save this network before stopping.boolean
canUpdate
(INetworkElement element) If the given element can update.getChannel
(int channel) Get the storage at the given channel.<S,
C> S getChannelExternal
(net.neoforged.neoforge.capabilities.BlockCapability<S, C> capability, int channel) Get the external storage at the given channel.getChannelIndex
(int channel) Get the last indexed storage at the given channel.getChannelSlotted
(int channel) Get the slotted storage at the given channel.protected IngredientPositionsIndex
<T, M> getIndexSafe
(int channel) getInstanceLocationsIndex
(int channel) Get the last tick duration of the index observer.Get the storage at the given position.void
invalidateElement
(INetworkElement element) Invalidate the given element.boolean
isObservationForcedPending
(int channel) void
kill()
Terminate the network elements for this network.void
Called when a change event is emitted.protected void
onPositionAdded
(int channel, PrioritizedPartPos pos) protected void
onPositionRemoved
(int channel, PrioritizedPartPos pos) void
onSkipUpdate
(INetworkElement element) When the given element is not being updated becauseIFullNetworkListener.canUpdate(INetworkElement)
returned false.void
postUpdate
(INetworkElement element) Called after a network element's update was called.void
removeNetworkElementPost
(INetworkElement element) Remove a given network element from the network.boolean
removeNetworkElementPre
(INetworkElement element) Checks if the given network element can be removed from the networkvoid
Remove the given index change observer.boolean
removePathElement
(IPathElement pathElement, net.minecraft.core.Direction side) Remove the given path element from the network.void
Reset the last second duration count.void
revalidateElement
(INetworkElement element) Revalidate the given element.void
Manually run observer synchronously (even if async is allowed), if it should observe.void
Indicate that this network should observe starting somewhere in the future.void
scheduleObservationForced
(int channel, PartPos pos) Indicate that this network should observe starting in the next tick.void
Set an ingredient filter for the given storage position.boolean
void
update()
This network updating should be called each tick.void
This guaranteed network updating should be called each tick, even in safe-mode.Methods inherited from class org.cyclops.integrateddynamics.core.network.PositionedAddonsNetwork
disablePosition, enablePosition, getChannels, getPartPosIteratorHandler, getPositionChannel, getPrioritizedPositions, getPrioritizedPositions, hasPositions, invalidateIterators, isPositionDisabled, removePosition, setPartPosIteratorHandler
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork
disablePosition, enablePosition, getChannels, getPartPosIteratorHandler, getPositionChannel, getPositions, getPositions, getPrioritizedPositions, getPrioritizedPositions, hasPositions, isPositionDisabled, removePosition, setPartPosIteratorHandler
Methods inherited from interface org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients
getPositionedStorageUnsafe, getRateLimit, getRawInstances
-
Constructor Details
-
PositionedAddonsNetworkIngredients
-
-
Method Details
-
getComponent
- Specified by:
getComponent
in interfaceIIngredientComponentStorageObservable<T,
M> - Specified by:
getComponent
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Returns:
- The ingredient component type this storage applies to.
-
getPositionedStorage
public org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage<T,M> getPositionedStorage(PartPos pos) Description copied from interface:IPositionedAddonsNetworkIngredients
Get the storage at the given position.- Specified by:
getPositionedStorage
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Parameters:
pos
- A position.- Returns:
- The storage, or an empty storage if none is available.
-
getInstanceLocationsIndex
-
addPosition
Description copied from interface:IPositionedAddonsNetwork
Add the given position.- Specified by:
addPosition
in interfaceIPositionedAddonsNetwork
- Overrides:
addPosition
in classPositionedAddonsNetwork
- Parameters:
pos
- The position.priority
- The priority.channel
- The channel id.- Returns:
- If the position was added, otherwise it was already present.
-
setPositionedStorageFilter
public void setPositionedStorageFilter(PartPos pos, @Nullable PositionedAddonsNetworkIngredientsFilter<T> filter) Description copied from interface:IPositionedAddonsNetworkIngredients
Set an ingredient filter for the given storage position. Unsets the filter if null is provided.- Specified by:
setPositionedStorageFilter
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Parameters:
pos
- A position.filter
- An ingredient filter.
-
getPositionedStorageFilter
@Nullable public PositionedAddonsNetworkIngredientsFilter<T> getPositionedStorageFilter(PartPos pos) - Specified by:
getPositionedStorageFilter
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Parameters:
pos
- A position.- Returns:
- An optional ingredient filter for the given storage position.
-
onChange
Description copied from interface:IIngredientComponentStorageObservable.IIndexChangeObserver
Called when a change event is emitted.- Specified by:
onChange
in interfaceIIngredientComponentStorageObservable.IIndexChangeObserver<T,
M> - Parameters:
event
- A storage change event.
-
applyChangesToChannel
protected void applyChangesToChannel(IIngredientComponentStorageObservable.StorageChangeEvent<T, M> event, int channel) -
getIndexSafe
-
onPositionAdded
- Overrides:
onPositionAdded
in classPositionedAddonsNetwork
-
onPositionRemoved
- Overrides:
onPositionRemoved
in classPositionedAddonsNetwork
-
getChannel
Description copied from interface:IPositionedAddonsNetworkIngredients
Get the storage at the given channel.- Specified by:
getChannel
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Parameters:
channel
- A channel id.- Returns:
- A storage.
-
addObserver
Description copied from interface:IIngredientComponentStorageObservable
Add an observer for listing to index change events.- Specified by:
addObserver
in interfaceIIngredientComponentStorageObservable<T,
M> - Parameters:
observer
- An index change observer.
-
removeObserver
public void removeObserver(IIngredientComponentStorageObservable.IIndexChangeObserver<T, M> observer) Description copied from interface:IIngredientComponentStorageObservable
Remove the given index change observer. This will silently fail if the given observer was not registered.- Specified by:
removeObserver
in interfaceIIngredientComponentStorageObservable<T,
M> - Parameters:
observer
- An index change observer.
-
scheduleObservation
public void scheduleObservation()Description copied from interface:IIngredientComponentStorageObservable
Indicate that this network should observe starting somewhere in the future. This should be called when observer diffs are needed, but are not urgent. This is a more efficient variant ofIIngredientComponentStorageObservable.scheduleObservationForced(int, PartPos)
. This should be called each time that observations are needed, as this observable will reset the internal flag after each observation.- Specified by:
scheduleObservation
in interfaceIIngredientComponentStorageObservable<T,
M>
-
scheduleObservationForced
Description copied from interface:IIngredientComponentStorageObservable
Indicate that this network should observe starting in the next tick. This is a stricter variant ofIIngredientComponentStorageObservable.scheduleObservation()
, and can only be done for a single position and channel. This should be called when observer diffs are needed in the next tick for the given position.- Specified by:
scheduleObservationForced
in interfaceIIngredientComponentStorageObservable<T,
M> - Parameters:
channel
- The channel to force an observation in.pos
- The position to force an observation for.
-
shouldObserve
public boolean shouldObserve()- Specified by:
shouldObserve
in interfaceIIngredientComponentStorageObservable<T,
M> - Returns:
- If an observation should happen.
-
isObservationForcedPending
public boolean isObservationForcedPending(int channel) - Specified by:
isObservationForcedPending
in interfaceIIngredientComponentStorageObservable<T,
M> - Parameters:
channel
- The channel to check for a forced observation in.- Returns:
- If the given channel contains a forced observation scheduling that has not been processed yet.
-
runObserverSync
public void runObserverSync()Description copied from interface:IIngredientComponentStorageObservable
Manually run observer synchronously (even if async is allowed), if it should observe.- Specified by:
runObserverSync
in interfaceIIngredientComponentStorageObservable<T,
M>
-
getChannelIndex
Description copied from interface:IIngredientComponentStorageObservable
Get the last indexed storage at the given channel.- Specified by:
getChannelIndex
in interfaceIIngredientComponentStorageObservable<T,
M> - Parameters:
channel
- A channel id.- Returns:
- A channel index.
-
getChannelSlotted
public org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted<T,M> getChannelSlotted(int channel) Description copied from interface:IPositionedAddonsNetworkIngredients
Get the slotted storage at the given channel.- Specified by:
getChannelSlotted
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Parameters:
channel
- A channel id.- Returns:
- A slotted storage.
-
getChannelExternal
@Nullable public <S,C> S getChannelExternal(net.neoforged.neoforge.capabilities.BlockCapability<S, C> capability, int channel) Description copied from interface:IPositionedAddonsNetworkIngredients
Get the external storage at the given channel.- Specified by:
getChannelExternal
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Type Parameters:
S
- The external storage type.- Parameters:
capability
- A capability to wrap the channel in.channel
- A channel id.- Returns:
- An external storage, or null if no wrapping is possible for the given capability.
-
addNetworkElement
Description copied from interface:IFullNetworkListener
Add a given network element to the network Also checks if it can tick and will handle it accordingly.- Specified by:
addNetworkElement
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.networkPreinit
- If the network is still in the process of being initialized.- Returns:
- If the addition succeeded.
-
removeNetworkElementPre
Description copied from interface:IFullNetworkListener
Checks if the given network element can be removed from the network- Specified by:
removeNetworkElementPre
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.- Returns:
- If the element was can be removed from the network.
-
removeNetworkElementPost
Description copied from interface:IFullNetworkListener
Remove a given network element from the network. Also removed its tickable instance.- Specified by:
removeNetworkElementPost
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.
-
kill
public void kill()Description copied from interface:IFullNetworkListener
Terminate the network elements for this network.- Specified by:
kill
in interfaceIFullNetworkListener
-
updateGuaranteed
public void updateGuaranteed()Description copied from interface:IFullNetworkListener
This guaranteed network updating should be called each tick, even in safe-mode.- Specified by:
updateGuaranteed
in interfaceIFullNetworkListener
-
update
public void update()Description copied from interface:IFullNetworkListener
This network updating should be called each tick.- Specified by:
update
in interfaceIFullNetworkListener
-
removePathElement
Description copied from interface:IFullNetworkListener
Remove the given path element from the network. If the path element had any network elements registered in the network, these will be killed and removed as well.- Specified by:
removePathElement
in interfaceIFullNetworkListener
- Parameters:
pathElement
- The path element.side
- The side.- Returns:
- If the path element was removed.
-
afterServerLoad
public void afterServerLoad()Description copied from interface:IFullNetworkListener
Called when the server loaded this network. This is the time to notify all network elements of this network.- Specified by:
afterServerLoad
in interfaceIFullNetworkListener
-
beforeServerStop
public void beforeServerStop()Description copied from interface:IFullNetworkListener
Called when the server will save this network before stopping. This is the time to notify all network elements of this network.- Specified by:
beforeServerStop
in interfaceIFullNetworkListener
-
canUpdate
Description copied from interface:IFullNetworkListener
If the given element can update.- Specified by:
canUpdate
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.- Returns:
- If it can update.
-
onSkipUpdate
Description copied from interface:IFullNetworkListener
When the given element is not being updated becauseIFullNetworkListener.canUpdate(INetworkElement)
returned false.- Specified by:
onSkipUpdate
in interfaceIFullNetworkListener
- Parameters:
element
- The element that is not being updated.
-
postUpdate
Description copied from interface:IFullNetworkListener
Called after a network element's update was called.- Specified by:
postUpdate
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.
-
getLastSecondDurationIndex
Description copied from interface:IPositionedAddonsNetworkIngredients
Get the last tick duration of the index observer.- Specified by:
getLastSecondDurationIndex
in interfaceIPositionedAddonsNetworkIngredients<T,
M> - Returns:
- Duration in nanoseconds
-
resetLastSecondDurationsIndex
public void resetLastSecondDurationsIndex()Description copied from interface:IPositionedAddonsNetworkIngredients
Reset the last second duration count.- Specified by:
resetLastSecondDurationsIndex
in interfaceIPositionedAddonsNetworkIngredients<T,
M>
-
invalidateElement
Description copied from interface:IFullNetworkListener
Invalidate the given element. Called when the element's chunk is being unloaded.- Specified by:
invalidateElement
in interfaceIFullNetworkListener
- Parameters:
element
- The network element to invalidate.
-
revalidateElement
Description copied from interface:IFullNetworkListener
Revalidate the given element. Called when the element's chunk is being reloaded.- Specified by:
revalidateElement
in interfaceIFullNetworkListener
- Parameters:
element
- The network element to invalidate.
-