Class IngredientComponent<T,M>
java.lang.Object
org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<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:
Comparable<IngredientComponent<?,
?>>
public final class IngredientComponent<T,M>
extends Object
implements Comparable<IngredientComponent<?,?>>
A IngredientComponent is a type of component that can be used as ingredients inside recipes.
-
Field Summary
Modifier and TypeFieldDescriptionstatic IngredientComponent
<Long, Boolean> static IngredientComponent
<net.neoforged.neoforge.fluids.FluidStack, Integer> static IngredientComponent
<net.minecraft.world.item.ItemStack, Integer> static net.minecraft.core.Registry
<IngredientComponent<?, ?>> -
Constructor Summary
ConstructorDescriptionIngredientComponent
(String name, IIngredientMatcher<T, M> matcher, IIngredientSerializer<T, M> serializer, List<IngredientComponentCategoryType<T, M, ?>> categoryTypes) IngredientComponent
(net.minecraft.resources.ResourceLocation name, IIngredientMatcher<T, M> matcher, IIngredientSerializer<T, M> serializer, List<IngredientComponentCategoryType<T, M, ?>> categoryTypes) -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(IngredientComponent<?, ?> that) void
gatherCapabilities
(net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent registerCapabilitiesEvent) <O,
C> IIngredientComponentStorage <T, M> getBlockStorage
(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.entity.BlockEntity blockEntity, C context) <TC> Optional
<TC> getCapability
(IngredientComponentCapability<TC, Void> capability) Get the given capability.<O,
C> IIngredientComponentStorage <T, M> getEntityStorage
(net.minecraft.world.entity.Entity entity, C context) static IngredientComponent
<?, ?> getIngredientComponentForStorageCapability
(net.neoforged.neoforge.capabilities.BaseCapability<?, ?> capability) Get the ingredient component that was attached to the given storage capability.<O,
C> IIngredientComponentStorage <T, M> getItemStorage
(net.minecraft.world.item.ItemStack itemStack, C context) net.minecraft.resources.ResourceLocation
getName()
<O,
C> IIngredientComponentStorage <T, M> getStorage
(Class<O> capabilityType, ICapabilityGetter<C> capabilityGetter, C context) Get the ingredient storage within the given capability provider.<S,
C> IIngredientComponentStorageWrapperHandler <T, M, S, C> getStorageWrapperHandler
(net.neoforged.neoforge.capabilities.BaseCapability<S, ?> capability) Get the storage wrapper handler for this component.Collection
<net.neoforged.neoforge.capabilities.BaseCapability<?, ?>> static void
onRegistriesCreate
(net.neoforged.neoforge.registries.NewRegistryEvent event) static void
onRegistriesFilled
(net.neoforged.neoforge.registries.RegisterEvent event) <S> void
setStorageWrapperHandler
(net.neoforged.neoforge.capabilities.BaseCapability<?, ?> capability, IIngredientComponentStorageWrapperHandler<T, M, ? super S, ?> storageWrapperHandler) Set the storage wrapper handler for this component.setTranslationKey
(String translationKey) toString()
Wrap the given instance inside an equals, hashCode and compareTo-safe holder.
-
Field Details
-
REGISTRY
-
ITEMSTACK
-
FLUIDSTACK
-
ENERGY
-
-
Constructor Details
-
IngredientComponent
public IngredientComponent(net.minecraft.resources.ResourceLocation name, IIngredientMatcher<T, M> matcher, IIngredientSerializer<T, M> serializer, List<IngredientComponentCategoryType<T, M, ?>> categoryTypes) -
IngredientComponent
public IngredientComponent(String name, IIngredientMatcher<T, M> matcher, IIngredientSerializer<T, M> serializer, List<IngredientComponentCategoryType<T, M, ?>> categoryTypes)
-
-
Method Details
-
onRegistriesCreate
public static void onRegistriesCreate(net.neoforged.neoforge.registries.NewRegistryEvent event) -
onRegistriesFilled
public static void onRegistriesFilled(net.neoforged.neoforge.registries.RegisterEvent event) -
getName
public net.minecraft.resources.ResourceLocation getName() -
toString
-
gatherCapabilities
public void gatherCapabilities(net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent registerCapabilitiesEvent) -
getCapability
Get the given capability.- Type Parameters:
TC
- The capability type.- Parameters:
capability
- The capability to get.- Returns:
- The lazy optional capability instance.
-
setTranslationKey
-
getTranslationKey
- Returns:
- The unlocalized name.
-
getMatcher
- Returns:
- A matcher instance for comparing instances of this component type.
-
getSerializer
- Returns:
- A (de)serializer instance for this component type.
-
getCategoryTypes
- Returns:
- The category types of this component.
-
wrap
Wrap the given instance inside an equals, hashCode and compareTo-safe holder.- Parameters:
instance
- An instance.- Returns:
- The wrapped instance.
-
getPrimaryQuantifier
- Returns:
- The primary quantifier category type, can be null.
-
setStorageWrapperHandler
public <S> void setStorageWrapperHandler(net.neoforged.neoforge.capabilities.BaseCapability<?, ?> capability, IIngredientComponentStorageWrapperHandler<T, M, ? super S, ?> storageWrapperHandler) Set the storage wrapper handler for this component.- Type Parameters:
S
- The capability type.- Parameters:
capability
- The capability for the storage wrapper.storageWrapperHandler
- The storage wrapper handler.
-
getStorageWrapperHandler
@Nullable public <S,C> IIngredientComponentStorageWrapperHandler<T,M, getStorageWrapperHandlerS, C> (net.neoforged.neoforge.capabilities.BaseCapability<S, ?> capability) Get the storage wrapper handler for this component.- Type Parameters:
S
- The external storage type.- Parameters:
capability
- The capability to get the storage wrapper for.- Returns:
- The storage wrapper handler, can be null if none has been assigned.
-
getStorageWrapperHandlerCapabilities
public Collection<net.neoforged.neoforge.capabilities.BaseCapability<?,?>> getStorageWrapperHandlerCapabilities()- Returns:
- All supported capabilities that have registered wrapper handlers
-
getIngredientComponentForStorageCapability
@Nullable public static IngredientComponent<?,?> getIngredientComponentForStorageCapability(net.neoforged.neoforge.capabilities.BaseCapability<?, ?> capability) Get the ingredient component that was attached to the given storage capability.- Parameters:
capability
- A storage capability.- Returns:
- The attached ingredient component, or null.
-
getStorage
@Nullable public <O,C> IIngredientComponentStorage<T,M> getStorage(Class<O> capabilityType, ICapabilityGetter<C> capabilityGetter, C context) Get the ingredient storage within the given capability provider. This will first check if the capability provider has aIIngredientComponentStorageHandler
capability and it will try to fetch the storage from there. If this fails, then the storage wrapper handlers that are registered in this ingredient component will be iterated and the first successful one will be returned.- Parameters:
capabilityType
- capabilityType The type of capability, usually Block.class, Item.class, or Entity.class.capabilityGetter
- A capability provider.context
- The context to get the storage from.- Returns:
- An ingredient storage, or null if it does not exist.
-
getBlockStorage
@Nullable public <O,C> IIngredientComponentStorage<T,M> getBlockStorage(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, C context) -
getEntityStorage
@Nullable public <O,C> IIngredientComponentStorage<T,M> getEntityStorage(net.minecraft.world.entity.Entity entity, C context) -
getItemStorage
@Nullable public <O,C> IIngredientComponentStorage<T,M> getItemStorage(net.minecraft.world.item.ItemStack itemStack, C context) -
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-