Class IngredientStorageHelpers
java.lang.Object
org.cyclops.cyclopscore.ingredient.storage.IngredientStorageHelpers
Helper methods for moving ingredients between
IIngredientComponentStorage
's.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Helper interface for constructing anIIngredientCollection
based on anIngredientComponent
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic IIngredientComponentStorage
<?, ?> deserialize
(net.minecraft.core.HolderLookup.Provider lookupProvider, net.minecraft.nbt.CompoundTag tag, long rateLimit) Deserialize the storage from the given NBT tag.static <T,
M> T handleRemainder
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, T movedEffective, T remainingEffective) static <T,
M> T insertIngredient
(IIngredientComponentStorage<T, M> destination, T instance, boolean simulate) Insert an ingredient in a destination storage.static <T,
M> long insertIngredientQuantity
(IIngredientComponentStorage<T, M> destination, T instance, boolean simulate) Insert an ingredient in a destination storage.static <T,
M> T insertIngredientRemainderFixup
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, T instance, boolean simulate) Insert an ingredient in a destination storage.protected static <T,
M> T moveEffectiveSourceExactDestinationExact
(IIngredientComponentStorageSlotted<T, M> sourceSlotted, int sourceSlot, IIngredientComponentStorageSlotted<T, M> destinationSlotted, int destinationSlot, T extractedSimulated, T remaining, boolean simulate) protected static <T,
M> T moveEffectiveSourceExactDestinationNonSlotted
(IIngredientComponentStorageSlotted<T, M> sourceSlotted, int sourceSlot, IIngredientComponentStorage<T, M> destination, T inserted, boolean simulate) protected static <T,
M> T moveEffectiveSourceNonSlottedDestinationExact
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorageSlotted<T, M> destinationSlotted, int destinationSlot, M extractMatchCondition, T extractedSimulated, T remaining, boolean simulate) static <T,
M> T moveIngredient
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, T instance, M matchCondition, boolean simulate) Move the first instance that matches the given match condition from source to destination.static <T,
M> T moveIngredients
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, long maxQuantity, boolean simulate) Move the given maximum quantity of instances from source to destination.static <T,
M> T moveIngredients
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, Predicate<T> predicate, long maxQuantity, boolean exactQuantity, boolean simulate) Move the first instance that matches the given predicate from source to destination.static <T,
M> T moveIngredients
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, T instance, M matchCondition, boolean simulate) Move the first instance that matches the given match condition from source to destination.static <T,
M> T moveIngredientsIterative
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, long maxQuantity, boolean simulate) Iteratively move the given maximum quantity of instances from source to destination.static <T,
M> T moveIngredientsIterative
(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, M> destination, T instance, M matchCondition, boolean simulate) Iteratively move the instance that matches the given match condition from source to destination.static <T,
M> T moveIngredientsSlotted
(IIngredientComponentStorage<T, M> source, int sourceSlot, IIngredientComponentStorage<T, M> destination, int destinationSlot, Predicate<T> predicate, long maxQuantity, boolean exactQuantity, boolean simulate) Move ingredients from source to target with optional source and target slots, based on an ingredient predicate.static <T,
M> T moveIngredientsSlotted
(IIngredientComponentStorage<T, M> source, int sourceSlot, IIngredientComponentStorage<T, M> destination, int destinationSlot, T instance, M matchCondition, boolean simulate) Move ingredients from source to target with optional source and target slots, based on an ingredient prototype and match condition.static <T,
M> net.minecraft.nbt.CompoundTag serialize
(net.minecraft.core.HolderLookup.Provider lookupProvider, IIngredientComponentStorage<T, M> storage) Serialize the given storage to NBT.static <T,
M> IIngredientComponentStorage <T, M> wrapStorage
(IIngredientComponentStorage<T, M> ingredientComponentStorage, boolean read, boolean insert, boolean extract) Wrap the given ingredient storage, where you can configure if the storage is allowed to be read, inserted to, or extracted from.
-
Constructor Details
-
IngredientStorageHelpers
public IngredientStorageHelpers()
-
-
Method Details
-
moveIngredientsIterative
public static <T,M> T moveIngredientsIterative(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, long maxQuantity, boolean simulate) Iteratively move the given maximum quantity of instances from source to destination. This is useful in cases that the internal transfer rate of certain storages have to be overridden. Note: When simulating, only a single iteration will be done. This is because the iterations don't actually take effect, which could cause infinite loops.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.maxQuantity
- The maximum instance quantity to move.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredients
public static <T,M> T moveIngredients(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, long maxQuantity, boolean simulate) Move the given maximum quantity of instances from source to destination.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.maxQuantity
- The maximum instance quantity to move.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredientsIterative
public static <T,M> T moveIngredientsIterative(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T instance, M matchCondition, boolean simulate) Iteratively move the instance that matches the given match condition from source to destination. The quantity of the given instance indicates the maximum amount that can be moved. This is useful in cases that the internal transfer rate of certain storages have to be overridden. Note: When simulating, only a single iteration will be done. This is because the iterations don't actually take effect, which could cause infinite loops.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.instance
- The prototype instance.matchCondition
- The match condition.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredients
public static <T,M> T moveIngredients(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T instance, M matchCondition, boolean simulate) Move the first instance that matches the given match condition from source to destination.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.instance
- The prototype instance.matchCondition
- The match condition.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredients
public static <T,M> T moveIngredients(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, Predicate<T> predicate, long maxQuantity, boolean exactQuantity, boolean simulate) Move the first instance that matches the given predicate from source to destination.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.predicate
- The predicate to match instances by.maxQuantity
- The max quantity that can be moved.exactQuantity
- If the max quantity should be interpreted as an exact quantity.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredientsSlotted
public static <T,M> T moveIngredientsSlotted(IIngredientComponentStorage<T, M> source, int sourceSlot, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, int destinationSlot, T instance, M matchCondition, boolean simulate) Move ingredients from source to target with optional source and target slots, based on an ingredient prototype and match condition. If the algorithm should iterate over all source/destination slot, then the respective slot should be -1. If a slot is defined, and the storage is not an instance ofIIngredientComponentStorageSlotted
, then nothing will be moved.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.sourceSlot
- The source slot or -1 for any.destination
- A destination storage to insert to.destinationSlot
- The destination slot or -1 for any.instance
- The prototype instance.matchCondition
- The match condition.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveIngredientsSlotted
public static <T,M> T moveIngredientsSlotted(IIngredientComponentStorage<T, M> source, int sourceSlot, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, int destinationSlot, Predicate<T> predicate, long maxQuantity, boolean exactQuantity, boolean simulate) Move ingredients from source to target with optional source and target slots, based on an ingredient predicate. If the algorithm should iterate over all source/destination slot, then the respective slot should be -1. If a slot is defined, and the storage is not an instance ofIIngredientComponentStorageSlotted
, then nothing will be moved.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.sourceSlot
- The source slot or -1 for any.destination
- A destination storage to insert to.destinationSlot
- The destination slot or -1 for any.predicate
- The instance predicate.maxQuantity
- The max quantity that can be moved.exactQuantity
- If the max quantity should be interpreted as an exact quantity.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
moveEffectiveSourceExactDestinationExact
protected static <T,M> T moveEffectiveSourceExactDestinationExact(IIngredientComponentStorageSlotted<T, M> sourceSlotted, int sourceSlot, IIngredientComponentStorageSlotted<T, throws InconsistentIngredientInsertionExceptionM> destinationSlotted, int destinationSlot, T extractedSimulated, T remaining, boolean simulate) -
moveEffectiveSourceExactDestinationNonSlotted
protected static <T,M> T moveEffectiveSourceExactDestinationNonSlotted(IIngredientComponentStorageSlotted<T, M> sourceSlotted, int sourceSlot, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T inserted, boolean simulate) -
moveEffectiveSourceNonSlottedDestinationExact
@Nullable protected static <T,M> T moveEffectiveSourceNonSlottedDestinationExact(IIngredientComponentStorage<T, M> source, IIngredientComponentStorageSlotted<T, throws InconsistentIngredientInsertionExceptionM> destinationSlotted, int destinationSlot, M extractMatchCondition, T extractedSimulated, T remaining, boolean simulate) -
handleRemainder
public static <T,M> T handleRemainder(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T movedEffective, T remainingEffective) -
moveIngredient
public static <T,M> T moveIngredient(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T instance, M matchCondition, boolean simulate) Move the first instance that matches the given match condition from source to destination. The main difference of this method tomoveIngredients(IIngredientComponentStorage, IIngredientComponentStorage, Object, Object, boolean)
is that the latter method will try checking *multiple* ingredients from the source, while this method will only check the *first matching* ingredient. This makes this method potentially more efficient than the latter.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to extract from.destination
- A destination storage to insert to.instance
- The prototype instance.matchCondition
- The match condition.simulate
- If the movement should be simulated.- Returns:
- The moved ingredient.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
insertIngredientQuantity
public static <T,M> long insertIngredientQuantity(IIngredientComponentStorage<T, M> destination, T instance, boolean simulate) Insert an ingredient in a destination storage. The difference of this method compared toIIngredientComponentStorage.insert(Object, boolean)
is that this method returns the actually inserted ingredient quantity instead of the remaining ingredient that was not inserted.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
destination
- A storage.instance
- An instance to insert.simulate
- If the insertion should be simulated.- Returns:
- The actual inserted ingredient quantity, or would-be inserted ingredient quantity if simulated.
-
insertIngredient
public static <T,M> T insertIngredient(IIngredientComponentStorage<T, M> destination, T instance, boolean simulate) Insert an ingredient in a destination storage. The difference of this method compared toIIngredientComponentStorage.insert(Object, boolean)
is that this method returns the actually inserted ingredient instead of the remaining ingredient that was not inserted.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
destination
- A storage.instance
- An instance to insert.simulate
- If the insertion should be simulated.- Returns:
- The actual inserted ingredient, or would-be inserted ingredient if simulated.
-
insertIngredientRemainderFixup
public static <T,M> T insertIngredientRemainderFixup(IIngredientComponentStorage<T, M> source, IIngredientComponentStorage<T, throws InconsistentIngredientInsertionExceptionM> destination, T instance, boolean simulate) Insert an ingredient in a destination storage. If not in simulation mode, and the instance does not completely fit into the destination, the remainder will be inserted into the source. If not everything can be re-inserted into the source, a warning will be emitted. The difference of this method compared toIIngredientComponentStorage.insert(Object, boolean)
is that this method returns the actually inserted ingredient instead of the remaining ingredient that was not inserted.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
source
- A source storage to insert fixup instances.destination
- A storage.instance
- An instance to insert.simulate
- If the insertion should be simulated.- Returns:
- The actual inserted ingredient, or would-be inserted ingredient if simulated.
- Throws:
InconsistentIngredientInsertionException
- When ingredients are lost due to inconsistent simulation.
-
wrapStorage
public static <T,M> IIngredientComponentStorage<T,M> wrapStorage(IIngredientComponentStorage<T, M> ingredientComponentStorage, boolean read, boolean insert, boolean extract) Wrap the given ingredient storage, where you can configure if the storage is allowed to be read, inserted to, or extracted from. This will distinguish between slotted and slotless storages.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
ingredientComponentStorage
- The storage to wrap.read
- If the storage can be read.insert
- If the storage can be inserted to.extract
- If the storage can be extracted from.- Returns:
- The wrapped storage.
-
serialize
public static <T,M> net.minecraft.nbt.CompoundTag serialize(net.minecraft.core.HolderLookup.Provider lookupProvider, IIngredientComponentStorage<T, M> storage) Serialize the given storage to NBT.All ingredients, the max quantity, and whether or not it is slotted will be stored.
- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
lookupProvider
- The holder lookup provider.storage
- An ingredient storage.- Returns:
- An NBT tag.
-
deserialize
public static IIngredientComponentStorage<?,?> deserialize(net.minecraft.core.HolderLookup.Provider lookupProvider, net.minecraft.nbt.CompoundTag tag, long rateLimit) Deserialize the storage from the given NBT tag.All ingredients, the max quantity, and whether or not it is slotted will be restored.
- Parameters:
lookupProvider
- The holder lookup provider.tag
- An NBT tag.rateLimit
- The rate limit per insertion/extraction.- Returns:
- The deserialized storage.
- Throws:
IllegalArgumentException
- If the tag was invalid.
-