Skip to content

Commit

Permalink
fix: Add a safeguard to avoid infinite looping trying to refill grid,…
Browse files Browse the repository at this point in the history
… log recipe to possibly identify the underlying issue in the future #224
  • Loading branch information
BlayTheNinth committed Oct 29, 2024
1 parent d7947e1 commit 316bc89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CraftingTweaks {

public static final String MOD_ID = "craftingtweaks";
public static boolean debugMode;

public static final Logger logger = LoggerFactory.getLogger(CraftingTweaks.class);

public static boolean isServerSideInstalled = true;

public static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.blay09.mods.craftingtweaks.api.impl;

import net.blay09.mods.craftingtweaks.CraftingTweaks;
import net.blay09.mods.craftingtweaks.api.CraftingGrid;
import net.blay09.mods.craftingtweaks.api.CraftingTweaksAPI;
import net.blay09.mods.craftingtweaks.api.GridRefillHandler;
Expand Down Expand Up @@ -33,6 +34,7 @@ public void refillRecipe(CraftingGrid grid, Player player, AbstractContainerMenu
return;
}

int operations = 0;
outer:
do {
final var ingredientTokens = operation.getIngredientTokens();
Expand Down Expand Up @@ -63,7 +65,12 @@ public void refillRecipe(CraftingGrid grid, Player player, AbstractContainerMenu
final var itemStack = ingredientToken.consume();
craftMatrix.setItem(slot, itemStack.copyWithCount(itemStack.getCount() + slotStack.getCount()));
});
if (!stack) {
operations++;
if (operations > 64) {
CraftingTweaks.logger.warn("Something went wrong trying to refill recipe. Too many iterations. Recipe: {}", recipeHolder.id().location());
break;
}
if (!stack || matrixDiff.isEmpty()) {
break;
}
} while (operation.prepare().canCraft());
Expand Down

0 comments on commit 316bc89

Please sign in to comment.