From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: nostalgic853 Date: Tue, 25 Oct 2022 00:57:45 +0800 Subject: [PATCH] Carpet-Fixes: Use optimized RecipeManager This patch is based on the following mixin: "carpetfixes/mixins/optimizations/RecipeManager_fasterMixin.java" By: fxmorin <28154542+fxmorin@users.noreply.github.com> Original license: MIT Original project: https://github.com/fxmorin/carpet-fixes Optimized the RecipeManager getFirstMatch call to be up to 3x faster This is a fully vanilla optimization. Improves: [Blast]Furnace/Campfire/Smoker/Stonecutter/Crafting/Sheep Color Choosing 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 index de7c77c1b25680ecc65f0f43f2391aff269a974f..febf87b14125925f548393360e89077329a6c522 100644 --- a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java +++ b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java @@ -128,16 +128,24 @@ public class RecipeManager extends SimpleJsonResourceReloadListener { } public > List> getAllRecipesFor(RecipeType type) { - return List.copyOf(this.byType(type)); + return new java.util.ArrayList<>(this.byType(type)); // Leaf - Carpet-Fixes } + // Leaf start - Remove streams to be faster public > List> getRecipesFor(RecipeType type, I input, Level world) { - return (List) this.byType(type).stream().filter((recipeholder) -> { - return recipeholder.value().matches(input, world); - }).sorted(Comparator.comparing((recipeholder) -> { - return recipeholder.value().getResultItem(world.registryAccess()).getDescriptionId(); - })).collect(Collectors.toList()); + List> list = new java.util.ArrayList<>(); + + for (RecipeHolder recipeholder : this.byType(type)) { + if (recipeholder.value().matches(input, world)) { + list.add(recipeholder); + } + } + + list.sort(Comparator.comparing((recipeholder) -> recipeholder.value().getResultItem(world.registryAccess()).getDescriptionId())); + + return list; } + // Leaf end - Remove streams to be faster private > Collection> byType(RecipeType type) { return (Collection) this.byType.get(type); // CraftBukkit - decompile error