PaperMC/patches/unapplied/server/Improve-exact-choice-recipe-ingredients.patch

437 lines
25 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 25 Jun 2023 23:10:14 -0700
Subject: [PATCH] Improve exact choice recipe ingredients
Fixes exact choices not working with recipe book clicks
and shapeless recipes.
Feature patch
== AT ==
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
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/io/papermc/paper/inventory/recipe/ItemOrExact.java
@@ -0,0 +0,0 @@
+package io.papermc.paper.inventory.recipe;
+
+import net.minecraft.core.Holder;
+import net.minecraft.world.item.ItemStack;
+
+public sealed interface ItemOrExact permits ItemOrExact.Item, ItemOrExact.Exact {
+
+ int getMaxStackSize();
+
+ boolean matches(ItemStack stack);
+
+ record Item(Holder<net.minecraft.world.item.Item> item) implements ItemOrExact {
+
+ public Item(final ItemStack stack) {
+ this(stack.getItemHolder());
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return this.item.value().getDefaultMaxStackSize();
+ }
+
+ @Override
+ public boolean matches(final ItemStack stack) {
+ return stack.is(this.item) && stack.getComponentsPatch().isEmpty();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof final Item otherItem)) return false;
+ return this.item.equals(otherItem.item());
+ }
+
+ @Override
+ public int hashCode() {
+ return this.item.hashCode();
+ }
+ }
+
+ record Exact(ItemStack stack) implements ItemOrExact {
+
+ @Override
+ public int getMaxStackSize() {
+ return this.stack.getMaxStackSize();
+ }
+
+ @Override
+ public boolean matches(final ItemStack stack) {
+ return ItemStack.isSameItemSameComponents(this.stack, stack);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof final Exact otherExact)) return false;
+ return ItemStack.isSameItemSameComponents(this.stack, otherExact.stack);
+ }
+
+ @Override
+ public int hashCode() {
+ return ItemStack.hashItemAndComponents(this.stack);
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java b/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/io/papermc/paper/inventory/recipe/StackedContentsExtrasMap.java
@@ -0,0 +0,0 @@
+package io.papermc.paper.inventory.recipe;
+
+import it.unimi.dsi.fastutil.objects.Object2IntMap;
+import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
+import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectSet;
+import net.minecraft.world.entity.player.StackedContents;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.ItemStackLinkedSet;
+import net.minecraft.world.item.crafting.CraftingInput;
+import net.minecraft.world.item.crafting.Recipe;
+
+public final class StackedContentsExtrasMap {
+
+ private final StackedContents<ItemOrExact> contents;
+ public Object2IntMap<ItemOrExact.Item> regularRemoved = new Object2IntOpenHashMap<>(); // needed for re-using the regular contents (for ShapelessRecipe)
+ public final ObjectSet<ItemStack> exactIngredients = new ObjectOpenCustomHashSet<>(ItemStackLinkedSet.TYPE_AND_TAG);
+
+ public StackedContentsExtrasMap(final StackedContents<ItemOrExact> contents) {
+ this.contents = contents;
+ }
+
+ public void initialize(final Recipe<?> recipe) {
+ this.exactIngredients.clear();
+ for (final StackedContents.IngredientInfo<ItemOrExact> info : recipe.placementInfo().unpackedIngredients()) {
+ if (info.isExact()) {
+ this.exactIngredients.addAll(info.allowedItems().stream().map(o -> ((ItemOrExact.Exact) o).stack()).toList());
+ }
+ }
+ }
+
+ public void accountInput(final CraftingInput input) {
+ // similar logic to the CraftingInput constructor
+ for (final ItemStack item : input.items()) {
+ if (!item.isEmpty()) {
+ if (this.accountStack(item, 1)) {
+ // if stack was accounted for as an exact ingredient, don't include it in the regular contents
+ final ItemOrExact.Item asItem = new ItemOrExact.Item(item);
+ if (this.contents.amounts.containsKey(asItem)) {
+ final int amount = this.contents.amounts.removeInt(asItem);
+ this.regularRemoved.put(asItem, amount);
+ }
+ }
+ }
+ }
+ }
+
+ public void resetExtras() {
+ // clear previous extra ids
+ for (final ItemStack extra : this.exactIngredients) {
+ this.contents.amounts.removeInt(new ItemOrExact.Exact(extra));
+ }
+ for (final Object2IntMap.Entry<ItemOrExact.Item> entry : this.regularRemoved.object2IntEntrySet()) {
+ this.contents.amounts.addTo(entry.getKey(), entry.getIntValue());
+ }
+ this.exactIngredients.clear();
+ this.regularRemoved.clear();
+ }
+
+ public boolean accountStack(final ItemStack stack, final int count) {
+ if (this.exactIngredients.contains(stack)) {
+ this.contents.account(new ItemOrExact.Exact(stack), count);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java b/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java
+++ b/src/main/java/net/minecraft/recipebook/ServerPlaceRecipe.java
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
return RecipeBookMenu.PostPlaceAction.NOTHING;
} else {
StackedItemContents stackedItemContents = new StackedItemContents();
+ stackedItemContents.initializeExtras(recipe.value(), null); // Paper - Improve exact choice recipe ingredients
inventory.fillStackedContents(stackedItemContents);
handler.fillCraftSlotsStackedContents(stackedItemContents);
return serverPlaceRecipe.tryPlaceRecipe(recipe, stackedItemContents);
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
}
int j = this.calculateAmountToCraft(i, bl);
- List<Holder<Item>> list = new ArrayList<>();
+ List<io.papermc.paper.inventory.recipe.ItemOrExact> list = new ArrayList<>(); // Paper - Improve exact choice recipe ingredients
if (finder.canCraft(recipe.value(), j, list::add)) {
- OptionalInt optionalInt = list.stream().mapToInt(item -> item.value().getDefaultMaxStackSize()).min();
+ OptionalInt optionalInt = list.stream().mapToInt(io.papermc.paper.inventory.recipe.ItemOrExact::getMaxStackSize).min(); // Paper - Improve exact choice recipe ingredients
if (optionalInt.isPresent()) {
j = Math.min(j, optionalInt.getAsInt());
}
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
int kx = k;
while (kx > 0) {
- Holder<Item> holder = list.get(jx);
+ io.papermc.paper.inventory.recipe.ItemOrExact holder = list.get(jx); // Paper - Improve exact choice recipe ingredients
kx = this.moveItemToGrid(slot2, holder, kx);
if (kx == -1) {
return;
@@ -0,0 +0,0 @@ public class ServerPlaceRecipe<R extends Recipe<?>> {
}
}
- 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
int i = this.inventory.findSlotMatchingCraftingIngredient(item);
if (i == -1) {
return -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
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
@@ -0,0 +0,0 @@ public class Inventory implements Container, Nameable {
return !stack.isDamaged() && !stack.isEnchanted() && !stack.has(DataComponents.CUSTOM_NAME);
}
- public int findSlotMatchingCraftingIngredient(Holder<Item> item) {
+ public int findSlotMatchingCraftingIngredient(io.papermc.paper.inventory.recipe.ItemOrExact item) { // Paper - Improve exact choice recipe ingredients
for (int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack = (ItemStack) this.items.get(i);
- if (!itemstack.isEmpty() && itemstack.is(item) && Inventory.isUsableForCrafting(itemstack)) {
+ if (!itemstack.isEmpty() && item.matches(itemstack) && (!(item instanceof io.papermc.paper.inventory.recipe.ItemOrExact.Item) || isUsableForCrafting(itemstack))) { // Paper - Improve exact choice recipe ingredients
return i;
}
}
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/player/StackedContents.java
+++ b/src/main/java/net/minecraft/world/entity/player/StackedContents.java
@@ -0,0 +0,0 @@ import java.util.Set;
import javax.annotation.Nullable;
public class StackedContents<T> {
- 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)
boolean hasAnyAmount(T input) {
return this.amounts.getInt(input) > 0;
@@ -0,0 +0,0 @@ public class StackedContents<T> {
this.put(input, count);
}
- public static record IngredientInfo<T>(List<T> allowedItems) {
- public IngredientInfo(List<T> allowedItems) {
+ public static record IngredientInfo<T>(List<T> allowedItems, boolean isExact) { // Paper - Improve exact choice recipe ingredients
+ public IngredientInfo(List<T> allowedItems, boolean isExact) { // Paper - Improve exact choice recipe ingredients
if (allowedItems.isEmpty()) {
throw new IllegalArgumentException("Ingredients can't be empty");
} else {
this.allowedItems = allowedItems;
+ this.isExact = isExact; // Paper - Improve exact choice recipe ingredients
}
}
}
diff --git a/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java b/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java
+++ b/src/main/java/net/minecraft/world/entity/player/StackedItemContents.java
@@ -0,0 +0,0 @@ import net.minecraft.world.item.crafting.PlacementInfo;
import net.minecraft.world.item.crafting.Recipe;
public class StackedItemContents {
- private final StackedContents<Holder<Item>> raw = new StackedContents<>();
+ // Paper start - Improve exact choice recipe ingredients
+ private final StackedContents<io.papermc.paper.inventory.recipe.ItemOrExact> raw = new StackedContents<>();
+ @Nullable
+ private io.papermc.paper.inventory.recipe.StackedContentsExtrasMap extrasMap = null;
+ // Paper start - Improve exact choice recipe ingredients
public void accountSimpleStack(ItemStack item) {
+ 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 (Inventory.isUsableForCrafting(item)) {
this.accountStack(item);
}
@@ -0,0 +0,0 @@ public class StackedItemContents {
public void accountStack(ItemStack item, int maxCount) {
if (!item.isEmpty()) {
int i = Math.min(maxCount, item.getCount());
- this.raw.account(item.getItemHolder(), i);
+ 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
+ this.raw.account(new io.papermc.paper.inventory.recipe.ItemOrExact.Item(item.getItemHolder()), i);
}
}
- public static StackedContents.IngredientInfo<Holder<Item>> convertIngredientContents(Stream<Holder<Item>> items) {
- List<Holder<Item>> list = items.sorted(Comparator.comparingInt(item -> BuiltInRegistries.ITEM.getId(item.value()))).toList();
- return new StackedContents.IngredientInfo<>(list);
+ // Paper start - Improve exact choice recipe ingredients
+ public void initializeExtras(final Recipe<?> recipe, @Nullable final net.minecraft.world.item.crafting.CraftingInput input) {
+ if (this.extrasMap == null) {
+ this.extrasMap = new io.papermc.paper.inventory.recipe.StackedContentsExtrasMap(this.raw);
+ }
+ this.extrasMap.initialize(recipe);
+ if (input != null) this.extrasMap.accountInput(input);
+ }
+
+ public void resetExtras() {
+ if (this.extrasMap != null && !this.raw.amounts.isEmpty()) {
+ this.extrasMap.resetExtras();
+ }
+ }
+
+ public static StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact> convertIngredientContents(Stream<io.papermc.paper.inventory.recipe.ItemOrExact> items, boolean isExact) {
+ List<io.papermc.paper.inventory.recipe.ItemOrExact> list = items.sorted(Comparator.comparingInt(item -> isExact ? ItemStack.hashItemAndComponents(((io.papermc.paper.inventory.recipe.ItemOrExact.Exact) item).stack()) : BuiltInRegistries.ITEM.getId(((io.papermc.paper.inventory.recipe.ItemOrExact.Item) item).item().value()))).toList();
+ return new StackedContents.IngredientInfo<>(list, isExact);
+ // Paper end - Improve exact choice recipe ingredients
}
- public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> itemCallback) {
+ public boolean canCraft(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // 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();
return !placementInfo.isImpossibleToPlace() && this.canCraft(placementInfo.unpackedIngredients(), quantity, itemCallback);
}
- public boolean canCraft(List<StackedContents.IngredientInfo<Holder<Item>>> rawIngredients, @Nullable StackedContents.Output<Holder<Item>> itemCallback) {
+ public boolean canCraft(List<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(rawIngredients, 1, itemCallback);
}
private boolean canCraft(
- List<StackedContents.IngredientInfo<Holder<Item>>> rawIngredients, int quantity, @Nullable StackedContents.Output<Holder<Item>> itemCallback
+ List<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
) {
return this.raw.tryPick(rawIngredients, quantity, itemCallback);
}
- public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<Holder<Item>> itemCallback) {
+ public int getBiggestCraftableStack(Recipe<?> recipe, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients
return this.getBiggestCraftableStack(recipe, Integer.MAX_VALUE, itemCallback);
}
- public int getBiggestCraftableStack(Recipe<?> recipe, int max, @Nullable StackedContents.Output<Holder<Item>> itemCallback) {
+ public int getBiggestCraftableStack(Recipe<?> recipe, int max, @Nullable StackedContents.Output<io.papermc.paper.inventory.recipe.ItemOrExact> itemCallback) { // Paper - Improve exact choice recipe ingredients
return this.raw.tryPickAll(recipe.placementInfo().unpackedIngredients(), max, itemCallback);
}
diff --git a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
+++ b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
@@ -0,0 +0,0 @@ public final class Ingredient implements Predicate<ItemStack> {
}
public SlotDisplay display() {
+ // Paper start - show exact ingredients in recipe book
+ if (this.isExact()) {
+ return new SlotDisplay.Composite(this.itemStacks().stream().<SlotDisplay>map(SlotDisplay.ItemStackSlotDisplay::new).toList());
+ }
+ // Paper end - show exact ingredients in recipe book
return (SlotDisplay) this.values.unwrap().map(SlotDisplay.TagSlotDisplay::new, (list) -> {
return new SlotDisplay.Composite(list.stream().map(Ingredient::displayForSingleItem).toList());
});
diff --git a/src/main/java/net/minecraft/world/item/crafting/PlacementInfo.java b/src/main/java/net/minecraft/world/item/crafting/PlacementInfo.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/crafting/PlacementInfo.java
+++ b/src/main/java/net/minecraft/world/item/crafting/PlacementInfo.java
@@ -0,0 +0,0 @@ import net.minecraft.world.item.Item;
public class PlacementInfo {
public static final PlacementInfo NOT_PLACEABLE = new PlacementInfo(List.of(), List.of(), List.of());
private final List<Ingredient> ingredients;
- private final List<StackedContents.IngredientInfo<Holder<Item>>> unpackedIngredients;
+ private final List<StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> unpackedIngredients; // Paper - Improve exact choice recipe ingredients
private final List<Optional<PlacementInfo.SlotInfo>> slotInfo;
private PlacementInfo(
- List<Ingredient> ingredients, List<StackedContents.IngredientInfo<Holder<Item>>> rawIngredients, List<Optional<PlacementInfo.SlotInfo>> placementSlots
+ List<Ingredient> ingredients, List<StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> rawIngredients, List<Optional<PlacementInfo.SlotInfo>> placementSlots // Paper - Improve exact choice recipe ingredients
) {
this.ingredients = ingredients;
this.unpackedIngredients = rawIngredients;
this.slotInfo = placementSlots;
}
- public static StackedContents.IngredientInfo<Holder<Item>> ingredientToContents(Ingredient ingredient) {
- return StackedItemContents.convertIngredientContents(ingredient.items().stream());
+ // Paper start - Improve exact choice recipe ingredients
+ public static StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact> ingredientToContents(Ingredient ingredient) {
+ return StackedItemContents.convertIngredientContents(ingredient.isExact() ? ingredient.itemStacks().stream().map(io.papermc.paper.inventory.recipe.ItemOrExact.Exact::new) : ingredient.items().stream().map(io.papermc.paper.inventory.recipe.ItemOrExact.Item::new), ingredient.isExact());
+ // Paper end - Improve exact choice recipe ingredients
}
public static PlacementInfo create(Ingredient ingredient) {
if (ingredient.items().isEmpty()) {
return NOT_PLACEABLE;
} else {
- StackedContents.IngredientInfo<Holder<Item>> ingredientInfo = ingredientToContents(ingredient);
+ StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact> ingredientInfo = ingredientToContents(ingredient); // Paper - Improve exact choice recipe ingredients
PlacementInfo.SlotInfo slotInfo = new PlacementInfo.SlotInfo(0);
return new PlacementInfo(List.of(ingredient), List.of(ingredientInfo), List.of(Optional.of(slotInfo)));
}
@@ -0,0 +0,0 @@ public class PlacementInfo {
public static PlacementInfo createFromOptionals(List<Optional<Ingredient>> ingredients) {
int i = ingredients.size();
List<Ingredient> list = new ArrayList<>(i);
- List<StackedContents.IngredientInfo<Holder<Item>>> list2 = new ArrayList<>(i);
+ List<StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> list2 = new ArrayList<>(i); // Paper - Improve exact choice recipe ingredients
List<Optional<PlacementInfo.SlotInfo>> list3 = new ArrayList<>(i);
int j = 0;
@@ -0,0 +0,0 @@ public class PlacementInfo {
public static PlacementInfo create(List<Ingredient> ingredients) {
int i = ingredients.size();
- List<StackedContents.IngredientInfo<Holder<Item>>> list = new ArrayList<>(i);
+ List<StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> list = new ArrayList<>(i); // Paper - Improve exact choice recipe ingredients
List<Optional<PlacementInfo.SlotInfo>> list2 = new ArrayList<>(i);
for (int j = 0; j < i; j++) {
@@ -0,0 +0,0 @@ public class PlacementInfo {
return this.ingredients;
}
- public List<StackedContents.IngredientInfo<Holder<Item>>> unpackedIngredients() {
+ public List<StackedContents.IngredientInfo<io.papermc.paper.inventory.recipe.ItemOrExact>> unpackedIngredients() { // Paper - Improve exact choice recipe ingredients
return this.unpackedIngredients;
}
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -0,0 +0,0 @@ public class ShapelessRecipe implements CraftingRecipe {
}
public boolean matches(CraftingInput input, Level world) {
- 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));
+ // Paper start - Improve exact choice recipe ingredients & unwrap ternary
+ if (input.ingredientCount() != this.ingredients.size()) {
+ return false;
+ }
+ if (input.size() == 1 && this.ingredients.size() == 1) {
+ return this.ingredients.getFirst().test(input.getItem(0));
+ }
+ input.stackedContents().initializeExtras(this, input);
+ boolean canCraft = input.stackedContents().canCraft(this, null);
+ input.stackedContents().resetExtras();
+ return canCraft;
+ // Paper end - Improve exact choice recipe ingredients & unwrap ternary
}
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {