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 Details

  • Constructor Details

  • 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

      public String toString()
      Overrides:
      toString in class Object
    • gatherCapabilities

      public void gatherCapabilities(net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent registerCapabilitiesEvent)
    • getCapability

      public <TC> Optional<TC> getCapability(IngredientComponentCapability<TC,Void> capability)
      Get the given capability.
      Type Parameters:
      TC - The capability type.
      Parameters:
      capability - The capability to get.
      Returns:
      The lazy optional capability instance.
    • setTranslationKey

      public IngredientComponent<T,M> setTranslationKey(String translationKey)
    • getTranslationKey

      public String getTranslationKey()
      Returns:
      The unlocalized name.
    • getMatcher

      public IIngredientMatcher<T,M> getMatcher()
      Returns:
      A matcher instance for comparing instances of this component type.
    • getSerializer

      public IIngredientSerializer<T,M> getSerializer()
      Returns:
      A (de)serializer instance for this component type.
    • getCategoryTypes

      public List<IngredientComponentCategoryType<T,M,?>> getCategoryTypes()
      Returns:
      The category types of this component.
    • wrap

      public IngredientInstanceWrapper<T,M> wrap(T instance)
      Wrap the given instance inside an equals, hashCode and compareTo-safe holder.
      Parameters:
      instance - An instance.
      Returns:
      The wrapped instance.
    • getPrimaryQuantifier

      @Nullable public IngredientComponentCategoryType<T,M,?> 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,S,C> getStorageWrapperHandler(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 a IIngredientComponentStorageHandler 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

      public int compareTo(IngredientComponent<?,?> that)
      Specified by:
      compareTo in interface Comparable<T>