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 f6dd363ececf967d282f5ba713013085da1ddf37..1e05a89a4e4e3a5d2fa9f7dc72fd89a9e0d93468 100644 --- a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java +++ b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java @@ -195,7 +195,7 @@ public class RecipeManager extends SimplePreparableReloadListener imp public > Optional> getRecipeFor(RecipeType type, I input, Level world) { // CraftBukkit start - List> list = this.recipes.getRecipesFor(type, input, world).toList(); + List> list = this.recipes.getRecipesForList(type, input, world); // 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/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java b/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java index c4067fbf827fed882772962a0e4b3ead0d642e62..c62ecec9bbc40f66b84d384bacf39d6d09e10a61 100644 --- a/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java +++ b/src/main/java/net/minecraft/world/item/crafting/RecipeMap.java @@ -105,4 +105,24 @@ public class RecipeMap { return recipeholder.value().matches(input, world); }); } + + // Leaf start - Carpet-Fixes - Remove streams to be faster + public > java.util.List> getRecipesForList(RecipeType type, I input, Level world) { + 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, world)) { + list.add(recipeholder); + } + } + + return list; + } + // Leaf end - Carpet-Fixes - Remove streams to be faster }