Skip to content

Commit

Permalink
Add RecipeUtils#ingredientMatches(Inventory;IntArrayList;DefaultedLis…
Browse files Browse the repository at this point in the history
…t;)Z
  • Loading branch information
FirstMegaGame4 committed Aug 5, 2023
1 parent 584844d commit ae5f53a
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mmodding.mmodding_lib.library.utils;

import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
Expand All @@ -9,7 +10,34 @@

public class RecipeUtils {

public static boolean ingredientMatches(Inventory inventory, Recipe<?> recipe, DefaultedList<Ingredient> ingredients, int outputCount) {
public static boolean ingredientMatches(Inventory inventory, IntArrayList recipeSlots, DefaultedList<Ingredient> ingredients) {
if (ingredients.size() == recipeSlots.size()) {
for (Ingredient ingredient : ingredients) {
boolean found = false;
for (int index = 0; index < recipeSlots.size(); index++) {
int slot = recipeSlots.getInt(index);
if (ingredient.test(inventory.getStack(slot))) {
recipeSlots.removeInt(index);
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
else {
return false;
}
}

public static boolean ingredientMatches(Inventory inventory, Recipe<?> recipe, DefaultedList<Ingredient> ingredients) {
return RecipeUtils.ingredientMatches(inventory, recipe, ingredients, 1);
}

public static boolean ingredientMatches(Inventory inventory, Recipe<?> recipe, DefaultedList<Ingredient> ingredients, int multiplier) {
RecipeMatcher matcher = new RecipeMatcher();
int counter = 0;

Expand All @@ -21,6 +49,8 @@ public static boolean ingredientMatches(Inventory inventory, Recipe<?> recipe, D
}
}

return ingredients.size() == counter && matcher.match(recipe, null, outputCount);
boolean test = ingredients.size() == counter && matcher.match(recipe, null, multiplier);
System.out.println(test);
return test;
}
}

0 comments on commit ae5f53a

Please sign in to comment.