Improve reliability of Shapeless Recipe logic
per feedback from @liach about a bug with vanillas previous logic that we essentially just reverted to. complex recipes could run into cases where a recipe that does have enough items can be unsatisfied if the items are in certain orders, making them not truely shapeless. this scenario doesn't occur in vanilla, but users can load custom recipes. this improves the logic to do some sorting on the lists to improve chances of matching the recipes harder ingredients before the easier to satisfy ingredients. the likelyhood of someone adding a recipe that still fails this is too extreme to care about. i doubt mojangs implementation is perfect either. we can improve this logic more later if we actually get bug reports on it.
This commit is contained in:
parent
4785ef6474
commit
47c6e17d45
1 changed files with 23 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
From 270c7bb8936f603c5f8700598807bb20482ed4d8 Mon Sep 17 00:00:00 2001
|
From 9c0b5a16f11a586c971b39cc33157c1360184145 Mon Sep 17 00:00:00 2001
|
||||||
From: Aikar <aikar@aikar.co>
|
From: Aikar <aikar@aikar.co>
|
||||||
Date: Fri, 18 Jan 2019 00:08:15 -0500
|
Date: Fri, 18 Jan 2019 00:08:15 -0500
|
||||||
Subject: [PATCH] Fix Custom Shapeless Custom Crafting Recipes
|
Subject: [PATCH] Fix Custom Shapeless Custom Crafting Recipes
|
||||||
|
@ -10,18 +10,18 @@ This made the Bukkit RecipeChoice API not work for Shapeless.
|
||||||
This reimplements vanilla logic using the same test logic as Shaped
|
This reimplements vanilla logic using the same test logic as Shaped
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/ShapelessRecipes.java b/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
diff --git a/src/main/java/net/minecraft/server/ShapelessRecipes.java b/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
||||||
index 819b4ac2da..1dc9a1c93c 100644
|
index 819b4ac2da..ea4083a45a 100644
|
||||||
--- a/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
--- a/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
||||||
+++ b/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
+++ b/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
||||||
@@ -59,21 +59,32 @@ public class ShapelessRecipes implements IRecipe {
|
@@ -62,18 +62,47 @@ public class ShapelessRecipes implements IRecipe {
|
||||||
if (!(iinventory instanceof InventoryCrafting)) {
|
AutoRecipeStackManager autorecipestackmanager = new AutoRecipeStackManager();
|
||||||
return false;
|
int i = 0;
|
||||||
} else {
|
|
||||||
- AutoRecipeStackManager autorecipestackmanager = new AutoRecipeStackManager();
|
+ // Paper start
|
||||||
- int i = 0;
|
|
||||||
-
|
|
||||||
+ // Paper start - use RecipeItemStack.test
|
|
||||||
+ java.util.List<ItemStack> providedItems = new java.util.ArrayList<>();
|
+ 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 j = 0; j < iinventory.n(); ++j) {
|
||||||
for (int k = 0; k < iinventory.U_(); ++k) {
|
for (int k = 0; k < iinventory.U_(); ++k) {
|
||||||
ItemStack itemstack = iinventory.getItem(k + j * iinventory.U_());
|
ItemStack itemstack = iinventory.getItem(k + j * iinventory.U_());
|
||||||
|
@ -29,13 +29,25 @@ index 819b4ac2da..1dc9a1c93c 100644
|
||||||
if (!itemstack.isEmpty()) {
|
if (!itemstack.isEmpty()) {
|
||||||
- ++i;
|
- ++i;
|
||||||
- autorecipestackmanager.b(new ItemStack(itemstack.getItem()));
|
- autorecipestackmanager.b(new ItemStack(itemstack.getItem()));
|
||||||
+ providedItems.add(itemstack.cloneItemStack());
|
+ // Paper start
|
||||||
|
+ itemstack = itemstack.cloneItemStack();
|
||||||
|
+ providedItems.add(itemstack);
|
||||||
|
+ for (RecipeItemStack ingredient : ingredients) {
|
||||||
|
+ if (ingredient.test(itemstack)) {
|
||||||
|
+ matchedProvided.increment(itemstack);
|
||||||
|
+ matchedIngredients.increment(ingredient);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-
|
-
|
||||||
- return i == this.ingredients.size() && autorecipestackmanager.a(this, (IntList) null);
|
- return i == this.ingredients.size() && autorecipestackmanager.a(this, (IntList) null);
|
||||||
|
+ // Paper start
|
||||||
+ java.util.List<RecipeItemStack> ingredients = new java.util.ArrayList<>(this.ingredients);
|
+ 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:
|
+ PROVIDED:
|
||||||
+ for (ItemStack provided : providedItems) {
|
+ for (ItemStack provided : providedItems) {
|
||||||
|
|
Loading…
Reference in a new issue