Interface Ingredient


@NonExtendable public interface Ingredient
What one grid slot of a recipe accepts, and how many of it the craft takes from that slot.

Vanilla always takes one item per slot. Here the count can be raised: Ingredient.of(DIAMOND).withCount(16) only matches a slot holding at least sixteen diamonds, and crafting takes sixteen of them.

Instances are immutable and safe to share between threads.

Since:
0.1.0
  • Method Details

    • of

      static Ingredient of(TypedKey<Item>... items)
      Parameters:
      items - the items accepted, any of them will do
      Returns:
      an ingredient taking one of any of items
      Throws:
      IllegalArgumentException - if items is empty
      Since:
      0.1.0
    • of

      static Ingredient of(Collection<TypedKey<Item>> items)
      Parameters:
      items - the items accepted, any of them will do
      Returns:
      an ingredient taking one of any of items
      Throws:
      IllegalArgumentException - if items is empty
      Since:
      0.1.0
    • tag

      static Ingredient tag(TagKey<Item> tag)
      Parameters:
      tag - an item tag, e.g. minecraft:planks, without the leading #
      Returns:
      an ingredient taking one of any item of the tag
      Since:
      0.1.0
    • exact

      static Ingredient exact(ItemStack stack)
      Accepts only stacks of the same item carrying the same components, which is how a plugin recognises its own custom items. The count of stack becomes the count of the ingredient: Ingredient.exact(ruby.withCount(4)) takes four rubies.
      Parameters:
      stack - the stack to compare against
      Returns:
      an ingredient taking stack.count() items similar to stack
      Throws:
      IllegalArgumentException - if stack is empty
      Since:
      0.1.0
    • matching

      static Ingredient matching(Predicate<ItemStack> predicate)
      Accepts whatever predicate accepts. The predicate sees the whole stack but must not look at its count: the count of the ingredient takes care of that.
      Parameters:
      predicate - tells whether a stack is accepted, never called with an empty stack
      Returns:
      an ingredient taking one item accepted by predicate
      Since:
      0.1.0
    • count

      int count()
      Returns:
      how many items one craft takes from the slot, at least 1
      Since:
      0.1.0
    • withCount

      Ingredient withCount(int newCount)
      Parameters:
      newCount - how many items one craft takes from the slot
      Returns:
      an ingredient accepting the same items, in that quantity
      Throws:
      IllegalArgumentException - if newCount is lower than 1
      Since:
      0.1.0
    • test

      boolean test(ItemStack stack, ItemTagLookup tags)
      Whether the item of stack is accepted, regardless of how many there are.
      Parameters:
      stack - the stack to test
      tags - resolves tag ingredients
      Returns:
      true when stack is not empty and its item is accepted
      Since:
      0.1.0
    • accepts

      boolean accepts(ItemStack stack, ItemTagLookup tags)
      Whether stack can feed one craft: its item is accepted and there are at least count() of it.
      Parameters:
      stack - the stack to test
      tags - resolves tag ingredients
      Returns:
      true when one craft can take its share from stack
      Since:
      0.1.0