Skip to content

Commit

Permalink
Fixed machines not resetting progress when their input is instantly s…
Browse files Browse the repository at this point in the history
…wapped
  • Loading branch information
Lykrast committed Jul 14, 2019
1 parent 34b659b commit 594173b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ private int canSmeltPrimordium()
private AtomicReshaperRecipe cachedRecipe;
private void updateCachedRecipe() {
if (cachedRecipe == null) cachedRecipe = AtomicReshaperManager.INSTANCE.findRecipe(getStackInSlot(1));
else if (!cachedRecipe.isValidInput(getStackInSlot(1))) cachedRecipe = AtomicReshaperManager.INSTANCE.findRecipe(getStackInSlot(1));
else if (!cachedRecipe.isValidInput(getStackInSlot(1))) {
cachedRecipe = AtomicReshaperManager.INSTANCE.findRecipe(getStackInSlot(1));
//Recipe became invalid, restart the process
processTimeMax = 0;
processTime = 0;
}
}

private boolean canProcess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,27 @@ public String getName() {
return super.getName() + "food_enricher";
}

private ItemStack cachedResult;
private ItemStack cachedResult, lastInput = ItemStack.EMPTY;
private void updateCachedResult() {
ItemStack input = getStackInSlot(0);
if (input.isEmpty()) cachedResult = null;
//No input
if (input.isEmpty()) {
cachedResult = null;
lastInput = ItemStack.EMPTY;
}
//No cached input, let it slide
else if (lastInput.isEmpty()) {
lastInput = input;
cachedResult = enrich(input);
}
//Input changed
else if (input != lastInput) {
lastInput = input;
cachedResult = enrich(input);
processTimeMax = 0;
processTime = 0;
}
//Missing the cache
else if (cachedResult == null) cachedResult = enrich(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@ public String getName() {
return super.getName() + "food_purifier";
}

private ItemStack cachedResult;
private ItemStack cachedResult, lastInput = ItemStack.EMPTY;
private void updateCachedResult() {
ItemStack input = getStackInSlot(0);
if (input.isEmpty()) cachedResult = null;
//No input
if (input.isEmpty()) {
cachedResult = null;
lastInput = ItemStack.EMPTY;
}
//No cached input, let it slide
else if (lastInput.isEmpty()) {
lastInput = input;
cachedResult = ItemFoodPurified.make(input);
}
//Input changed
else if (input != lastInput) {
lastInput = input;
cachedResult = ItemFoodPurified.make(input);
processTimeMax = 0;
processTime = 0;
}
//Missing the cache
else if (cachedResult == null) cachedResult = ItemFoodPurified.make(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,31 @@ public String getName() {
return super.getName() + "fuel_processor";
}

private ItemStack lastInput = ItemStack.EMPTY;
private void updateCachedResult() {
ItemStack input = getStackInSlot(0);
//No input
if (input.isEmpty()) {
lastInput = ItemStack.EMPTY;
}
//No cached input, let it slide
else if (lastInput.isEmpty()) {
lastInput = input;
}
//Input changed
else if (input != lastInput) {
lastInput = input;
processTimeMax = 0;
processTime = 0;
}
}

@SuppressWarnings("deprecation")
@Override
protected boolean canProcess() {
if (getStackInSlot(0).isEmpty() || hotAir.getInAirTemperature() < 80) return false;


updateCachedResult();
//Assume that if something was inserted it is valid input
//And that whatever is in the output slot is a Fuel Pellet if there's something
ItemStack curOutput = getStackInSlot(1);
Expand Down Expand Up @@ -97,6 +117,7 @@ else if (processTime <= 0) {
}
}
else if (processTime >= processTimeMax) {
updateCachedResult();
processTimeMax = 0;
processTime = 0;
}
Expand All @@ -123,6 +144,7 @@ private void smelt() {
else curOutput.grow(amount);

input.shrink(1);
updateCachedResult();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ protected IItemHandlerModifiable createInventoryHandler() {
private SimpleRecipeSecondaryOutput cachedRecipe;
private void updateCachedRecipe() {
if (cachedRecipe == null) cachedRecipe = manager.findRecipe(getStackInSlot(0));
else if (!cachedRecipe.isValidInput(getStackInSlot(0))) cachedRecipe = manager.findRecipe(getStackInSlot(0));
else if (!cachedRecipe.isValidInput(getStackInSlot(0))) {
cachedRecipe = manager.findRecipe(getStackInSlot(0));
//Recipe became invalid, restart the process
processTimeMax = 0;
processTime = 0;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ protected boolean isTooCool() {
private SimpleRecipe cachedRecipe;
private void updateCachedRecipe() {
if (cachedRecipe == null) cachedRecipe = manager.findRecipe(getStackInSlot(0));
else if (!cachedRecipe.isValidInput(getStackInSlot(0))) cachedRecipe = manager.findRecipe(getStackInSlot(0));
else if (!cachedRecipe.isValidInput(getStackInSlot(0))) {
cachedRecipe = manager.findRecipe(getStackInSlot(0));
//Recipe became invalid, restart the process
processTimeMax = 0;
processTime = 0;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TileMachineInventory(int slots) {

@Override
public ITextComponent getDisplayName() {
return new TextComponentTranslation(this.getName(), new Object[0]);
return new TextComponentTranslation(getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ private int canSmeltGold()
private SoldererRecipe cachedRecipe;
private void updateCachedRecipe() {
if (cachedRecipe == null) cachedRecipe = SoldererManager.findRecipe(getStackInSlot(0), getStackInSlot(2), gold);
else if (!cachedRecipe.isValidInput(getStackInSlot(0), getStackInSlot(2), gold)) cachedRecipe = SoldererManager.findRecipe(getStackInSlot(0), getStackInSlot(2), gold);
else if (!cachedRecipe.isValidInput(getStackInSlot(0), getStackInSlot(2), gold)) {
cachedRecipe = SoldererManager.findRecipe(getStackInSlot(0), getStackInSlot(2), gold);
//Recipe became invalid, restart the process
processTimeMax = 0;
processTime = 0;
}
}

private boolean canProcess()
Expand Down

0 comments on commit 594173b

Please sign in to comment.