Skip to content

Commit

Permalink
add a new api to stack extractors
Browse files Browse the repository at this point in the history
Signed-off-by: Glease <[email protected]>
  • Loading branch information
Glease committed Apr 16, 2024
1 parent a7f0d6b commit efd4970
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,16 @@ private static int takeFromInventory(@Nonnull Iterable<ItemStack> inv, @Nonnull
}
if (!recursive) continue;
for (ItemStackExtractor f : stackExtractors) {
boolean end = f.isAPIImplemented(APIType.IS_VALID_SOURCE);
if (!f.isValidSource(stack, player)) continue;
if (filter != null && f.isAPIImplemented(APIType.EXTRACT_ONE_STACK)) {
copiedFilter.stackSize = count - found;
found += f.getItem(stack, copiedFilter, simulate, player);
} else {
found += f.takeFromStack(predicate, simulate, count - found, store, stack, filter, player);
}
if (found >= count) return found;
if (end) break;
}
}
return found;
Expand Down Expand Up @@ -294,10 +297,15 @@ public interface ItemStackExtractor {
enum APIType {
MAIN,
EXTRACT_ONE_STACK,
IS_VALID_SOURCE,
}

boolean isAPIImplemented(APIType type);

default boolean isValidSource(ItemStack is, EntityPlayerMP player) {
return true;
}

/**
* Extract a particular type of item. The extractor can choose to not return all items contained within this
* item as long as it makes sense, but the author should inform the player of this.
Expand Down

0 comments on commit efd4970

Please sign in to comment.