Skip to content

Commit

Permalink
Fix crash when recipe does not fit in 3x3 nor 2x2 grid
Browse files Browse the repository at this point in the history
Closes #117
  • Loading branch information
rubensworks committed Nov 10, 2024
1 parent 9a6623d commit 5b9c8a9
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.cyclops.integrateddynamics.api.part.PartPos;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.function.Function;
Expand Down Expand Up @@ -56,8 +57,13 @@ public boolean craft(Function<IngredientComponent<?, ?>, PartPos> targetGetter,

return CraftingHelpers.findServerRecipe(RecipeType.CRAFTING, gridInput, level)
.or(() -> {
CraftingGrid gridSmall = new CraftingGrid(ingredients, 2, 2);
return CraftingHelpers.findServerRecipe(RecipeType.CRAFTING, gridSmall.asCraftInput(), level);
try {
CraftingGrid gridSmall = new CraftingGrid(ingredients, 2, 2);
return CraftingHelpers.findServerRecipe(RecipeType.CRAFTING, gridSmall.asCraftInput(), level);
} catch (IllegalArgumentException e) {
// This can occur if the ingredients don't fit in a 2x2 grid.
return Optional.empty();
}
})
.map(recipeHolder -> {
CraftingRecipe recipe = recipeHolder.value();
Expand Down

0 comments on commit 5b9c8a9

Please sign in to comment.