diff --git a/src/api/java/mekanism/api/chemical/BasicChemicalTank.java b/src/api/java/mekanism/api/chemical/BasicChemicalTank.java index 936f34e9754..2b561cd72e6 100644 --- a/src/api/java/mekanism/api/chemical/BasicChemicalTank.java +++ b/src/api/java/mekanism/api/chemical/BasicChemicalTank.java @@ -108,8 +108,9 @@ private void setStack(STACK stack, boolean validateStack) { @Override public STACK insert(@NotNull STACK stack, Action action, AutomationType automationType) { - if (stack.isEmpty() || !isValid(stack) || !canInsert.test(stack.getChemical(), automationType)) { - //"Fail quick" if the given stack is empty, or we can never insert the chemical or currently are unable to insert it + boolean sameType = false; + if (stack.isEmpty() || !(isEmpty() || (sameType = isTypeEqual(stack)))) { + //"Fail quick" if the given stack is empty return stack; } long needed = Math.min(getInsertRate(automationType), getNeeded()); @@ -117,26 +118,25 @@ public STACK insert(@NotNull STACK stack, Action action, AutomationType automati //Fail if we are a full tank or our rate is zero return stack; } - boolean sameType = false; - if (isEmpty() || (sameType = isTypeEqual(stack))) { - long toAdd = Math.min(stack.getAmount(), needed); - if (action.execute()) { - //If we want to actually insert the chemical, then update the current chemical - if (sameType) { - //We can just grow our stack by the amount we want to increase it - stored.grow(toAdd); - onContentsChanged(); - } else { - //If we are not the same type then we have to copy the stack and set it - // Just set it unchecked as we have already validated it - // Note: this also will mark that the contents changed - setStackUnchecked(createStack(stack, toAdd)); - } + if (!isValid(stack) || !canInsert.test(stack.getChemical(), automationType)) { + //we can never insert the chemical or currently are unable to insert it + return stack; + } + long toAdd = Math.min(stack.getAmount(), needed); + if (action.execute()) { + //If we want to actually insert the chemical, then update the current chemical + if (sameType) { + //We can just grow our stack by the amount we want to increase it + stored.grow(toAdd); + onContentsChanged(); + } else { + //If we are not the same type then we have to copy the stack and set it + // Just set it unchecked as we have already validated it + // Note: this also will mark that the contents changed + setStackUnchecked(createStack(stack, toAdd)); } - return createStack(stack, stack.getAmount() - toAdd); } - //If we didn't accept this chemical, then just return the given stack - return stack; + return createStack(stack, stack.getAmount() - toAdd); } @Override