mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-14 05:33:56 +01:00
Improve performance of RecipeMap#removeRecipe
This commit is contained in:
parent
7acf73ce66
commit
9467a08b36
3 changed files with 37 additions and 16 deletions
|
@ -92,7 +92,7 @@
|
|||
|
||||
+ // CraftBukkit start
|
||||
+ public boolean removeRecipe(ResourceKey<Recipe<?>> mcKey) {
|
||||
+ boolean removed = this.recipes.removeRecipe(mcKey);
|
||||
+ boolean removed = this.recipes.removeRecipe((ResourceKey<Recipe<RecipeInput>>) (ResourceKey) mcKey); // Paper - generic fix
|
||||
+ if (removed) {
|
||||
+ this.finalizeRecipeLoading();
|
||||
+ }
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
public class RecipeMap {
|
||||
|
||||
@@ -35,11 +39,39 @@
|
||||
@@ -35,11 +39,56 @@
|
||||
com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder);
|
||||
}
|
||||
|
||||
|
@ -31,21 +31,38 @@
|
|||
+ }
|
||||
+ }
|
||||
+
|
||||
+ 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;
|
||||
+ }
|
||||
+ }
|
||||
+ removed |= this.byKey.remove(mcKey) != null;
|
||||
+
|
||||
+ return removed;
|
||||
+ }
|
||||
+ // 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;
|
||||
+ // }
|
||||
+ // }
|
||||
+ // removed |= this.byKey.remove(mcKey) != null;
|
||||
+ //
|
||||
+ // return removed;
|
||||
+ // }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+
|
||||
+ // Paper start - replace removeRecipe implementation
|
||||
+ 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;
|
||||
+ }
|
||||
+ 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???
|
||||
+ }
|
||||
+ // Paper end - replace removeRecipe implementation
|
||||
+
|
||||
public <I extends RecipeInput, T extends Recipe<I>> Collection<RecipeHolder<T>> byType(RecipeType<T> type) {
|
||||
- return this.byType.get(type);
|
||||
|
|
|
@ -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().reloadRecipes();
|
||||
// Paper end - correctly reload recipes
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue