-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of RecipeMap#removeRecipe
- Loading branch information
1 parent
16d7d73
commit 102bfe4
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
patches/server/1059-Improve-performance-of-RecipeMap-removeRecipe.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
Date: Thu, 31 Oct 2024 20:36:41 -0700 | ||
Subject: [PATCH] Improve performance of RecipeMap#removeRecipe | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java b/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java | ||
index 5d842d7e774564143f9f3be6c2628d54595a235b..e01b01a6582a87503495c5017c7e6cbbcb12a902 100644 | ||
--- a/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java | ||
+++ b/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java | ||
@@ -54,19 +54,19 @@ public class RecipeMap { | ||
} | ||
} | ||
|
||
- public boolean removeRecipe(ResourceKey<Recipe<?>> mcKey) { | ||
- boolean removed = false; | ||
- Iterator<RecipeHolder<?>> iter = this.byType.values().iterator(); | ||
- while (iter.hasNext()) { | ||
- RecipeHolder<?> recipe = iter.next(); | ||
- if (recipe.id().equals(mcKey)) { | ||
- iter.remove(); | ||
- removed = true; | ||
- } | ||
+ // Paper start - why are you using a loop??? | ||
+ public <T extends RecipeInput> boolean removeRecipe(ResourceKey<Recipe<T>> mcKey) { | ||
+ //noinspection unchecked | ||
+ final RecipeHolder<Recipe<T>> remove = (RecipeHolder<Recipe<T>>) this.byKey.remove(mcKey); | ||
+ if (remove == null) { | ||
+ return false; | ||
} | ||
- removed |= this.byKey.remove(mcKey) != null; | ||
- | ||
- return removed; | ||
+ final Collection<? extends RecipeHolder<? extends Recipe<T>>> recipes = this.byType(remove.value().getType()); | ||
+ if (recipes.remove(remove)) { | ||
+ return true; | ||
+ } | ||
+ return false; | ||
+ // Paper end - why are you using a loop??? | ||
} | ||
// CraftBukkit end | ||
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java | ||
index c0433e054e64c329dff670c8f7ca21c4a4133c6f..6c8c5d6d06d0f92fd7c8010ad5a339200307d003 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java | ||
@@ -32,5 +32,9 @@ public class RecipeIterator implements Iterator<Recipe> { | ||
public void remove() { | ||
MinecraftServer.getServer().getRecipeManager().recipes.byKey.remove(this.currentRecipe.id()); // Paper - fix removing recipes from RecipeIterator | ||
this.recipes.remove(); | ||
+ // Paper start - correctly reload recipes | ||
+ MinecraftServer.getServer().getRecipeManager().finalizeRecipeLoading(); | ||
+ MinecraftServer.getServer().getPlayerList().reloadRecipeData(); | ||
+ // Paper end - correctly reload recipes | ||
} | ||
} |