Skip to content

Commit

Permalink
Fix Quantum Compressor not running without item in input (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ALongStringOfNumbers authored Oct 23, 2021
1 parent 1603046 commit 7a1f8c3
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,42 @@ public void update() {
boolean mark = false;

if (!this.getWorld().isRemote) {
CompressorRecipe recipe = null;

ItemStack output = this.getStackInSlot(0);
ItemStack input = this.getStackInSlot(1);

if (!input.isEmpty()) {
if (this.materialStack.isEmpty()) {
// Update the input item and materialStack before finding the recipe to prevent returning a null recipe
// on the first tick, as materialStack would be empty. This would become infinite failure of finding a recipe
// due to materialStack clearing on failed recipe
if(!input.isEmpty()) {
if(this.materialStack.isEmpty()) {
this.materialStack = input.copy();
mark = true;
}
}

// Retrieve the recipe after checking if the input is not empty, run every update cycle
recipe = this.getRecipe();
CompressorRecipe recipe = getRecipe();

if (!this.inputLimit || (recipe != null && this.materialCount < recipe.getInputCount())) {
if (StackHelper.areStacksEqual(input, this.materialStack)) {
int consumeAmount = input.getCount();
if (this.inputLimit && recipe != null) {
consumeAmount = Math.min(consumeAmount, recipe.getInputCount() - this.materialCount);
}

StackHelper.decrease(input, consumeAmount, false);
this.materialCount += consumeAmount;
mark = true;
// Consuming Input Items
if (!input.isEmpty() && (!this.inputLimit || (recipe != null && this.materialCount < recipe.getInputCount()))) {
if (StackHelper.areStacksEqual(input, this.materialStack)) {
int consumeAmount = input.getCount();
if (this.inputLimit && recipe != null) {
consumeAmount = Math.min(consumeAmount, recipe.getInputCount() - this.materialCount);
}

StackHelper.decrease(input, consumeAmount, false);
this.materialCount += consumeAmount;
mark = true;
}
//Invalidate the cached item and marked state on unsuccessful recipe retrieval
else if(mark) {
this.materialStack = ItemStack.EMPTY;
}
}
//Invalidate the cached item and marked state on unsuccessful recipe retrieval
else if(mark) {
this.materialStack = ItemStack.EMPTY;
}

// Progressing output item
if (recipe != null && this.getEnergy().getEnergyStored() > 0) {
if (this.materialCount >= recipe.getInputCount()) {
this.process(recipe);
Expand Down Expand Up @@ -137,6 +142,7 @@ else if(mark) {
}
}

// Update Energy amount
if (this.oldEnergy != this.energy.getEnergyStored()) {
this.oldEnergy = this.energy.getEnergyStored();
mark = true;
Expand Down

0 comments on commit 7a1f8c3

Please sign in to comment.