Fixed StackOverflowError in RecipeManager

This commit is contained in:
nostalgic853
2022-10-25 15:50:09 +08:00
parent 9e1544d3aa
commit f45c9d35c8

View File

@@ -11,7 +11,7 @@ This is a fully vanilla optimization. Improves: [Blast]Furnace/Campfire/Smoker/S
This was mostly made for the auto crafting table, since the performance boost is much more visible while using that mod This was mostly made for the auto crafting table, since the performance boost is much more visible while using that mod
diff --git a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java diff --git a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java
index 4872f70977e73c889fe6e2339d00ebc64459613d..3e9cce51080addf294abab30532244628a9c63a2 100644 index 4872f70977e73c889fe6e2339d00ebc64459613d..7f6bd5fb335ea33c52d510461a1f17371c36576a 100644
--- a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java --- a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java +++ b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java
@@ -11,14 +11,7 @@ import com.google.gson.JsonParseException; @@ -11,14 +11,7 @@ import com.google.gson.JsonParseException;
@@ -54,7 +54,7 @@ index 4872f70977e73c889fe6e2339d00ebc64459613d..3e9cce51080addf294abab3053224462
+ //compare size to quickly remove recipes that are not even close. Plus remove streams + //compare size to quickly remove recipes that are not even close. Plus remove streams
+ for (int slot = 0; slot < inventory.getContainerSize(); slot++) + for (int slot = 0; slot < inventory.getContainerSize(); slot++)
+ if (!inventory.getItem(slot).isEmpty()) slots++; + if (!inventory.getItem(slot).isEmpty()) slots++;
+ for (Recipe<C> recipe : this.getAllRecipesFor(type)) { + for (Recipe<C> recipe : this.byType(type).values()) {
+ count = 0; + count = 0;
+ if (recipe instanceof CustomRecipe) { + if (recipe instanceof CustomRecipe) {
+ if (recipe.matches(inventory, world)) { + if (recipe.matches(inventory, world)) {
@@ -78,7 +78,7 @@ index 4872f70977e73c889fe6e2339d00ebc64459613d..3e9cce51080addf294abab3053224462
public <C extends Container, T extends Recipe<C>> List<T> getAllRecipesFor(RecipeType<T> type) { public <C extends Container, T extends Recipe<C>> List<T> getAllRecipesFor(RecipeType<T> type) {
- return List.copyOf(this.byType(type).values()); - return List.copyOf(this.byType(type).values());
+ return new ArrayList<>(this.getAllRecipesFor(type)); // KeYi + return new ArrayList<>(this.byType(type).values()); // KeYi
} }
public <C extends Container, T extends Recipe<C>> List<T> getRecipesFor(RecipeType<T> type, C inventory, Level world) { public <C extends Container, T extends Recipe<C>> List<T> getRecipesFor(RecipeType<T> type, C inventory, Level world) {