Skip to content

Commit 7a1f8c3

Browse files
Fix Quantum Compressor not running without item in input (#20)
1 parent 1603046 commit 7a1f8c3

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/main/java/com/blakebr0/extendedcrafting/tile/TileCompressor.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,42 @@ public void update() {
6161
boolean mark = false;
6262

6363
if (!this.getWorld().isRemote) {
64-
CompressorRecipe recipe = null;
64+
6565
ItemStack output = this.getStackInSlot(0);
6666
ItemStack input = this.getStackInSlot(1);
6767

68-
if (!input.isEmpty()) {
69-
if (this.materialStack.isEmpty()) {
68+
// Update the input item and materialStack before finding the recipe to prevent returning a null recipe
69+
// on the first tick, as materialStack would be empty. This would become infinite failure of finding a recipe
70+
// due to materialStack clearing on failed recipe
71+
if(!input.isEmpty()) {
72+
if(this.materialStack.isEmpty()) {
7073
this.materialStack = input.copy();
7174
mark = true;
7275
}
76+
}
7377

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

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

84-
StackHelper.decrease(input, consumeAmount, false);
85-
this.materialCount += consumeAmount;
86-
mark = true;
81+
// Consuming Input Items
82+
if (!input.isEmpty() && (!this.inputLimit || (recipe != null && this.materialCount < recipe.getInputCount()))) {
83+
if (StackHelper.areStacksEqual(input, this.materialStack)) {
84+
int consumeAmount = input.getCount();
85+
if (this.inputLimit && recipe != null) {
86+
consumeAmount = Math.min(consumeAmount, recipe.getInputCount() - this.materialCount);
8787
}
88+
89+
StackHelper.decrease(input, consumeAmount, false);
90+
this.materialCount += consumeAmount;
91+
mark = true;
8892
}
89-
//Invalidate the cached item and marked state on unsuccessful recipe retrieval
90-
else if(mark) {
91-
this.materialStack = ItemStack.EMPTY;
92-
}
93+
}
94+
//Invalidate the cached item and marked state on unsuccessful recipe retrieval
95+
else if(mark) {
96+
this.materialStack = ItemStack.EMPTY;
9397
}
9498

99+
// Progressing output item
95100
if (recipe != null && this.getEnergy().getEnergyStored() > 0) {
96101
if (this.materialCount >= recipe.getInputCount()) {
97102
this.process(recipe);
@@ -137,6 +142,7 @@ else if(mark) {
137142
}
138143
}
139144

145+
// Update Energy amount
140146
if (this.oldEnergy != this.energy.getEnergyStored()) {
141147
this.oldEnergy = this.energy.getEnergyStored();
142148
mark = true;

0 commit comments

Comments
 (0)