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/net/minecraft/world/item/crafting/RecipeManager.java b/net/minecraft/world/item/crafting/RecipeManager.java index aefaac550b58be479cc282f52dea91d4b1e530f6..400d11b0a7266cee642546aa190553e60ad0723b 100644 --- a/net/minecraft/world/item/crafting/RecipeManager.java +++ b/net/minecraft/world/item/crafting/RecipeManager.java @@ -167,7 +167,7 @@ public class RecipeManager extends SimplePreparableReloadListener imp public > Optional> getRecipeFor(RecipeType recipeType, I input, Level level) { // CraftBukkit start - List> list = this.recipes.getRecipesFor(recipeType, input, level).toList(); + List> list = this.recipes.getRecipesForList(recipeType, input, level); // Leaf - Carpet-Fixes - Remove streams to be faster return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority // CraftBukkit end } diff --git a/net/minecraft/world/item/crafting/RecipeMap.java b/net/minecraft/world/item/crafting/RecipeMap.java index 098753ddd215b6ef5915fac71d8c4f0b19cf4142..c888daa9a8cdc8168cca173acb69b3c3919c5bda 100644 --- a/net/minecraft/world/item/crafting/RecipeMap.java +++ b/net/minecraft/world/item/crafting/RecipeMap.java @@ -75,4 +75,24 @@ public class RecipeMap { public > Stream> getRecipesFor(RecipeType type, I input, Level level) { return input.isEmpty() ? Stream.empty() : this.byType(type).stream().filter(recipeHolder -> recipeHolder.value().matches(input, level)); } + + // Leaf start - Carpet-Fixes - Remove streams to be faster + public > java.util.List> getRecipesForList(RecipeType type, I input, Level level) { + java.util.List> list; + + if (input.isEmpty()) { + return java.util.List.of(); + } else { + list = new java.util.ArrayList<>(); + } + + for (RecipeHolder recipeholder : this.byType(type)) { + if (recipeholder.value().matches(input, level)) { + list.add(recipeholder); + } + } + + return list; + } + // Leaf end - Carpet-Fixes - Remove streams to be faster }