9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-31 04:46:29 +00:00
Files
LeavesMC/patches/server/0044-Simpler-ShapelessRecipes-comparison-for-Vanilla.patch
2023-03-19 17:30:46 +08:00

91 lines
4.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Fri, 16 Sep 2022 16:34:11 +0800
Subject: [PATCH] Simpler ShapelessRecipes comparison for Vanilla
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
index f4f3f3a19d3cadaef1ae1a47daa68251a983dcf2..cad40fa0482f286d4b51e934ac639ea524a08455 100644
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -27,13 +27,21 @@ public class ShapelessRecipe implements CraftingRecipe {
final CraftingBookCategory category;
final ItemStack result;
final NonNullList<Ingredient> ingredients;
+ private final boolean isBukkit; // Leaves
public ShapelessRecipe(ResourceLocation id, String group, CraftingBookCategory category, ItemStack output, NonNullList<Ingredient> input) {
+ // Leaves start
+ this(id, group, category, output, input, false);
+ }
+
+ public ShapelessRecipe(ResourceLocation id, String group, CraftingBookCategory category, ItemStack output, NonNullList<Ingredient> input, boolean isBukkit) {
+ // Leaves end
this.id = id;
this.group = group;
this.category = category;
this.result = output;
this.ingredients = input;
+ this.isBukkit = isBukkit; // Leaves
}
// CraftBukkit start
@@ -82,6 +90,28 @@ public class ShapelessRecipe implements CraftingRecipe {
}
public boolean matches(CraftingContainer inventory, Level world) {
+ // Leaves start - easy match
+ if (top.leavesmc.leaves.LeavesConfig.simplerVanillaShapelessRecipes && !this.isBukkit) {
+ java.util.List<Ingredient> ingredients = com.google.common.collect.Lists.newArrayList(this.ingredients.toArray(new Ingredient[0]));
+
+ inventory: for (int index = 0; index < inventory.getContainerSize(); index++) {
+ ItemStack itemStack = inventory.getItem(index);
+
+ if (!itemStack.isEmpty()) {
+ for (int i = 0; i < ingredients.size(); i++) {
+ if (ingredients.get(i).test(itemStack)) {
+ ingredients.remove(i);
+ continue inventory;
+ }
+ }
+ return false;
+ }
+ }
+
+ return ingredients.isEmpty();
+ }
+ // Leaves end - easy match
+
StackedContents autorecipestackmanager = new StackedContents();
int i = 0;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
index f7ea77dd82d978ad307f99c743efacfb34478b3d..96be7a7b030b2f82ac91f0c5c8e66f282fd4d6bc 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
@@ -44,6 +44,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
data.set(i, toNMS(ingred.get(i), true));
}
- MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.ShapelessRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data));
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.ShapelessRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data, true)); // Leaves - is bukkit recipe
}
}
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index a2b13e51c96dc929ab3f0ddb89560398bbab23f5..3207f4787b0bad1122825a9b491de03e768e16ad 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -383,6 +383,11 @@ public final class LeavesConfig {
reduceChuckLoadAndLookup = getBoolean("settings.performance.reduce-chuck-load-and-lookup", reduceChuckLoadAndLookup);
}
+ public static boolean simplerVanillaShapelessRecipes = true;
+ private static void simplerVanillaShapelessRecipes() {
+ simplerVanillaShapelessRecipes = getBoolean("settings.performance.simpler-vanilla-shapeless-recipes", simplerVanillaShapelessRecipes);
+ }
+
public static final class WorldConfig {
public final String worldName;