Interface IItemSource


  • public interface IItemSource
    Represent an item source. Take only, cannot be placed back.
    • Method Detail

      • take

        @Nonnull
        java.util.Map<ItemStack,​java.lang.Integer> take​(java.util.function.Predicate<ItemStack> predicate,
                                                              boolean simulate,
                                                              int count)
        Retrieve some amount of items from this item source matching given filter.

        We probably don't need to get a lot of items from this method, so I don't care about the overhead of storing all fetched items even if downstream code doesn't need it

        Parameters:
        predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
        simulate - whether to actually commit the modification. true for dry run, false otherwise.
        count - how many items to extract.
        Returns:
        A nonnull map reflecting the result of extraction. Note this map is NBT and metadata aware.
      • takeOne

        default ItemStack takeOne​(java.util.function.Predicate<ItemStack> predicate,
                                  boolean simulate)
        Take exactly one item that matches the predicate.
        Parameters:
        predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
        simulate - whether to actually commit the modification. true for dry run, false otherwise.
        Returns:
        item stack, or null if none matches
        Throws:
        java.lang.IllegalArgumentException - if given predicate is null.
      • takeAll

        default boolean takeAll​(java.util.function.Predicate<ItemStack> predicate,
                                boolean simulate,
                                int count)
        Take exactly count amount of items matching predicate.
        Parameters:
        predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
        simulate - whether to actually commit the modification. true for dry run, false otherwise.
        count - how many items to extract.
        Returns:
        true if at least count amount of items can be/is taken.
        Throws:
        java.lang.IllegalArgumentException - if given predicate is null
      • takeOne

        default boolean takeOne​(ItemStack stack,
                                boolean simulate)
        Take exactly one item. ItemStack given must have a stack size of 1.

        This is meant to be an optimized version of takeOne(Predicate, boolean). Implementations that support item storage indexed by ItemStack can use this to speed up calculation.

        Parameters:
        stack - what item to extract. The NBT tag of this ItemStack is siginifcant and will be considered during matching. must have a stack size of 1.
        simulate - whether to actually commit the modification. true for dry run, false otherwise.
        Returns:
        true if found. false otherwise
        Throws:
        java.lang.IllegalArgumentException - if given stack is invalid, or has a stack size other than 1.
      • takeAll

        default boolean takeAll​(ItemStack stack,
                                boolean simulate)
        Take some item. Will not take item if it cannot find enough items to take.

        This is meant to be an optimized version of takeOne(Predicate, boolean). Implementations that support indexing off ItemStack can use this to speed up calculation.

        Parameters:
        stack - what item and how many to extract. The NBT tag of this ItemStack is siginifcant and will be considered during matching
        simulate - whether to actually commit the modification. true for dry run, false otherwise.
        Returns:
        true if enough item can be/has been extracted. false otherwise
        Throws:
        java.lang.IllegalArgumentException - if given stack is invalid