Skip to content

Commit e59aebd

Browse files
committed
reset ingredients
1 parent e3039a6 commit e59aebd

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main/java/gregtech/common/metatileentities/storage/CachedRecipeData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class CachedRecipeData {
1111

1212
private IRecipe recipe;
13+
private IRecipe previousRecipe;
1314

1415
public CachedRecipeData() {
1516
this(null);
@@ -27,13 +28,18 @@ public boolean matches(InventoryCrafting inventoryCrafting, World world) {
2728
}
2829

2930
public void setRecipe(IRecipe newRecipe) {
31+
this.previousRecipe = this.recipe;
3032
this.recipe = newRecipe;
3133
}
3234

3335
public IRecipe getRecipe() {
3436
return recipe;
3537
}
3638

39+
public IRecipe getPreviousRecipe() {
40+
return previousRecipe;
41+
}
42+
3743
public ItemStack getRecipeOutput() {
3844
return recipe == null ? ItemStack.EMPTY : recipe.getRecipeOutput();
3945
}

src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class CraftingRecipeLogic extends SyncHandler {
3737

3838
// client only
3939
public static final int UPDATE_INGREDIENTS = 1;
40+
public static final int RESET_INGREDIENTS = 2;
4041
public static final int SYNC_STACK = 4;
4142

4243
// server only
@@ -336,7 +337,16 @@ public IRecipe getCachedRecipe() {
336337
@Override
337338
public void detectAndSendChanges(boolean init) {
338339
var recipe = getCachedRecipe();
339-
if (recipe == null) return;
340+
if (recipe == null) {
341+
var prevRecipe = cachedRecipeData.getPreviousRecipe();
342+
if (prevRecipe == null) return;
343+
cachedRecipeData.setRecipe(null);
344+
for (CraftingInputSlot inputSlot : this.inputSlots) {
345+
inputSlot.hasIngredients = true;
346+
}
347+
syncToClient(RESET_INGREDIENTS);
348+
return;
349+
}
340350

341351
requiredItems.clear();
342352
final Map<Integer, Boolean> map = new Int2BooleanArrayMap();
@@ -424,9 +434,12 @@ public void readOnClient(int id, PacketBuffer buf) {
424434
for (int i = 0; i < size; i++) {
425435
this.inputSlots[buf.readByte()].hasIngredients = buf.readBoolean();
426436
}
427-
}
428-
if (id == SYNC_STACK) {
437+
} else if (id == SYNC_STACK) {
429438
getSyncManager().setCursorItem(NetworkUtils.readItemStack(buf));
439+
} else if (id == RESET_INGREDIENTS) {
440+
for (CraftingInputSlot inputSlot : this.inputSlots) {
441+
inputSlot.hasIngredients = true;
442+
}
430443
}
431444
}
432445

0 commit comments

Comments
 (0)