Class CraftingNetwork

java.lang.Object
org.cyclops.integratedcrafting.core.network.CraftingNetwork
All Implemented Interfaces:
ICraftingNetwork

public class CraftingNetwork extends Object implements ICraftingNetwork
A crafting handler network with multiple channels.
  • Constructor Details

    • CraftingNetwork

      public CraftingNetwork()
  • Method Details

    • newRecipeCraftingInterfacesMap

      protected static com.google.common.collect.Multimap<org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition,ICraftingInterface> newRecipeCraftingInterfacesMap()
    • getChannels

      public int[] getChannels()
      Specified by:
      getChannels in interface ICraftingNetwork
      Returns:
      The channels that have at least one active position.
    • getCraftingInterfaces

      public Set<ICraftingInterface> getCraftingInterfaces(int channel)
      Description copied from interface: ICraftingNetwork
      Get all crafting interfaces for the given channel.
      Specified by:
      getCraftingInterfaces in interface ICraftingNetwork
      Parameters:
      channel - The crafting channel.
      Returns:
      Crafting interfaces.
    • getRecipeCraftingInterfaces

      public com.google.common.collect.Multimap<org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition,ICraftingInterface> getRecipeCraftingInterfaces(int channel)
      Description copied from interface: ICraftingNetwork
      Get the recipe to interface mapping for the given channel.
      Specified by:
      getRecipeCraftingInterfaces in interface ICraftingNetwork
      Parameters:
      channel - The crafting channel.
      Returns:
      The recipe to interface mapping.
    • getRecipeIndex

      public IRecipeIndexModifiable getRecipeIndex(int channel)
      Description copied from interface: ICraftingNetwork
      Get the recipe index on the given channel.
      Specified by:
      getRecipeIndex in interface ICraftingNetwork
      Parameters:
      channel - The crafting channel.
      Returns:
      The index.
    • addCraftingInterface

      public boolean addCraftingInterface(int channel, ICraftingInterface craftingInterface)
      Description copied from interface: ICraftingNetwork
      Add a crafting interface to the network.
      Specified by:
      addCraftingInterface in interface ICraftingNetwork
      Parameters:
      channel - The channel of the interface.
      craftingInterface - A crafting interface.
      Returns:
      If the crafting interface did not exist before in the network.
    • removeCraftingInterface

      public boolean removeCraftingInterface(int channel, ICraftingInterface craftingInterface)
      Description copied from interface: ICraftingNetwork
      Remove a crafting interface from the network.
      Specified by:
      removeCraftingInterface in interface ICraftingNetwork
      Parameters:
      channel - The channel of the interface.
      craftingInterface - A crafting interface.
      Returns:
      If the crafting interface existed.
    • addCraftingInterfaceRecipe

      public boolean addCraftingInterfaceRecipe(int channel, ICraftingInterface craftingInterface, org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition recipe)
      Description copied from interface: ICraftingNetwork
      Add the given recipe that is owned by the given crafting interface. This should only be called for differential changes, otherwise ICraftingNetwork.addCraftingInterface(int, ICraftingInterface) should be called.
      Specified by:
      addCraftingInterfaceRecipe in interface ICraftingNetwork
      Parameters:
      channel - The channel of the interface.
      craftingInterface - A crafting interface.
      recipe - The recipe to add.
      Returns:
      If the recipe was added.
    • removeCraftingInterfaceRecipe

      public boolean removeCraftingInterfaceRecipe(int channel, ICraftingInterface craftingInterface, org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition recipe)
      Description copied from interface: ICraftingNetwork
      Remove the given recipe that is owned by the given crafting interface. This should only be called for differential changes, otherwise ICraftingNetwork.removeCraftingInterface(int, ICraftingInterface) should be called.
      Specified by:
      removeCraftingInterfaceRecipe in interface ICraftingNetwork
      Parameters:
      channel - The channel of the interface.
      craftingInterface - A crafting interface.
      recipe - The recipe to remove.
      Returns:
      If the recipe was removed.
    • scheduleCraftingJob

      public void scheduleCraftingJob(CraftingJob craftingJob, boolean allowDistribution, Function<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage> storageGetter) throws UnavailableCraftingInterfacesException
      Description copied from interface: ICraftingNetwork
      Add the given crafting job to the list of crafting jobs.
      Specified by:
      scheduleCraftingJob in interface ICraftingNetwork
      Parameters:
      craftingJob - The crafting job.
      allowDistribution - If the crafting job is allowed to be split over multiple crafting interfaces.
      storageGetter - The storage getter.
      Throws:
      UnavailableCraftingInterfacesException - If no crafting interfaces were available.
    • getCurrentTick

      protected long getCurrentTick()
    • onCraftingJobFinished

      public void onCraftingJobFinished(CraftingJob craftingJob)
      Description copied from interface: ICraftingNetwork
      Called by crafting interfaces when the crafting job is finished and should be removed from all lists.
      Specified by:
      onCraftingJobFinished in interface ICraftingNetwork
      Parameters:
      craftingJob - The crafting job.
    • cancelCraftingJob

      public boolean cancelCraftingJob(int channel, int craftingJobId)
      Description copied from interface: ICraftingNetwork
      Cancel the given crafting job. This will also cancel all its dependencies.
      Specified by:
      cancelCraftingJob in interface ICraftingNetwork
      Parameters:
      channel - A channel id.
      craftingJobId - The crafting job id.
      Returns:
      If the crafting job existed.
    • cancelCraftingJob

      protected void cancelCraftingJob(CraftingJob craftingJob)
    • getCraftingJobs

      public Iterator<CraftingJob> getCraftingJobs(int channel)
      Specified by:
      getCraftingJobs in interface ICraftingNetwork
      Parameters:
      channel - A channel id.
      Returns:
      Get all present crafting jobs.
    • getCraftingJob

      @Nullable public CraftingJob getCraftingJob(int channel, int craftingJobId)
      Specified by:
      getCraftingJob in interface ICraftingNetwork
      Parameters:
      channel - A channel id.
      craftingJobId - A crafting job id.
      Returns:
      The crafting job with the given id or null.
    • addCraftingJob

      protected void addCraftingJob(int channel, CraftingJob craftingJob, ICraftingInterface craftingInterface)
    • removeCraftingJob

      protected void removeCraftingJob(int channel, CraftingJob craftingJob)
    • getCraftingJobs

      public <T, M> Iterator<CraftingJob> getCraftingJobs(int channel, org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T,M> ingredientComponent, T instance, M matchCondition)
      Description copied from interface: ICraftingNetwork
      Get present crafting jobs for the given (expected) output instance.
      Specified by:
      getCraftingJobs in interface ICraftingNetwork
      Type Parameters:
      T - The instance type.
      M - The matching condition parameter.
      Parameters:
      channel - The channel.
      ingredientComponent - The ingredient component of the given output type.
      instance - The expected output instance.
      matchCondition - The matching condition under which the instance should be matched.
      Returns:
      The applicable crafting jobs, can be empty.
    • getCraftingJobDependencyGraph

      public CraftingJobDependencyGraph getCraftingJobDependencyGraph()
      Specified by:
      getCraftingJobDependencyGraph in interface ICraftingNetwork
      Returns:
      An overview of all crafting job dependencies in this network.
    • getCraftingJobInterface

      @Nullable public ICraftingInterface getCraftingJobInterface(int channel, int craftingJobId)
      Description copied from interface: ICraftingNetwork
      Get the interface in which the given crafting job is being crafted.
      Specified by:
      getCraftingJobInterface in interface ICraftingNetwork
      Parameters:
      channel - The channel.
      craftingJobId - A crafting job.
      Returns:
      The owning crafting interface or null.
    • getRunningTicks

      public long getRunningTicks(CraftingJob craftingJob)
      Description copied from interface: ICraftingNetwork
      Calculate the number of ticks the given job has been running.
      Specified by:
      getRunningTicks in interface ICraftingNetwork
      Parameters:
      craftingJob - A crafting job.
      Returns:
      The number of ticks this job has been running.
    • cleanupChannelIfEmpty

      protected void cleanupChannelIfEmpty(int channel)