74 lines
4.1 KiB
Diff
74 lines
4.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Sun, 4 Aug 2024 22:15:50 +0800
|
|
Subject: [PATCH] Pufferfish Simpler ShapelessRecipes comparison for Vanilla
|
|
|
|
|
|
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 213ee4aa988dd4c2a5a7be99b1d13f67338e5209..8e46753af60aa9fd8e4b4c0f955f7a55a77de314 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
|
|
@@ -10,6 +10,7 @@ import net.minecraft.core.HolderLookup;
|
|
import net.minecraft.core.NonNullList;
|
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
+import net.minecraft.world.inventory.CraftingContainer;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.Level;
|
|
// CraftBukkit start
|
|
@@ -25,8 +26,13 @@ public class ShapelessRecipe extends io.papermc.paper.inventory.recipe.RecipeBoo
|
|
final CraftingBookCategory category;
|
|
final ItemStack result;
|
|
final NonNullList<Ingredient> ingredients;
|
|
+ private final boolean isBukkit; // Pufferfish
|
|
|
|
+ // Pufferfish start
|
|
public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, NonNullList<Ingredient> ingredients) {
|
|
+ this(group, category, result, ingredients, false);
|
|
+ }
|
|
+ public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, NonNullList<Ingredient> ingredients, boolean isBukkit) { this.isBukkit = isBukkit; // Pufferfish end
|
|
this.group = group;
|
|
this.category = category;
|
|
this.result = result;
|
|
@@ -76,6 +82,28 @@ public class ShapelessRecipe extends io.papermc.paper.inventory.recipe.RecipeBoo
|
|
}
|
|
|
|
public boolean matches(CraftingInput input, Level world) {
|
|
+ // Pufferfish start
|
|
+ if (!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 < input.size(); index++) {
|
|
+ ItemStack itemStack = input.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();
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
// Paper start - unwrap ternary & better exact choice recipes
|
|
if (input.ingredientCount() != this.ingredients.size()) {
|
|
return false;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
index 96d772eb02f79f8c478f5e6f065e387aa7665b18..c5ce412f321b8b4f31cc042893659e213b081f29 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
@@ -45,6 +45,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
|
|
data.set(i, this.toNMS(ingred.get(i), true));
|
|
}
|
|
|
|
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
|
|
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data, true))); // Pufferfish
|
|
}
|
|
}
|