Class CraftingJobHandler

java.lang.Object
org.cyclops.integratedcrafting.core.CraftingJobHandler

public class CraftingJobHandler extends Object
A CraftingJobHandler maintains a list of processing and pending crafting job. Each time that update(INetwork, int, PartPos) is called, the handler will observe the target position for changes in the processing job. Also, it will try initiating pending jobs into the target if none was running. If blockingJobsMode is true, then a multi-amount job will only be crafted one-by-one. If false, then as much as possible of that job will be crafted at once.
  • Constructor Details

  • Method Details

    • writeToNBT

      public void writeToNBT(net.minecraft.nbt.CompoundTag tag)
    • readFromNBT

      public void readFromNBT(net.minecraft.nbt.CompoundTag tag)
    • setBlockingJobsMode

      public boolean setBlockingJobsMode(boolean blockingJobsMode)
    • isBlockingJobsMode

      public boolean isBlockingJobsMode()
    • canScheduleCraftingJobs

      public boolean canScheduleCraftingJobs()
    • scheduleCraftingJob

      public void scheduleCraftingJob(CraftingJob craftingJob)
    • fillCraftingJobBufferFromStorage

      public void fillCraftingJobBufferFromStorage(CraftingJob craftingJob, Function<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage> storageGetter)
    • getProcessingCraftingJobsPendingIngredients

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<Map<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,List<org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient<?,?>>>>> getProcessingCraftingJobsPendingIngredients()
    • getProcessingCraftingJobsRaw

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<CraftingJob> getProcessingCraftingJobsRaw()
    • getProcessingCraftingJobs

      public Collection<CraftingJob> getProcessingCraftingJobs()
    • getPendingCraftingJobs

      public Collection<CraftingJob> getPendingCraftingJobs()
    • unmarkCraftingJobProcessing

      public void unmarkCraftingJobProcessing(CraftingJob craftingJob)
    • removeCraftingJobProcessingPendingIngredientsEntry

      protected boolean removeCraftingJobProcessingPendingIngredientsEntry(CraftingJob craftingJob, Map<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,List<org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient<?,?>>> pendingIngredients)
      Undo a single crafting operation that was added via addCraftingJobProcessingPendingIngredientsEntry(org.cyclops.integratedcrafting.api.crafting.CraftingJob, java.util.Map<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?, ?>, java.util.List<org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient<?, ?>>>). Other operations of the same job, which may still be running in non-blocking mode, are kept. If no operations remain, the job is moved back to the pending jobs.
      Parameters:
      craftingJob - The crafting job.
      pendingIngredients - The exact pending ingredients entry that was added for the operation.
      Returns:
      If the operation was still running.
    • addCraftingJobProcessingPendingIngredientsEntry

      public void addCraftingJobProcessingPendingIngredientsEntry(CraftingJob craftingJob, Map<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,List<org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient<?,?>>> pendingIngredients)
    • getObserversPendingDeletion

      public List<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>> getObserversPendingDeletion()
    • registerIngredientObserver

      protected <T, M> void registerIngredientObserver(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T,M> ingredientComponent, org.cyclops.integrateddynamics.api.network.INetwork network)
    • unregisterIngredientObserver

      protected <T, M> void unregisterIngredientObserver(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T,M> ingredientComponent, org.cyclops.integrateddynamics.api.network.INetwork network)
    • createIngredientObserver

      protected <T, M> void createIngredientObserver(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T,M> ingredientComponent, org.cyclops.integrateddynamics.api.network.INetwork network)
    • removeIngredientObserver

      protected <T, M> void removeIngredientObserver(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T,M> ingredientComponent, org.cyclops.integrateddynamics.api.network.INetwork network)
    • onNetworkAddition

      public void onNetworkAddition(org.cyclops.integrateddynamics.api.network.INetwork network)
      Register the observers of running jobs in the network this handler was added to.
      Parameters:
      network - The network.
    • onNetworkRemoval

      public void onNetworkRemoval(org.cyclops.integrateddynamics.api.network.INetwork network)
      Unregister all observers from the network this handler was removed from. Counters are retained, so that observers can be registered again in a new network. This is needed because networks are recreated when they are rebuilt, e.g. when a cable is added or removed.
      Parameters:
      network - The network.
    • onCraftingJobFinished

      public void onCraftingJobFinished(CraftingJob craftingJob)
    • markCraftingJobFinished

      public void markCraftingJobFinished(int craftingJobId)
    • onCraftingJobEntryFinished

      public void onCraftingJobEntryFinished(ICraftingNetwork craftingNetwork, int craftingJobId)
    • update

      public void update(org.cyclops.integrateddynamics.api.network.INetwork network, int channel, org.cyclops.integrateddynamics.api.part.PartPos targetPos)
    • insertCrafting

      protected boolean insertCrafting(org.cyclops.integrateddynamics.api.part.PartPos target, org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients ingredients, org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition recipe, CraftingJob craftingJob, org.cyclops.integrateddynamics.api.network.INetwork network, int channel, boolean simulate)
    • insertLoopNonBlocking

      protected void insertLoopNonBlocking(org.cyclops.integrateddynamics.api.network.INetwork network, int channel, org.cyclops.integrateddynamics.api.part.PartPos targetPos, CraftingJob craftingJob)
    • consumeAndInsertCrafting

      protected boolean consumeAndInsertCrafting(boolean blockingMode, org.cyclops.integrateddynamics.api.network.INetwork network, int channel, org.cyclops.integrateddynamics.api.part.PartPos targetPos, CraftingJob startingCraftingJob)
    • getCraftingJobStatus

      public CraftingJobStatus getCraftingJobStatus(ICraftingNetwork network, int channel, int craftingJobId)
    • getAllCraftingJobs

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<CraftingJob> getAllCraftingJobs()
    • setIngredientComponentTarget

      public void setIngredientComponentTarget(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?> ingredientComponent, @Nullable net.minecraft.core.Direction side)
    • getIngredientComponentTarget

      @Nullable public net.minecraft.core.Direction getIngredientComponentTarget(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?> ingredientComponent)
    • getTargetGetter

      public Function<org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<?,?>,org.cyclops.integrateddynamics.api.part.PartPos> getTargetGetter(org.cyclops.integrateddynamics.api.part.PartPos defaultPosition)
    • beforeFlushIngredientToNetwork

      public <T, M> org.cyclops.integrateddynamics.core.network.IIngredientChannelInsertPreConsumer.Result<T> beforeFlushIngredientToNetwork(org.cyclops.commoncapabilities.api.ingredient.IngredientInstanceWrapper<T,M> instanceWrapper, int channel)
      This method is called right before a crafting interface's result buffer is flushed to the network. This will first try to pass the instance along to crafting jobs that have pending ingredients. The remaining instance that could not be inserted into any of those crafting jobs is returned.
      Type Parameters:
      T - The ingredient type.
      M - The match condition.
      Parameters:
      instanceWrapper - The instance that would be inserted into the network.
      channel - The channel.
      Returns:
      The remaining instance that was not consumed by observers, and the part of it that no crafting interface has claimed.