9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-27 10:59:16 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0102-Carpet-Fixes-Use-optimized-RecipeManager.patch
Dreeam f5b95a6716 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b0da38c2 Repository details in RuntimeException for MavenLibraryResolver#addRepository (#12939)
PaperMC/Paper@1922be90 Update custom tags (#12183)
PaperMC/Paper@79cf1353 Ignore HopperInventorySearchEvent when it has no listeners (#13009)
PaperMC/Paper@ea014f7a feat: add stuckEntityPoiRetryDelay config (#12949)
PaperMC/Paper@a9e76749 Support for showNotification in PlayerRecipeDiscoverEvent (#12992)
PaperMC/Paper@5622c9dd Expose attribute sentiment (#12974)
PaperMC/Paper@42b653b1 Expose more argument types (#12665)
PaperMC/Paper@52d9a221 [ci/skip] Fix typo in Display javadoc (#13010)
PaperMC/Paper@614e9acf Improve APIs around riptide tridents (#12996)
PaperMC/Paper@51706e5a Fixed DyeItem sheep dye hunk
2025-08-25 15:52:00 -04:00

58 lines
3.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: nostalgic853 <yuu8583@proton.me>
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
Dreeam: Remove stream, better than original version
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 07d7c4737635f671f33b8f73001d67928fc75782..c30fafe40e52d1c5c713e48364dce6c9797443a2 100644
--- a/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
@@ -167,8 +167,20 @@ public class RecipeManager extends SimplePreparableReloadListener<RecipeMap> imp
public <I extends RecipeInput, T extends Recipe<I>> Optional<RecipeHolder<T>> getRecipeFor(RecipeType<T> recipeType, I input, Level level) {
// CraftBukkit start
- List<RecipeHolder<T>> list = this.recipes.getRecipesFor(recipeType, input, level).toList();
- return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority
+ // Leaf start - Carpet-Fixes - Use optimized RecipeManager - Remove streams to be faster
+ if (input.isEmpty()) {
+ return Optional.empty();
+ }
+
+ RecipeHolder<T> lastRecipe = null;
+ for (RecipeHolder<T> recipeHolder : this.recipes.byType(recipeType)) {
+ if (recipeHolder.value().matches(input, level)) {
+ lastRecipe = recipeHolder;
+ }
+ }
+
+ return lastRecipe != null ? Optional.of(lastRecipe) : Optional.empty();
+ // Leaf end - Carpet-Fixes - Use optimized RecipeManager - Remove streams to be faster
// CraftBukkit end
}
diff --git a/net/minecraft/world/item/crafting/RecipeMap.java b/net/minecraft/world/item/crafting/RecipeMap.java
index 098753ddd215b6ef5915fac71d8c4f0b19cf4142..0fb79f5a0284d5ef27a82eb7771b7acd3d36253e 100644
--- a/net/minecraft/world/item/crafting/RecipeMap.java
+++ b/net/minecraft/world/item/crafting/RecipeMap.java
@@ -73,6 +73,6 @@ public class RecipeMap {
}
public <I extends RecipeInput, T extends Recipe<I>> Stream<RecipeHolder<T>> getRecipesFor(RecipeType<T> type, I input, Level level) {
- return input.isEmpty() ? Stream.empty() : this.byType(type).stream().filter(recipeHolder -> recipeHolder.value().matches(input, level));
+ return input.isEmpty() ? Stream.empty() : this.byType(type).stream().filter(recipeHolder -> recipeHolder.value().matches(input, level)); // Leaf - Carpet-Fixes - Use optimized RecipeManager - diff on change
}
}