Skip to content

Commit b1e726f

Browse files
committed
fix: Fix tool tag ingredients cycling through items that aren't present #752
1 parent 3fa699b commit b1e726f

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

shared/src/main/java/net/blay09/mods/cookingforblockheads/registry/CookingRegistry.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public static void initFoodRegistry(RecipeManager recipeManager, RegistryAccess
8888

8989
//noinspection ConstantConditions
9090
if (output == null) {
91-
CookingForBlockheads.logger.warn("Recipe " + recipe.getId() + " returned a null ItemStack in getRecipeOutput - this is bad! The developer of " + recipe.getId().getNamespace() + " should return an empty ItemStack instead to avoid problems.");
91+
CookingForBlockheads.logger.warn("Recipe " + recipe.getId() + " returned a null ItemStack in getRecipeOutput - this is bad! The developer of " + recipe.getId()
92+
.getNamespace() + " should return an empty ItemStack instead to avoid problems.");
9293
continue;
9394
}
9495

@@ -275,22 +276,30 @@ private static SourceItem findAnyItemStack(ItemStack checkStack, List<IKitchenIt
275276

276277
public static List<SourceItem> findSourceCandidates(FoodIngredient ingredient, List<IKitchenItemProvider> inventories, boolean requireBucket, boolean isNoFilter) {
277278
List<SourceItem> sourceList = new ArrayList<>();
279+
List<SourceItem> fallbackSourceList = new ArrayList<>();
278280

279281
ItemStack[] variants = ingredient.getItemStacks();
280282
for (ItemStack checkStack : variants) {
281283
SourceItem sourceItem = CookingRegistry.findAnyItemStack(checkStack, inventories, requireBucket);
282284
ItemStack foundStack = sourceItem != null ? sourceItem.getSourceStack() : ItemStack.EMPTY;
283285
if (foundStack.isEmpty()) {
284-
if (isNoFilter || ingredient.isToolItem()) {
286+
if (isNoFilter) {
285287
sourceItem = new SourceItem(null, -1, checkStack);
288+
sourceList.add(sourceItem);
289+
} else if (ingredient.isToolItem()) {
290+
sourceItem = new SourceItem(null, -1, checkStack);
291+
fallbackSourceList.add(sourceItem);
286292
}
287-
}
288-
289-
if (sourceItem != null) {
293+
} else {
290294
sourceList.add(sourceItem);
291295
}
292296
}
293297

298+
// Only include all tag variants for tools if there are no valid sources present
299+
if (sourceList.isEmpty()) {
300+
sourceList.addAll(fallbackSourceList);
301+
}
302+
294303
SourceItem sourceItem = !sourceList.isEmpty() ? sourceList.get(0) : null;
295304
if (sourceItem != null && sourceItem.getSourceProvider() != null) {
296305
sourceItem.getSourceProvider().markAsUsed(sourceItem, 1, inventories, requireBucket);
@@ -350,7 +359,8 @@ public static List<IKitchenItemProvider> getItemProviders(@Nullable KitchenMulti
350359
@SuppressWarnings("unchecked")
351360
public static <T extends Recipe<?>> T findFoodRecipe(InventoryCraftBook craftMatrix, Level level, RecipeType<T> recipeType, Item expectedItem) {
352361
for (Recipe<Container> recipe : recipeList) {
353-
if (recipe.getType() == recipeType && recipe.matches(craftMatrix, level) && recipe.getResultItem(level.registryAccess()).getItem() == expectedItem) {
362+
if (recipe.getType() == recipeType && recipe.matches(craftMatrix, level) && recipe.getResultItem(level.registryAccess())
363+
.getItem() == expectedItem) {
354364
return (T) recipe;
355365
}
356366
}

0 commit comments

Comments
 (0)