2019-04-22 23:36:14 +02:00
|
|
|
From 9ba6775e3eddfd4b8af01471ce6cf7b3a658291a Mon Sep 17 00:00:00 2001
|
2019-02-28 03:06:04 +01:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Fri, 18 Jan 2019 00:08:15 -0500
|
|
|
|
Subject: [PATCH] Fix Custom Shapeless Custom Crafting Recipes
|
|
|
|
|
|
|
|
Mojang implemented Shapeless different than Shaped
|
|
|
|
|
|
|
|
This made the Bukkit RecipeChoice API not work for Shapeless.
|
|
|
|
|
|
|
|
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
|
2019-04-22 23:36:14 +02:00
|
|
|
index 819b4ac2da..ea4083a45a 100644
|
2019-02-28 03:06:04 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ShapelessRecipes.java
|
2019-02-28 06:02:20 +01:00
|
|
|
@@ -62,18 +62,47 @@ public class ShapelessRecipes implements IRecipe {
|
|
|
|
AutoRecipeStackManager autorecipestackmanager = new AutoRecipeStackManager();
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
+ // Paper start
|
2019-02-28 03:06:04 +01:00
|
|
|
+ java.util.List<ItemStack> providedItems = new java.util.ArrayList<>();
|
2019-02-28 06:02:20 +01:00
|
|
|
+ co.aikar.util.Counter<ItemStack> matchedProvided = new co.aikar.util.Counter<>();
|
|
|
|
+ co.aikar.util.Counter<RecipeItemStack> matchedIngredients = new co.aikar.util.Counter<>();
|
|
|
|
+ // Paper end
|
2019-02-28 03:06:04 +01:00
|
|
|
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()) {
|
|
|
|
- ++i;
|
|
|
|
- autorecipestackmanager.b(new ItemStack(itemstack.getItem()));
|
2019-02-28 06:02:20 +01:00
|
|
|
+ // Paper start
|
|
|
|
+ itemstack = itemstack.cloneItemStack();
|
|
|
|
+ providedItems.add(itemstack);
|
|
|
|
+ for (RecipeItemStack ingredient : ingredients) {
|
|
|
|
+ if (ingredient.test(itemstack)) {
|
|
|
|
+ matchedProvided.increment(itemstack);
|
|
|
|
+ matchedIngredients.increment(ingredient);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2019-02-28 03:06:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-
|
|
|
|
- return i == this.ingredients.size() && autorecipestackmanager.a(this, (IntList) null);
|
2019-02-28 06:02:20 +01:00
|
|
|
+ // Paper start
|
2019-02-28 03:06:04 +01:00
|
|
|
+ java.util.List<RecipeItemStack> ingredients = new java.util.ArrayList<>(this.ingredients);
|
2019-02-28 06:02:20 +01:00
|
|
|
+ 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)));
|
2019-02-28 03:06:04 +01:00
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2019-03-20 01:28:15 +01:00
|
|
|
2.21.0
|
2019-02-28 03:06:04 +01:00
|
|
|
|