From efd49701e1d1f5384592a00eb82d594a2238e16b Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:32:31 +0800 Subject: [PATCH] add a new api to stack extractors Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gtnewhorizon/structurelib/util/InventoryUtility.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/gtnewhorizon/structurelib/util/InventoryUtility.java b/src/main/java/com/gtnewhorizon/structurelib/util/InventoryUtility.java index 4536d1fd..770043b2 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/util/InventoryUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/util/InventoryUtility.java @@ -253,6 +253,8 @@ private static int takeFromInventory(@Nonnull Iterable 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); @@ -260,6 +262,7 @@ private static int takeFromInventory(@Nonnull Iterable inv, @Nonnull found += f.takeFromStack(predicate, simulate, count - found, store, stack, filter, player); } if (found >= count) return found; + if (end) break; } } return found; @@ -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.