107 lines
5.4 KiB
Diff
107 lines
5.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: IPECTER <ipectert@gmail.com>
|
|
Date: Wed, 6 Sep 2023 16:23:56 +0900
|
|
Subject: [PATCH] CarpetFixes-Optimizations-RecipeManager
|
|
|
|
Original: fxmorin/carpet-fixes
|
|
Copyright (C) 2023 fxmorin
|
|
|
|
RecipeManager optimization.
|
|
Optimized by taking out streams & doing extra early checks to quickly remove unrelated recipes
|
|
|
|
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 9ffb6999171f602f0b113dac40e0130410cad870..49b5fece692cd5da99ed21d7fd0864cea1609495 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/RecipeManager.java
|
|
@@ -103,13 +103,38 @@ public class RecipeManager extends SimpleJsonResourceReloadListener {
|
|
}
|
|
|
|
public <C extends Container, T extends Recipe<C>> Optional<T> getRecipeFor(RecipeType<T> type, C inventory, Level world) {
|
|
- // CraftBukkit start
|
|
- Optional<T> recipe = this.byType(type).values().stream().filter((irecipe) -> {
|
|
- return irecipe.matches(inventory, world);
|
|
- }).findFirst();
|
|
- inventory.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found
|
|
- // CraftBukkit end
|
|
- return recipe;
|
|
+ // Plazma start - CarpetFixes - Optimized RecipeManager
|
|
+ if (world.plazmaLevelConfiguration().carpetFixes.optimizedRecipeManager() && type == RecipeType.CRAFTING) {
|
|
+ int slots = 0;
|
|
+ int count;
|
|
+ //compare size to quickly remove recipes that are not even close. Plus remove streams
|
|
+ for (int slot = 0; slot < inventory.getContainerSize(); slot++)
|
|
+ if (!inventory.getItem(slot).isEmpty()) slots++;
|
|
+ for (Recipe<C> recipe : this.byType(type).values()) {
|
|
+ count = 0;
|
|
+ if (recipe instanceof CustomRecipe) {
|
|
+ if (recipe.matches(inventory, world)) {
|
|
+ return (Optional<T>) Optional.of(recipe);
|
|
+ }
|
|
+ } else {
|
|
+ for (Ingredient ingredient : recipe.getIngredients())
|
|
+ if (ingredient != Ingredient.EMPTY) count++;
|
|
+ if (count == slots && recipe.matches(inventory, world)) {
|
|
+ return (Optional<T>) Optional.of(recipe);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return Optional.empty();
|
|
+ } else {
|
|
+ // CraftBukkit start
|
|
+ Optional<T> recipe = this.byType(type).values().stream().filter((irecipe) -> {
|
|
+ return irecipe.matches(inventory, world);
|
|
+ }).findFirst();
|
|
+ inventory.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found
|
|
+ // CraftBukkit end
|
|
+ return recipe;
|
|
+ }
|
|
+ // Plazma end
|
|
}
|
|
|
|
public <C extends Container, T extends Recipe<C>> Optional<Pair<ResourceLocation, T>> getRecipeFor(RecipeType<T> type, C inventory, Level world, @Nullable ResourceLocation id) {
|
|
@@ -134,7 +159,7 @@ public class RecipeManager extends SimpleJsonResourceReloadListener {
|
|
}
|
|
|
|
public <C extends Container, T extends Recipe<C>> List<T> getAllRecipesFor(RecipeType<T> type) {
|
|
- return List.copyOf(this.byType(type).values());
|
|
+ return org.plazmamc.plazma.configurations.GlobalConfiguration.get().carpetFixes.optimizedRecipeManager() ? (List<T>) new java.util.ArrayList<>(this.byType(type).values()) : List.copyOf(this.byType(type).values()); // Plazma start - CarpetFixes - Optimized RecipeManager
|
|
}
|
|
|
|
public <C extends Container, T extends Recipe<C>> List<T> getRecipesFor(RecipeType<T> type, C inventory, Level world) {
|
|
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
index d329f77ab19ac781506c26909591fa4ae9dabb1e..36511f71fcf3a8a5da746dd087003861a4f0a8f4 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
@@ -83,10 +83,15 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
|
|
public boolean enabled = DO_OPTIMIZE;
|
|
boolean optimizedBiomeAccess = true;
|
|
+ boolean optimizedRecipeManager = true;
|
|
|
|
public boolean optimizedBiomeAccess() {
|
|
return enabled && optimizedBiomeAccess;
|
|
}
|
|
|
|
+ public boolean optimizedRecipeManager() {
|
|
+ return enabled && optimizedRecipeManager;
|
|
+ }
|
|
+
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java
|
|
index b0deec445b5ea3cd3e4802eca04e99818b539bd8..e089a881600b61060bae1135b89703f6c0b5c7e8 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java
|
|
@@ -137,6 +137,11 @@ public class LevelConfigurations extends ConfigurationPart {
|
|
public class CarpetFixes extends ConfigurationPart {
|
|
|
|
public boolean enabled = DO_OPTIMIZE;
|
|
+ boolean optimizedRecipeManager = true;
|
|
+
|
|
+ public boolean optimizedRecipeManager() {
|
|
+ return enabled && optimizedRecipeManager;
|
|
+ }
|
|
|
|
}
|
|
}
|