craftbukkit/nms-patches/net/minecraft/world/item/crafting/RecipeItemStack.patch

67 lines
2.3 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/item/crafting/RecipeItemStack.java
+++ b/net/minecraft/world/item/crafting/RecipeItemStack.java
2024-12-04 03:20:00 +11:00
@@ -21,6 +21,11 @@
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.level.IMaterial;
+// CraftBukkit start
+import java.util.List;
+import javax.annotation.Nullable;
+// CraftBukkit end
+
public final class RecipeItemStack implements AutoRecipeStackManager.a<Holder<Item>>, Predicate<ItemStack> {
public static final StreamCodec<RegistryFriendlyByteBuf, RecipeItemStack> CONTENTS_STREAM_CODEC = ByteBufCodecs.holderSet(Registries.ITEM).map(RecipeItemStack::new, (recipeitemstack) -> {
@@ -38,6 +43,24 @@
return recipeitemstack.values;
});
2024-10-23 02:15:00 +11:00
private final HolderSet<Item> values;
+ // CraftBukkit start
+ @Nullable
+ private List<ItemStack> itemStacks;
+
+ public boolean isExact() {
+ return this.itemStacks != null;
+ }
+
+ public List<ItemStack> itemStacks() {
+ return this.itemStacks;
+ }
+
+ public static RecipeItemStack ofStacks(List<ItemStack> stacks) {
+ RecipeItemStack recipe = RecipeItemStack.of(stacks.stream().map(ItemStack::getItem));
+ recipe.itemStacks = stacks;
2024-10-23 02:15:00 +11:00
+ return recipe;
+ }
+ // CraftBukkit end
2024-10-23 02:15:00 +11:00
private RecipeItemStack(HolderSet<Item> holderset) {
holderset.unwrap().ifRight((list) -> {
2024-12-04 03:20:00 +11:00
@@ -70,6 +93,17 @@
2024-10-23 02:15:00 +11:00
}
2024-10-23 02:15:00 +11:00
public boolean test(ItemStack itemstack) {
+ // CraftBukkit start
+ if (this.isExact()) {
+ for (ItemStack itemstack1 : this.itemStacks()) {
+ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) {
+ return true;
2022-12-08 03:00:00 +11:00
+ }
2024-10-23 02:15:00 +11:00
+ }
+
+ return false;
2024-10-23 02:15:00 +11:00
+ }
+ // CraftBukkit end
2024-12-04 03:20:00 +11:00
return itemstack.is(this.values);
}
2024-10-23 02:15:00 +11:00
2024-12-04 03:20:00 +11:00
@@ -79,7 +113,7 @@
2024-10-23 02:15:00 +11:00
public boolean equals(Object object) {
if (object instanceof RecipeItemStack recipeitemstack) {
- return Objects.equals(this.values, recipeitemstack.values);
+ return Objects.equals(this.values, recipeitemstack.values) && Objects.equals(this.itemStacks, recipeitemstack.itemStacks); // CraftBukkit
} else {
return false;
}