Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Paper start
java.util.List<ItemStack> providedItems = new java.util.ArrayList<>();
co.aikar.util.Counter<ItemStack> matchedProvided = new co.aikar.util.Counter<>();
co.aikar.util.Counter<RecipeItemStack> matchedIngredients = new co.aikar.util.Counter<>();
// Paper end
for (int j = 0; j < iinventory.n(); ++j) {
for (int k = 0; k < iinventory.U_(); ++k) {
ItemStack itemstack = iinventory.getItem(k + j * iinventory.U_());
if (!itemstack.isEmpty()) {
// Paper start
itemstack = itemstack.cloneItemStack();
providedItems.add(itemstack);
for (RecipeItemStack ingredient : ingredients) {
if (ingredient.test(itemstack)) {
matchedProvided.increment(itemstack);
matchedIngredients.increment(ingredient);
}
}
// Paper end
}
}
}
// Paper start
java.util.List<RecipeItemStack> ingredients = new java.util.ArrayList<>(this.ingredients);
providedItems.sort(java.util.Comparator.comparingInt((ItemStack c) -> (int) matchedProvided.getCount(c)).reversed());
ingredients.sort(java.util.Comparator.comparingInt((RecipeItemStack c) -> (int) matchedIngredients.getCount(c)));
PROVIDED:
for (ItemStack provided : providedItems) {
for (Iterator<RecipeItemStack> itIngredient = ingredients.iterator(); itIngredient.hasNext(); ) {
RecipeItemStack ingredient = itIngredient.next();
if (ingredient.test(provided)) {
itIngredient.remove();
continue PROVIDED;
}
}
return false;
}
return ingredients.isEmpty();
// Paper end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.