update smithing recipe copy data components API

This commit is contained in:
Jake Potrebic
2024-04-25 08:13:36 -07:00
parent 09edc7e437
commit cbfb3d4f97
2 changed files with 52 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 26 Sep 2021 12:57:35 -0700
Subject: [PATCH] Option to prevent NBT copy in smithing recipes
Subject: [PATCH] Option to prevent data components copy in smithing recipes
diff --git a/src/main/java/org/bukkit/inventory/SmithingRecipe.java b/src/main/java/org/bukkit/inventory/SmithingRecipe.java
@@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private final ItemStack result;
private final RecipeChoice base;
private final RecipeChoice addition;
+ private final boolean copyNbt; // Paper
+ private final boolean copyDataComponents; // Paper
/**
* Create a smithing recipe to produce the specified result ItemStack.
@@ -30,12 +30,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param result The item you want the recipe to create.
+ * @param base The base ingredient
+ * @param addition The addition ingredient
+ * @param copyNbt whether to copy the nbt from the input base item to the output
+ * @param copyDataComponents whether to copy the data components from the input base item to the output
+ * @deprecated use {@link SmithingTrimRecipe} or {@link SmithingTransformRecipe}
+ */
+ @Deprecated
+ public SmithingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyNbt) {
+ this.copyNbt = copyNbt;
+ public SmithingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyDataComponents) {
+ this.copyDataComponents = copyDataComponents;
+ // Paper end
this.key = key;
this.result = result;
@@ -47,12 +47,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ // Paper start
+ /**
+ * Whether or not to copy the NBT of the input base item to the output.
+ * Whether to copy the NBT of the input base item to the output.
+ *
+ * @return true to copy the NBT (default for vanilla smithing recipes)
+ * @apiNote use {@link #willCopyDataComponents()}
+ */
+ @org.jetbrains.annotations.ApiStatus.Obsolete(since = "1.20.5")
+ public boolean willCopyNbt() {
+ return copyNbt;
+ return this.willCopyDataComponents();
+ }
+
+ /**
+ * Whether to copy the data components of the input base item to the output.
+ *
+ * @return true to copy the data components (default for vanilla smithing recipes)
+ */
+ public boolean willCopyDataComponents() {
+ return this.copyDataComponents;
+ }
+ // Paper end
}
@@ -73,10 +84,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param template The template item.
+ * @param base The base ingredient
+ * @param addition The addition ingredient
+ * @param copyNbt whether to copy the nbt from the input base item to the output
+ * @param copyDataComponents whether to copy the data components from the input base item to the output
+ */
+ public SmithingTransformRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result, @NotNull RecipeChoice template, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyNbt) {
+ super(key, result, base, addition, copyNbt);
+ public SmithingTransformRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result, @NotNull RecipeChoice template, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyDataComponents) {
+ super(key, result, base, addition, copyDataComponents);
+ this.template = template;
+ }
+ // Paper end
@@ -99,10 +110,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param template The template item.
+ * @param base The base ingredient
+ * @param addition The addition ingredient
+ * @param copyNbt whether to copy the nbt from the input base item to the output
+ * @param copyDataComponents whether to copy the data components from the input base item to the output
+ */
+ public SmithingTrimRecipe(@NotNull NamespacedKey key, @NotNull RecipeChoice template, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyNbt) {
+ super(key, new ItemStack(Material.AIR), base, addition, copyNbt);
+ public SmithingTrimRecipe(@NotNull NamespacedKey key, @NotNull RecipeChoice template, @NotNull RecipeChoice base, @NotNull RecipeChoice addition, boolean copyDataComponents) {
+ super(key, new ItemStack(Material.AIR), base, addition, copyDataComponents);
+ this.template = template;
+ }
+ // Paper end