Class CraftingManager

java.lang.Object
com.hypixel.hytale.builtin.crafting.component.CraftingManager
All Implemented Interfaces:
Component<EntityStore>, Cloneable

public class CraftingManager extends Object implements Component<EntityStore>
Crafting Manager

A component that handles the queueing and processing of crafting recipes.

  • Constructor Details

    • CraftingManager

      public CraftingManager()
      Empty Constructor for a CraftingManager instance.

      Used to initialize the component on an entity.

  • Method Details

    • getComponentType

      @Nonnull public static ComponentType<EntityStore, CraftingManager> getComponentType()
      Returns:
      the component type for the CraftingManager component.
    • hasBenchSet

      public boolean hasBenchSet()
      Returns:
      true if the crafting manager has an active bench, false otherwise.
    • setBench

      public void setBench(int x, int y, int z, @Nonnull BlockType blockType)
      Called to set the current bench being used for crafting.
      Parameters:
      x - The X position of the crafting bench.
      y - The Y position of the crafting bench.
      z - The Z position of the crafting bench.
      blockType - The block type of the crafting bench.
    • clearBench

      public boolean clearBench(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to clear this bench, cancelling all queued crafts.
      Parameters:
      ref - The reference of the affiliated entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      True if a craft was cancelled, false otherwise.
    • craftItem

      public boolean craftItem(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull CraftingRecipe recipe, int requestedQuantity, @Nonnull ItemContainer itemContainer)
      Called to instantly craft the given item for the given quantity.
      Parameters:
      ref - The entity ref of the affiliated entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      recipe - The recipe to craft.
      requestedQuantity - The quantity of item to craft, before it is resolved against the player's game mode.
      itemContainer - The container to pick items from.
    • queueCraft

      public boolean queueCraft(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull CraftingWindow window, int transactionId, @Nonnull CraftingRecipe recipe, int requestedQuantity, @Nonnull ItemContainer inputItemContainer, @Nonnull CraftingManager.InputRemovalType inputRemovalType)
      Called to queue a recipe to be crafted.
      Parameters:
      ref - The entity ref of the affiliated entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      window - The crafting window for this queued craft.
      transactionId - The transaction id for this queued craft.
      recipe - The recipe to craft.
      requestedQuantity - The quantity of item to craft, before it is resolved against the player's game mode.
      inputItemContainer - The target input item container.
    • getRemainingQueueSize

      public int getRemainingQueueSize()
    • tick

      public void tick(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, float dt)
      Called to tick and update this crafting manager.
      Parameters:
      ref - A reference to the entity affiliated with this crafting manager.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      dt - The delta time of this tick.
    • cancelAllCrafting

      public boolean cancelAllCrafting(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to cancel all crafting within this crafting manager.
      Parameters:
      ref - The entity ref of the affiliated entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      True if a craft was cancelled, false otherwise.
    • getOutputItemStacks

      @Nonnull public static List<ItemStack> getOutputItemStacks(@Nonnull CraftingRecipe recipe)
      Fetches a list of item stacks as the output item stacks for the given recipe.
      Parameters:
      recipe - The recipe that we are fetching the output item stacks for.
      Returns:
      a list of ItemStack instances as the output items.
    • getOutputItemStacks

      @Nonnull public static List<ItemStack> getOutputItemStacks(@Nonnull CraftingRecipe recipe, int quantity)
      Fetches a list of item stacks as the output item stacks for the given recipe, for the given quantity.
      Parameters:
      recipe - The recipe that we are fetching the output item stacks for.
      quantity - The number of the output item stacks to return.
      Returns:
      a list of ItemStack instances as the output items.
    • getOutputItemStack

      @Nullable public static ItemStack getOutputItemStack(@Nonnull MaterialQuantity outputMaterial, @Nonnull String id)
      Fetches a list of item stacks as the output item stacks for the given output material.
      Parameters:
      outputMaterial - The output material that we are fetching the output item stacks for.
      id - The ID of the recipe that the output material is affiliated with.
      Returns:
      a list of ItemStack instances as the output items.
    • getOutputItemStack

      @Nullable public static ItemStack getOutputItemStack(@Nonnull MaterialQuantity outputMaterial, int quantity)
      Fetches a list of item stacks as the output item stacks for the given output material, for the given quantity.
      Parameters:
      outputMaterial - The output material that we are fetching the output item stacks for.
      quantity - The quantity of the item stack to return to the entities inventory.
      Returns:
      a list of ItemStack instances as the output items, or null if the output material has no item ID.
    • getInputMaterials

      @Nonnull public static List<MaterialQuantity> getInputMaterials(@Nonnull CraftingRecipe recipe)
      Fetches a list of material quantities affiliated with the given recipe.
      Parameters:
      recipe - The recipe that we are fetching the material quantities for.
      Returns:
      a list of MaterialQuantity instances for the given recipe.
    • getInputMaterials

      @Nonnull public static List<MaterialQuantity> getInputMaterials(@Nonnull CraftingRecipe recipe, int quantity)
      Fetches a list of material quantities affiliated with the given recipe, for the given quantity.
      Parameters:
      recipe - The recipe that we are fetching the material quantities for.
      quantity - The quantity of the material quantities to return.
      Returns:
      a list of MaterialQuantity instances for the given recipe.
    • matches

      public static boolean matches(@Nonnull MaterialQuantity craftingMaterial, @Nonnull ItemStack itemStack)
      Determines whether the given crafting material matches the given item stack.
      Parameters:
      craftingMaterial - The crafting material that we are matching.
      itemStack - The item stack that we are matching.
      Returns:
      true if they match, false otherwise.
    • generateInventoryHints

      @Nonnull public static com.google.gson.JsonArray generateInventoryHints(@Nonnull List<CraftingRecipe> recipes, int inputSlotIndex, @Nonnull ItemContainer container)
      Generates and returns inventory hints for the given recipes.
      Parameters:
      recipes - Given list of bench recipes to generate inventory hints for.
      inputSlotIndex - The index of the current input slot.
      container - The target item containers.
      Returns:
      a new JsonArray instance, populated with the appropriate inventory hints.
    • matchesAnyRecipe

      public static boolean matchesAnyRecipe(@Nonnull List<CraftingRecipe> recipes, int inputSlotIndex, @Nonnull ItemStack slotItemStack)
      Determines whether the given item stack matches any of the provided bench recipes.
      Parameters:
      recipes - Given list of recipes to match against.
      inputSlotIndex - The current input slot index.
      slotItemStack - The item stack to match.
      Returns:
      true if the item stack matches any of the given recipes, false otherwise.
    • startTierUpgrade

      public boolean startTierUpgrade(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull BenchWindow window)
      Called to attempt to start a bench tier upgrade for the affiliated entity.
      Parameters:
      ref - The entity reference of the instigating player entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      window - The associated bench window.
      Returns:
      true if the upgrade was started, false otherwise.
    • feedExtraResourcesSection

      public static int feedExtraResourcesSection(@Nonnull World world, int x, int y, int z, @Nonnull BlockType blockType, int rotationIndex, @Nonnull Bench benchAsset, int tierLevel, @Nonnull MaterialExtraResourcesSection extraResourcesSection)
      Feeds the extra resources section with the contents of chests around the bench.
      Parameters:
      world - The world containing the bench.
      x - The X position of the bench.
      y - The Y position of the bench.
      z - The Z position of the bench.
      blockType - The block type of the bench.
      rotationIndex - The rotation index of the bench.
      tierLevel - The current tier level of the bench.
      extraResourcesSection - The section to populate.
      Returns:
      The number of chests found around the bench.
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • clone

      @Nonnull public Component<EntityStore> clone()
      Specified by:
      clone in interface Component<EntityStore>
      Returns:
      a clone instance of the original component instance.