mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
53 lines
2.9 KiB
Diff
53 lines
2.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
|
Date: Sat, 1 Feb 2025 19:17:31 +0300
|
|
Subject: [PATCH] Carpet-Fixes: RecipeManager Optimize
|
|
|
|
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 f2c82217811712625df594667330a73f8f44e261..d39ff67faf89f34dcb41769b268c3dafc1b6305b 100644
|
|
--- a/net/minecraft/world/item/crafting/RecipeManager.java
|
|
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
|
|
@@ -166,7 +166,7 @@ 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();
|
|
+ List<RecipeHolder<T>> list = this.recipes.getRecipesForList(recipeType, input, level); // DivineMC - 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..1778e58dca9430756d59d07bf017ebe4cc1f4ed4 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 <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));
|
|
}
|
|
+
|
|
+ // DivineMC start - Carpet-Fixes - Remove streams to be faster
|
|
+ public <I extends RecipeInput, T extends Recipe<I>> java.util.List<RecipeHolder<T>> getRecipesForList(RecipeType<T> type, I input, Level world) {
|
|
+ java.util.List<RecipeHolder<T>> list;
|
|
+
|
|
+ if (input.isEmpty()) {
|
|
+ return java.util.List.of();
|
|
+ } else {
|
|
+ list = new java.util.ArrayList<>();
|
|
+ }
|
|
+
|
|
+ for (RecipeHolder<T> recipeholder : this.byType(type)) {
|
|
+ if (recipeholder.value().matches(input, world)) {
|
|
+ list.add(recipeholder);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return list;
|
|
+ }
|
|
+ // DivineMC end - Carpet-Fixes - Remove streams to be faster
|
|
}
|