From 3516af186acb83280eb348bca188d94a4be4d951 Mon Sep 17 00:00:00 2001 From: Darkere Date: Wed, 9 Jun 2021 18:39:37 +0200 Subject: [PATCH] allow for cleaner override --- .../ICraftingPatternContainer.java | 16 ++++++++++---- .../task/v6/node/ProcessingNode.java | 12 +++++----- .../network/node/CrafterNetworkNode.java | 22 +++++++++++++++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java b/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java index d3f1c68df..4f0ef3738 100644 --- a/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java +++ b/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java @@ -134,21 +134,29 @@ public interface ICraftingPatternContainer { * Called when the autocrafting system wants to insert items. Will be called with Action.SIMULATE first and if that * succeeds will be called again with Action.PERFORM * - * @param dest The ItemHandler to insert into * @param toInsert A collection of items that should be inserted. * @param action Action to take * @return whether the insertion was successful */ - boolean insertIntoInventory(@Nullable IItemHandler dest, Collection> toInsert, Action action); + boolean insertItemsIntoInventory(Collection> toInsert, Action action); /** * Called when the autocrafting system wants to insert fluids. Will be called with Action.SIMULATE first and if that * succeeds will be called again with Action.PERFORM * - * @param dest The FluidHandler to insert into * @param toInsert A collection of fluids that should be inserted. * @param action Action to take * @return whether the insertion was successful */ - boolean insertIntoInventory(IFluidHandler dest, Collection> toInsert, Action action); + boolean insertFluidsIntoInventory(Collection> toInsert, Action action); + + /** + * @return whether the container is successfully connected to the inventory it wants to insert to + */ + boolean hasConnectedInventory(); + + /** + * @return whether the container is successfully connected to the fluid inventory it wants to insert to + */ + boolean hasConnectedFluidInventory(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/autocrafting/task/v6/node/ProcessingNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/autocrafting/task/v6/node/ProcessingNode.java index e96fb3a0c..5a750736a 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/autocrafting/task/v6/node/ProcessingNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/autocrafting/task/v6/node/ProcessingNode.java @@ -104,8 +104,8 @@ public class ProcessingNode extends Node { allLocked = false; } - if ((!singleItemSetToRequire.isEmpty() && container.getConnectedInventory() == null) || - (!singleFluidSetToRequire.isEmpty() && container.getConnectedFluidInventory() == null)) { + if ((!singleItemSetToRequire.isEmpty() && container.hasConnectedInventory()) || + (!singleFluidSetToRequire.isEmpty() && container.hasConnectedFluidInventory())) { if (allMissingMachine) { this.state = ProcessingState.MACHINE_NONE; } @@ -128,9 +128,9 @@ public class ProcessingNode extends Node { boolean canInsertFullAmount = false; if (hasAllRequirements) { - canInsertFullAmount = container.insertIntoInventory(container.getConnectedInventory(), extractedItems.getStacks(), Action.SIMULATE); + canInsertFullAmount = container.insertItemsIntoInventory(extractedItems.getStacks(), Action.SIMULATE); if (canInsertFullAmount) { - canInsertFullAmount = container.insertIntoInventory(container.getConnectedFluidInventory(), extractedFluids.getStacks(), Action.SIMULATE); + canInsertFullAmount = container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.SIMULATE); } } @@ -150,8 +150,8 @@ public class ProcessingNode extends Node { extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM); extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM); - container.insertIntoInventory(container.getConnectedInventory(), extractedItems.getStacks(), Action.PERFORM); - container.insertIntoInventory(container.getConnectedFluidInventory(), extractedFluids.getStacks(), Action.PERFORM); + container.insertItemsIntoInventory(extractedItems.getStacks(), Action.PERFORM); + container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.PERFORM); next(); diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java index ee1e8c327..ef7aff966 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java @@ -464,7 +464,9 @@ public class CrafterNetworkNode extends NetworkNode implements ICraftingPatternC } @Override - public boolean insertIntoInventory(@Nullable IItemHandler dest, Collection> toInsert, Action action) { + public boolean insertItemsIntoInventory(Collection> toInsert, Action action) { + IItemHandler dest = getConnectedInventory(); + if (dest == null) { return false; } @@ -518,7 +520,13 @@ public class CrafterNetworkNode extends NetworkNode implements ICraftingPatternC } @Override - public boolean insertIntoInventory(IFluidHandler dest, Collection> toInsert, Action action) { + public boolean insertFluidsIntoInventory(Collection> toInsert, Action action) { + IFluidHandler dest = getConnectedFluidInventory(); + + if (dest == null) { + return false; + } + for (StackListEntry entry : toInsert) { int filled = dest.fill(entry.getStack(), action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE); @@ -533,4 +541,14 @@ public class CrafterNetworkNode extends NetworkNode implements ICraftingPatternC return true; } + + @Override + public boolean hasConnectedInventory() { + return getConnectedInventory() != null; + } + + @Override + public boolean hasConnectedFluidInventory() { + return getConnectedFluidInventory() != null; + } }