allow for cleaner override

This commit is contained in:
Darkere
2021-06-09 18:39:37 +02:00
parent 7292984d54
commit 3516af186a
3 changed files with 38 additions and 12 deletions

View File

@@ -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 * 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 * 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 toInsert A collection of items that should be inserted.
* @param action Action to take * @param action Action to take
* @return whether the insertion was successful * @return whether the insertion was successful
*/ */
boolean insertIntoInventory(@Nullable IItemHandler dest, Collection<StackListEntry<ItemStack>> toInsert, Action action); boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> toInsert, Action action);
/** /**
* Called when the autocrafting system wants to insert fluids. Will be called with Action.SIMULATE first and if that * 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 * 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 toInsert A collection of fluids that should be inserted.
* @param action Action to take * @param action Action to take
* @return whether the insertion was successful * @return whether the insertion was successful
*/ */
boolean insertIntoInventory(IFluidHandler dest, Collection<StackListEntry<FluidStack>> toInsert, Action action); boolean insertFluidsIntoInventory(Collection<StackListEntry<FluidStack>> 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();
} }

View File

@@ -104,8 +104,8 @@ public class ProcessingNode extends Node {
allLocked = false; allLocked = false;
} }
if ((!singleItemSetToRequire.isEmpty() && container.getConnectedInventory() == null) || if ((!singleItemSetToRequire.isEmpty() && container.hasConnectedInventory()) ||
(!singleFluidSetToRequire.isEmpty() && container.getConnectedFluidInventory() == null)) { (!singleFluidSetToRequire.isEmpty() && container.hasConnectedFluidInventory())) {
if (allMissingMachine) { if (allMissingMachine) {
this.state = ProcessingState.MACHINE_NONE; this.state = ProcessingState.MACHINE_NONE;
} }
@@ -128,9 +128,9 @@ public class ProcessingNode extends Node {
boolean canInsertFullAmount = false; boolean canInsertFullAmount = false;
if (hasAllRequirements) { if (hasAllRequirements) {
canInsertFullAmount = container.insertIntoInventory(container.getConnectedInventory(), extractedItems.getStacks(), Action.SIMULATE); canInsertFullAmount = container.insertItemsIntoInventory(extractedItems.getStacks(), Action.SIMULATE);
if (canInsertFullAmount) { 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); extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM);
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM); extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM);
container.insertIntoInventory(container.getConnectedInventory(), extractedItems.getStacks(), Action.PERFORM); container.insertItemsIntoInventory(extractedItems.getStacks(), Action.PERFORM);
container.insertIntoInventory(container.getConnectedFluidInventory(), extractedFluids.getStacks(), Action.PERFORM); container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.PERFORM);
next(); next();

View File

@@ -464,7 +464,9 @@ public class CrafterNetworkNode extends NetworkNode implements ICraftingPatternC
} }
@Override @Override
public boolean insertIntoInventory(@Nullable IItemHandler dest, Collection<StackListEntry<ItemStack>> toInsert, Action action) { public boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> toInsert, Action action) {
IItemHandler dest = getConnectedInventory();
if (dest == null) { if (dest == null) {
return false; return false;
} }
@@ -518,7 +520,13 @@ public class CrafterNetworkNode extends NetworkNode implements ICraftingPatternC
} }
@Override @Override
public boolean insertIntoInventory(IFluidHandler dest, Collection<StackListEntry<FluidStack>> toInsert, Action action) { public boolean insertFluidsIntoInventory(Collection<StackListEntry<FluidStack>> toInsert, Action action) {
IFluidHandler dest = getConnectedFluidInventory();
if (dest == null) {
return false;
}
for (StackListEntry<FluidStack> entry : toInsert) { for (StackListEntry<FluidStack> entry : toInsert) {
int filled = dest.fill(entry.getStack(), action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE); 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; return true;
} }
@Override
public boolean hasConnectedInventory() {
return getConnectedInventory() != null;
}
@Override
public boolean hasConnectedFluidInventory() {
return getConnectedFluidInventory() != null;
}
} }