Actually obey the update cache param, and use the more advanced helper method in Container as well

This commit is contained in:
pupnewfster committed 2019-04-26 14:39:40 -04:00
1 parent f6d3d742e8
commit ba89f446f9
2 files changed
+6 -18

No files matched your search

@@ -3,13 +3,11 @@ package mekanism.common.inventory.container;
import java.util.Arrays;
import javax.annotation.Nonnull;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.common.tier.FactoryTier;
import mekanism.common.base.IFactory.RecipeType;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.item.ItemBlockMachine;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.tier.FactoryTier;
import mekanism.common.tile.TileEntityFactory;
import mekanism.common.util.ChargeUtils;
import net.minecraft.entity.player.EntityPlayer;
@@ -194,16 +192,8 @@ public class ContainerFactory extends ContainerMekanism<TileEntityFactory> {
@Override
public boolean isItemValid(ItemStack stack) {
ItemStack outputSlotStack = tileEntity.inventory.get(getOutputSlotIndex(this.processNumber));
if (outputSlotStack.isEmpty()) {
return super.isItemValid(stack);
}
MachineRecipe matchingRecipe = tileEntity.getRecipeType()
.getAnyRecipe(stack, inventorySlots.get(4).getStack(), tileEntity.gasTank.getGasType(),
tileEntity.infuseStored);
if (matchingRecipe != null && matchingRecipe.recipeOutput instanceof ItemStackOutput) {
return ItemStack.areItemsEqual(((ItemStackOutput) matchingRecipe.recipeOutput).output, outputSlotStack);
}
return super.isItemValid(stack);
return tileEntity.inputProducesOutput(getInputSlotIndex(this.processNumber), stack, outputSlotStack, false)
&& super.isItemValid(stack);
}
}
}
@@ -438,7 +438,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
* @param updateCache True to make the cached recipe get updated if it is out of date.
* @return True if the recipe produces the given output.
*/
private boolean inputProducesOutput(int slotID, ItemStack fallbackInput, ItemStack output, boolean updateCache) {
public boolean inputProducesOutput(int slotID, ItemStack fallbackInput, ItemStack output, boolean updateCache) {
if (output.isEmpty()) {
return true;
}
@@ -447,8 +447,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
MachineRecipe cached = cachedRecipe[process];
ItemStack extra = inventory.get(4);
if (cached == null) {
cached = recipeType
.getAnyRecipe(fallbackInput, extra, gasTank.getGasType(), infuseStored);
cached = recipeType.getAnyRecipe(fallbackInput, extra, gasTank.getGasType(), infuseStored);
if (updateCache) {
cachedRecipe[process] = cached;
}
@@ -480,8 +479,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
// then it is an out of date cache so we compare against the new one
// and update the cache while we are at it
if (recipeInput.isEmpty() || !secondaryMatch || !ItemStack.areItemsEqual(recipeInput, fallbackInput)) {
cached = cachedRecipe[process] = recipeType
.getAnyRecipe(fallbackInput, extra, gasTank.getGasType(), infuseStored);
cached = recipeType.getAnyRecipe(fallbackInput, extra, gasTank.getGasType(), infuseStored);
if (updateCache) {
cachedRecipe[process] = cached;
}