Update Improve-exact-choice-recipe-ingredients patch

This commit is contained in:
Nassim Jahnke 2024-12-17 12:32:56 +01:00
parent d37b5601d2
commit 4b51927783
No known key found for this signature in database
GPG key ID: EF6771C01F6EF02F

View file

@ -6,15 +6,12 @@ Subject: [PATCH] Improve exact choice recipe ingredients
Fixes exact choices not working with recipe book clicks Fixes exact choices not working with recipe book clicks
and shapeless recipes. and shapeless recipes.
== AT == diff --git a/io/papermc/paper/inventory/recipe/ItemOrExact.java b/io/papermc/paper/inventory/recipe/ItemOrExact.java
public net.minecraft.world.item.ItemStackLinkedSet TYPE_AND_TAG
diff --git a/src/main/java/io/papermc/paper/inventory/recipe/ItemOrExact.java b/src/main/java/io/papermc/paper/inventory/recipe/ItemOrExact.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 index 0000000000000000000000000000000000000000..ce745e49cd54fe3ae187785563a1bd311d14b5b2
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/inventory/recipe/ItemOrExact.java +++ b/io/papermc/paper/inventory/recipe/ItemOrExact.java
@@ -0,0 +0,0 @@ @@ -0,0 +1,63 @@
+package io.papermc.paper.inventory.recipe; +package io.papermc.paper.inventory.recipe;
+ +
+import net.minecraft.core.Holder; +import net.minecraft.core.Holder;
@ -78,12 +75,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+} +}
diff --git a/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java b/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java diff --git a/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java b/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 index 0000000000000000000000000000000000000000..f47c12e9dd6cfa857ca07a764edc22de372e25b6
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java +++ b/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java
@@ -0,0 +0,0 @@ @@ -0,0 +1,68 @@
+package io.papermc.paper.inventory.recipe; +package io.papermc.paper.inventory.recipe;
+ +
+import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap;
@ -152,92 +149,94 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return false; + return false;
+ } + }
+} +}
diff --git a/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java b/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java diff --git a/net/minecraft/recipebook/ServerPlaceRecipe.java b/net/minecraft/recipebook/ServerPlaceRecipe.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 6475509689439636275b06b9eac33f0922d8fcfd..6c398c91909f42e352e80d0781549df9d834a060 100644
--- a/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java --- a/net/minecraft/recipebook/ServerPlaceRecipe.java
+++ b/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java +++ b/net/minecraft/recipebook/ServerPlaceRecipe.java
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> { @@ -40,6 +40,7 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
return RecipeBookMenu.PostPlaceAction.NOTHING; return RecipeBookMenu.PostPlaceAction.NOTHING;
} else { } else {
StackedItemContents stackedItemContents = new StackedItemContents(); StackedItemContents stackedItemContents = new StackedItemContents();
+ stackedItemContents.initializeExtras(recipe.value(), null); // Paper - Improve exact choice recipe ingredients + stackedItemContents.initializeExtras(recipe.value(), null); // Paper - Improve exact choice recipe ingredients
inventory.fillStackedContents(stackedItemContents); inventory.fillStackedContents(stackedItemContents);
handler.fillCraftSlotsStackedContents(stackedItemContents); menu.fillCraftSlotsStackedContents(stackedItemContents);
return serverPlaceRecipe.tryPlaceRecipe(recipe, stackedItemContents); return serverPlaceRecipe.tryPlaceRecipe(recipe, stackedItemContents);
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> { @@ -99,7 +100,7 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
} }
int j = this.calculateAmountToCraft(i, bl); int i = this.calculateAmountToCraft(biggestCraftableStack, flag);
- List<Holder<Item>> list = new ArrayList<>(); - List<Holder<Item>> list = new ArrayList<>();
+ List<io.papermc.paper.inventory.recipe.ItemOrExact> list = new ArrayList<>(); // Paper - Improve exact choice recipe ingredients + List<io.papermc.paper.inventory.recipe.ItemOrExact> list = new ArrayList<>(); // Paper - Improve exact choice recipe ingredients
if (finder.canCraft(recipe.value(), j, list::add)) { if (stackedItemContents.canCraft(recipe.value(), i, list::add)) {
int k = clampToMaxStackSize(j, list); int i1 = clampToMaxStackSize(i, list);
if (k != j) { if (i1 != i) {
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> { @@ -114,7 +115,7 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
this.gridWidth, this.gridHeight, recipe.value(), recipe.value().placementInfo().slotsToIngredientIndex(), (slotx, index, x, y) -> { this.gridWidth, this.gridHeight, recipe.value(), recipe.value().placementInfo().slotsToIngredientIndex(), (item1, slot1, x, y) -> {
if (slotx != -1) { if (item1 != -1) {
Slot slot2 = this.inputGridSlots.get(index); Slot slot2 = this.inputGridSlots.get(slot1);
- Holder<Item> holder = list.get(slotx); - Holder<Item> holder = list.get(item1);
+ io.papermc.paper.inventory.recipe.ItemOrExact holder = list.get(slotx); // Paper - Improve exact choice recipe ingredients + io.papermc.paper.inventory.recipe.ItemOrExact holder = list.get(item1); // Paper - Improve exact choice recipe ingredients
int jx = k; int i2 = i1;
while (jx > 0) { while (i2 > 0) {
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> { @@ -129,9 +130,11 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
} }
} }
- private static int clampToMaxStackSize(int count, List<Holder<Item>> entries) { - private static int clampToMaxStackSize(int amount, List<Holder<Item>> items) {
- for (Holder<Item> holder : entries) { - for (Holder<Item> holder : items) {
- count = Math.min(count, holder.value().getDefaultMaxStackSize()); - amount = Math.min(amount, holder.value().getDefaultMaxStackSize());
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
+ private static int clampToMaxStackSize(int count, List<io.papermc.paper.inventory.recipe.ItemOrExact> entries) { + private static int clampToMaxStackSize(int amount, List<io.papermc.paper.inventory.recipe.ItemOrExact> items) {
+ for (io.papermc.paper.inventory.recipe.ItemOrExact holder : entries) { + for (io.papermc.paper.inventory.recipe.ItemOrExact holder : items) {
+ count = Math.min(count, holder.getMaxStackSize()); + amount = Math.min(amount, holder.getMaxStackSize());
+ // Paper end - Improve exact choice recipe ingredients + // Paper end - Improve exact choice recipe ingredients
} }
return count; return amount;
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> { @@ -160,7 +163,7 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
} }
} }
- private int moveItemToGrid(Slot slot, Holder<Item> item, int count) { - private int moveItemToGrid(Slot slot, Holder<Item> item, int count) {
+ private int moveItemToGrid(Slot slot, io.papermc.paper.inventory.recipe.ItemOrExact item, int count) { // Paper - Improve exact choice recipe ingredients + private int moveItemToGrid(Slot slot, io.papermc.paper.inventory.recipe.ItemOrExact item, int count) { // Paper - Improve exact choice recipe ingredients
ItemStack itemStack = slot.getItem(); ItemStack item1 = slot.getItem();
int i = this.inventory.findSlotMatchingCraftingIngredient(item, itemStack); int i = this.inventory.findSlotMatchingCraftingIngredient(item, item1);
if (i == -1) { if (i == -1) {
diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index e8522f5ccd69ff5513782a31a3b53219bc17b0e5..9a72651c5efefc6290ae14aa50ca79572d274562 100644
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java --- a/net/minecraft/world/entity/player/Inventory.java
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java +++ b/net/minecraft/world/entity/player/Inventory.java
@@ -0,0 +0,0 @@ public class Inventory implements Container, Nameable { @@ -178,12 +178,12 @@ public class Inventory implements Container, Nameable {
return !stack.isDamaged() && !stack.isEnchanted() && !stack.has(DataComponents.CUSTOM_NAME); return !stack.isDamaged() && !stack.isEnchanted() && !stack.has(DataComponents.CUSTOM_NAME);
} }
- public int findSlotMatchingCraftingIngredient(Holder<Item> item, ItemStack stack) { - public int findSlotMatchingCraftingIngredient(Holder<Item> item, ItemStack stack) {
+ public int findSlotMatchingCraftingIngredient(io.papermc.paper.inventory.recipe.ItemOrExact item, ItemStack stack) { // Paper - Improve exact choice recipe ingredients + public int findSlotMatchingCraftingIngredient(io.papermc.paper.inventory.recipe.ItemOrExact item, ItemStack stack) { // Paper - Improve exact choice recipe ingredients
for (int i = 0; i < this.items.size(); ++i) { for (int i = 0; i < this.items.size(); i++) {
ItemStack itemstack1 = (ItemStack) this.items.get(i); ItemStack itemStack = this.items.get(i);
if (!itemStack.isEmpty()
- if (!itemstack1.isEmpty() && itemstack1.is(item) && Inventory.isUsableForCrafting(itemstack1) && (stack.isEmpty() || ItemStack.isSameItemSameComponents(stack, itemstack1))) { - && itemStack.is(item)
+ if (!itemstack1.isEmpty() && item.matches(itemstack1) && (!(item instanceof io.papermc.paper.inventory.recipe.ItemOrExact.Item) || Inventory.isUsableForCrafting(itemstack1)) && (stack.isEmpty() || ItemStack.isSameItemSameComponents(stack, itemstack1))) { // Paper - Improve exact choice recipe ingredients - && isUsableForCrafting(itemStack)
+ && item.matches(itemStack) // Paper - Improve exact choice recipe ingredients
+ && (!(item instanceof io.papermc.paper.inventory.recipe.ItemOrExact.Item) || Inventory.isUsableForCrafting(itemStack)) // Paper - Improve exact choice recipe ingredients
&& (stack.isEmpty() || ItemStack.isSameItemSameComponents(stack, itemStack))) {
return i; return i;
} }
} diff --git a/net/minecraft/world/entity/player/StackedContents.java b/net/minecraft/world/entity/player/StackedContents.java
diff --git a/src/main/java/net/minecraft/world/entity/player/StackedContents.java b/src/main/java/net/minecraft/world/entity/player/StackedContents.java index a4b528574ab371af94b0e07819e471cec94da244..a3fea6c8397046596afe3c8b5589f2ed37fcdfc3 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/net/minecraft/world/entity/player/StackedContents.java
--- a/src/main/java/net/minecraft/world/entity/player/StackedContents.java +++ b/net/minecraft/world/entity/player/StackedContents.java
+++ b/src/main/java/net/minecraft/world/entity/player/StackedContents.java @@ -13,7 +13,7 @@ import java.util.List;
@@ -0,0 +0,0 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class StackedContents<T> { public class StackedContents<T> {
- public final Reference2IntOpenHashMap<T> amounts = new Reference2IntOpenHashMap<>(); - public final Reference2IntOpenHashMap<T> amounts = new Reference2IntOpenHashMap<>();
+ public final it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<T> amounts = new it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<>(); // Paper - Improve exact choice recipe ingredients (don't use "reference" map) + public final it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<T> amounts = new it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<>(); // Paper - Improve exact choice recipe ingredients (don't use "reference" map)
boolean hasAtLeast(T input, int minimum) { boolean hasAtLeast(T item, int amount) {
return this.amounts.getInt(input) >= minimum; return this.amounts.getInt(item) >= amount;
@@ -0,0 +0,0 @@ public class StackedContents<T> { @@ -49,7 +49,7 @@ public class StackedContents<T> {
List<T> getUniqueAvailableIngredientItems(Iterable<? extends StackedContents.IngredientInfo<T>> ingredients) { List<T> getUniqueAvailableIngredientItems(Iterable<? extends StackedContents.IngredientInfo<T>> ingredients) {
List<T> list = new ArrayList<>(); List<T> list = new ArrayList<>();
@ -246,7 +245,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (entry.getIntValue() > 0 && anyIngredientMatches(ingredients, entry.getKey())) { if (entry.getIntValue() > 0 && anyIngredientMatches(ingredients, entry.getKey())) {
list.add(entry.getKey()); list.add(entry.getKey());
} }
@@ -0,0 +0,0 @@ public class StackedContents<T> { @@ -71,13 +71,13 @@ public class StackedContents<T> {
@VisibleForTesting @VisibleForTesting
public int getResultUpperBound(List<? extends StackedContents.IngredientInfo<T>> ingredients) { public int getResultUpperBound(List<? extends StackedContents.IngredientInfo<T>> ingredients) {
int i = Integer.MAX_VALUE; int i = Integer.MAX_VALUE;
@ -255,18 +254,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
label31: label31:
for (StackedContents.IngredientInfo<T> ingredientInfo : ingredients) { for (StackedContents.IngredientInfo<T> ingredientInfo : ingredients) {
int j = 0; int i1 = 0;
- for (Entry<T> entry : objectIterable) { - for (Entry<T> entry : objectIterable) {
+ for (it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<T> entry : objectIterable) { // Paper - Improve exact choice recipe ingredients (don't use "reference" map) + for (it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<T> entry : objectIterable) { // Paper - Improve exact choice recipe ingredients (don't use "reference" map)
int k = entry.getIntValue(); int intValue = entry.getIntValue();
if (k > j) { if (intValue > i1) {
if (ingredientInfo.acceptsItem(entry.getKey())) { if (ingredientInfo.acceptsItem(entry.getKey())) {
diff --git a/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java b/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java diff --git a/net/minecraft/world/entity/player/StackedItemContents.java b/net/minecraft/world/entity/player/StackedItemContents.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 6bbe2e51ef71d193e0a5d3cace2b0ad1760ce759..83ccde54c625d40dc595e000c533f60aa929bd5a 100644
--- a/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java --- a/net/minecraft/world/entity/player/StackedItemContents.java
+++ b/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java +++ b/net/minecraft/world/entity/player/StackedItemContents.java
@@ -0,0 +0,0 @@ import net.minecraft.world.item.crafting.PlacementInfo; @@ -9,9 +9,14 @@ import net.minecraft.world.item.crafting.PlacementInfo;
import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.Recipe;
public class StackedItemContents { public class StackedItemContents {
@ -274,25 +273,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
+ private final StackedContents<io.papermc.paper.inventory.recipe.ItemOrExact> raw = new StackedContents<>(); + private final StackedContents<io.papermc.paper.inventory.recipe.ItemOrExact> raw = new StackedContents<>();
+ @Nullable + @Nullable
+ private io.papermc.paper.inventory.recipe.StackedContentsExtrasMap extrasMap = null; + private io.papermc.paper.inventory.recipe.StackedContentsExtrasMap extrasMap;
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
public void accountSimpleStack(ItemStack item) { public void accountSimpleStack(ItemStack stack) {
+ if (this.extrasMap != null && this.extrasMap.accountStack(item, Math.min(64, item.getCount()))) return; // Paper - Improve exact choice recipe ingredients; max of 64 due to accountStack method below + if (this.extrasMap != null && this.extrasMap.accountStack(stack, Math.min(64, stack.getCount()))) return; // Paper - Improve exact choice recipe ingredients; max of 64 due to accountStack method below
if (Inventory.isUsableForCrafting(item)) { if (Inventory.isUsableForCrafting(stack)) {
this.accountStack(item); this.accountStack(stack);
} }
@@ -0,0 +0,0 @@ public class StackedItemContents { @@ -24,34 +29,51 @@ public class StackedItemContents {
public void accountStack(ItemStack item, int maxCount) { public void accountStack(ItemStack stack, int maxStackSize) {
if (!item.isEmpty()) { if (!stack.isEmpty()) {
int i = Math.min(maxCount, item.getCount()); int min = Math.min(maxStackSize, stack.getCount());
- this.raw.account(item.getItemHolder(), i); - this.raw.account(stack.getItemHolder(), min);
+ if (this.extrasMap != null && !item.getComponentsPatch().isEmpty() && this.extrasMap.accountStack(item, i)) return; // Paper - Improve exact choice recipe ingredients; if an exact ingredient, don't include it + if (this.extrasMap != null && !stack.getComponentsPatch().isEmpty() && this.extrasMap.accountStack(stack, min)) return; // Paper - Improve exact choice recipe ingredients; if an exact ingredient, don't include it
+ this.raw.account(new io.papermc.paper.inventory.recipe.ItemOrExact.Item(item.getItemHolder()), i); + this.raw.account(new io.papermc.paper.inventory.recipe.ItemOrExact.Item(stack.getItemHolder()), min);
} }
} }
- public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> itemCallback) { - public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> output) {
+ public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output) { // Paper - Improve exact choice recipe ingredients
return this.canCraft(recipe, 1, output);
}
- public boolean canCraft(Recipe<?> recipe, int maxCount, @Nullable StackedContents.Output<Holder<Item>> output) {
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
+ public void initializeExtras(final Recipe<?> recipe, @Nullable final net.minecraft.world.item.crafting.CraftingInput input) { + public void initializeExtras(final Recipe<?> recipe, @Nullable final net.minecraft.world.item.crafting.CraftingInput input) {
+ if (this.extrasMap == null) { + if (this.extrasMap == null) {
@ -309,70 +313,64 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ // Paper end - Improve exact choice recipe ingredients + // Paper end - Improve exact choice recipe ingredients
+ +
+ public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients + public boolean canCraft(Recipe<?> recipe, int maxCount, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output) { // Paper - Improve exact choice recipe ingredients
return this.canCraft(recipe, 1, itemCallback);
}
- public boolean canCraft(Recipe<?> recipe, int quantity, @Nullable StackedContents.Output<Holder<Item>> itemCallback) {
+ public boolean canCraft(Recipe<?> recipe, int quantity, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients
PlacementInfo placementInfo = recipe.placementInfo(); PlacementInfo placementInfo = recipe.placementInfo();
return !placementInfo.isImpossibleToPlace() && this.canCraft(placementInfo.ingredients(), quantity, itemCallback); return !placementInfo.isImpossibleToPlace() && this.canCraft(placementInfo.ingredients(), maxCount, output);
} }
public boolean canCraft( - public boolean canCraft(List<? extends StackedContents.IngredientInfo<Holder<Item>>> ingredients, @Nullable StackedContents.Output<Holder<Item>> output) {
- List<? extends StackedContents.IngredientInfo<Holder<Item>>> rawIngredients, @Nullable StackedContents.Output<Holder<Item>> itemCallback + public boolean canCraft(List<? extends StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> ingredients, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output) { // Paper - Improve exact choice recipe ingredients
+ List<? extends StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> rawIngredients, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback // Paper - Improve exact choice recipe ingredients return this.canCraft(ingredients, 1, output);
) {
return this.canCraft(rawIngredients, 1, itemCallback);
} }
private boolean canCraft( private boolean canCraft(
- List<? extends StackedContents.IngredientInfo<Holder<Item>>> rawIngredients, int quantity, @Nullable StackedContents.Output<Holder<Item>> itemCallback - List<? extends StackedContents.IngredientInfo<Holder<Item>>> ingredients, int maxCount, @Nullable StackedContents.Output<Holder<Item>> output
+ List<? extends StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> rawIngredients, int quantity, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback // Paper - Improve exact choice recipe ingredients + List<? extends StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> ingredients, int maxCount, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output // Paper - Improve exact choice recipe ingredients
) { ) {
return this.raw.tryPick(rawIngredients, quantity, itemCallback); return this.raw.tryPick(ingredients, maxCount, output);
} }
- public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> itemCallback) { - public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> output) {
+ public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients + public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output) { // Paper - Improve exact choice recipe ingredients
return this.getBiggestCraftableStack(recipe, Integer.MAX_VALUE, itemCallback); return this.getBiggestCraftableStack(recipe, Integer.MAX_VALUE, output);
} }
- public int getBiggestCraftableStack(Recipe<?> recipe, int max, @Nullable StackedContents.Output<Holder<Item>> itemCallback) { - public int getBiggestCraftableStack(Recipe<?> recipe, int maxCount, @Nullable StackedContents.Output<Holder<Item>> output) {
+ public int getBiggestCraftableStack(Recipe<?> recipe, int max, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients + public int getBiggestCraftableStack(Recipe<?> recipe, int maxCount, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> output) { // Paper - Improve exact choice recipe ingredients
return this.raw.tryPickAll(recipe.placementInfo().ingredients(), max, itemCallback); return this.raw.tryPickAll(recipe.placementInfo().ingredients(), maxCount, output);
} }
diff --git a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java diff --git a/net/minecraft/world/item/crafting/Ingredient.java b/net/minecraft/world/item/crafting/Ingredient.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index e43641650d66a62b5b7b58c43833ce504970ab1e..879c8fe1f20decc793cfa39e686b61d521bd76ba 100644
--- a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java --- a/net/minecraft/world/item/crafting/Ingredient.java
+++ b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java +++ b/net/minecraft/world/item/crafting/Ingredient.java
@@ -0,0 +0,0 @@ import java.util.List; @@ -21,7 +21,7 @@ import net.minecraft.world.item.Items;
import javax.annotation.Nullable; import net.minecraft.world.item.crafting.display.SlotDisplay;
// CraftBukkit end import net.minecraft.world.level.ItemLike;
-public final class Ingredient implements StackedContents.IngredientInfo<Holder<Item>>, Predicate<ItemStack> { -public final class Ingredient implements StackedContents.IngredientInfo<Holder<Item>>, Predicate<ItemStack> {
+public final class Ingredient implements StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>, Predicate<ItemStack> { // Paper - Improve exact choice recipe ingredients +public final class Ingredient implements StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>, Predicate<ItemStack> { // Paper - Improve exact choice recipe ingredients
public static final StreamCodec<RegistryFriendlyByteBuf, Ingredient> CONTENTS_STREAM_CODEC = ByteBufCodecs.holderSet(Registries.ITEM)
public static final StreamCodec<RegistryFriendlyByteBuf, Ingredient> CONTENTS_STREAM_CODEC = ByteBufCodecs.holderSet(Registries.ITEM).map(Ingredient::new, (recipeitemstack) -> { .map(Ingredient::new, ingredient -> ingredient.values);
return recipeitemstack.values; public static final StreamCodec<RegistryFriendlyByteBuf, Optional<Ingredient>> OPTIONAL_CONTENTS_STREAM_CODEC = ByteBufCodecs.holderSet(Registries.ITEM)
@@ -0,0 +0,0 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I @@ -35,20 +35,24 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I
private final HolderSet<Item> values; private final HolderSet<Item> values;
// CraftBukkit start // CraftBukkit start
@Nullable @javax.annotation.Nullable
- private List<ItemStack> itemStacks; - private java.util.List<ItemStack> itemStacks;
+ private java.util.Set<ItemStack> itemStacks; // Paper - Improve exact choice recipe ingredients + private java.util.Set<ItemStack> itemStacks; // Paper - Improve exact choice recipe ingredients
public boolean isExact() { public boolean isExact() {
return this.itemStacks != null; return this.itemStacks != null;
} }
- public List<ItemStack> itemStacks() { @javax.annotation.Nullable
- public java.util.List<ItemStack> itemStacks() {
+ public java.util.Set<ItemStack> itemStacks() { // Paper - Improve exact choice recipe ingredients + public java.util.Set<ItemStack> itemStacks() { // Paper - Improve exact choice recipe ingredients
return this.itemStacks; return this.itemStacks;
} }
public static Ingredient ofStacks(List<ItemStack> stacks) { public static Ingredient ofStacks(java.util.List<ItemStack> stacks) {
Ingredient recipe = Ingredient.of(stacks.stream().map(ItemStack::getItem)); Ingredient recipe = Ingredient.of(stacks.stream().map(ItemStack::getItem));
- recipe.itemStacks = stacks; - recipe.itemStacks = stacks;
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
@ -383,29 +381,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return recipe; return recipe;
} }
// CraftBukkit end // CraftBukkit end
@@ -0,0 +0,0 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I @@ -81,21 +85,22 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I
public boolean test(ItemStack itemstack) { public boolean test(ItemStack stack) {
// CraftBukkit start // CraftBukkit start
if (this.isExact()) { if (this.isExact()) {
- for (ItemStack itemstack1 : this.itemStacks()) { - for (ItemStack itemstack1 : this.itemStacks()) {
- if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) { - if (itemstack1.getItem() == stack.getItem() && ItemStack.isSameItemSameComponents(stack, itemstack1)) {
- return true; - return true;
- } - }
- } - }
- -
- return false; - return false;
+ return this.itemStacks.contains(itemstack); // Paper - Improve exact choice recipe ingredients (hashing FTW!) + return this.itemStacks.contains(stack); // Paper - Improve exact choice recipe ingredients (hashing FTW!)
} }
// CraftBukkit end // CraftBukkit end
return itemstack.is(this.values); return stack.is(this.values);
} }
- public boolean acceptsItem(Holder<Item> holder) {
- return this.values.contains(holder);
+ // Paper start - Improve exact choice recipe ingredients + // Paper start - Improve exact choice recipe ingredients
+ @Override @Override
+ public boolean acceptsItem(final io.papermc.paper.inventory.recipe.ItemOrExact holder) { - public boolean acceptsItem(Holder<Item> item) {
+ return switch (holder) { - return this.values.contains(item);
+ public boolean acceptsItem(final io.papermc.paper.inventory.recipe.ItemOrExact itemOrExact) {
+ return switch (itemOrExact) {
+ case io.papermc.paper.inventory.recipe.ItemOrExact.Item(final Holder<Item> item) -> + case io.papermc.paper.inventory.recipe.ItemOrExact.Item(final Holder<Item> item) ->
+ !this.isExact() && this.values.contains(item); + !this.isExact() && this.values.contains(item);
+ case io.papermc.paper.inventory.recipe.ItemOrExact.Exact(final ItemStack exact) -> + case io.papermc.paper.inventory.recipe.ItemOrExact.Exact(final ItemStack exact) ->
@ -414,8 +412,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - Improve exact choice recipe ingredients + // Paper end - Improve exact choice recipe ingredients
} }
public boolean equals(Object object) { @Override
@@ -0,0 +0,0 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I @@ -120,6 +125,11 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I
} }
public SlotDisplay display() { public SlotDisplay display() {
@ -424,22 +422,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return new SlotDisplay.Composite(this.itemStacks().stream().<SlotDisplay>map(SlotDisplay.ItemStackSlotDisplay::new).toList()); + return new SlotDisplay.Composite(this.itemStacks().stream().<SlotDisplay>map(SlotDisplay.ItemStackSlotDisplay::new).toList());
+ } + }
+ // Paper end - show exact ingredients in recipe book + // Paper end - show exact ingredients in recipe book
return (SlotDisplay) this.values.unwrap().map(SlotDisplay.TagSlotDisplay::new, (list) -> { return (SlotDisplay)this.values
return new SlotDisplay.Composite(list.stream().map(Ingredient::displayForSingleItem).toList()); .unwrap()
}); .map(SlotDisplay.TagSlotDisplay::new, list -> new SlotDisplay.Composite(list.stream().map(Ingredient::displayForSingleItem).toList()));
diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java diff --git a/net/minecraft/world/item/crafting/ShapelessRecipe.java b/net/minecraft/world/item/crafting/ShapelessRecipe.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index fb317eafeed39adff793bffa8f6b21c37a32086c..d601b54b1de2f2ae44fe2b20c8116c71a6340e45 100644
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java --- a/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java +++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -0,0 +0,0 @@ public class ShapelessRecipe implements CraftingRecipe { @@ -72,13 +72,18 @@ public class ShapelessRecipe implements CraftingRecipe {
}
public boolean matches(CraftingInput input, Level world) { @Override
- return input.ingredientCount() != this.ingredients.size() ? false : (input.size() == 1 && this.ingredients.size() == 1 ? ((Ingredient) this.ingredients.getFirst()).test(input.getItem(0)) : input.stackedContents().canCraft((Recipe) this, (StackedContents.Output) null)); public boolean matches(CraftingInput input, Level level) {
+ // Paper start - Improve exact choice recipe ingredients & unwrap ternary + // Paper start - Improve exact choice recipe ingredients & unwrap ternary
+ if (input.ingredientCount() != this.ingredients.size()) { if (input.ingredientCount() != this.ingredients.size()) {
+ return false; return false;
+ } - } else {
- return input.size() == 1 && this.ingredients.size() == 1
- ? this.ingredients.getFirst().test(input.getItem(0))
- : input.stackedContents().canCraft(this, null);
}
+ if (input.size() == 1 && this.ingredients.size() == 1) { + if (input.size() == 1 && this.ingredients.size() == 1) {
+ return this.ingredients.getFirst().test(input.getItem(0)); + return this.ingredients.getFirst().test(input.getItem(0));
+ } + }
@ -450,4 +451,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - Improve exact choice recipe ingredients & unwrap ternary + // Paper end - Improve exact choice recipe ingredients & unwrap ternary
} }
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { @Override