2023-06-08 04:04:01 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 26 Sep 2021 12:57:28 -0700
2024-04-25 17:13:36 +02:00
Subject: [PATCH] Option to prevent data components copy in smithing recipes
2023-06-08 04:04:01 +02:00
diff --git a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
2024-04-25 17:13:36 +02:00
index c6c6d54f35dd75e14a6e040d730d5ae9c1406059..a39a2b2b1a4294cb68cdbc3e67ad3e29552eeec8 100644
2023-06-08 04:04:01 +02:00
--- a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
2023-09-22 14:22:24 +02:00
@@ -23,8 +23,15 @@ public class SmithingTransformRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
final Ingredient base;
final Ingredient addition;
final ItemStack result;
2024-04-25 17:13:36 +02:00
+ final boolean copyDataComponents; // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
2023-09-22 14:22:24 +02:00
public SmithingTransformRecipe(Ingredient template, Ingredient base, Ingredient addition, ItemStack result) {
2024-04-25 17:13:36 +02:00
+ // Paper start - Option to prevent data components copy
2023-09-22 14:22:24 +02:00
+ this(template, base, addition, result, true);
2023-06-08 04:04:01 +02:00
+ }
2024-04-25 17:13:36 +02:00
+ public SmithingTransformRecipe(Ingredient template, Ingredient base, Ingredient addition, ItemStack result, boolean copyDataComponents) {
+ this.copyDataComponents = copyDataComponents;
+ // Paper end - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
this.template = template;
this.base = base;
2023-09-22 14:22:24 +02:00
this.addition = addition;
2024-04-24 17:27:28 +02:00
@@ -40,7 +47,9 @@ public class SmithingTransformRecipe implements SmithingRecipe {
public ItemStack assemble(Container inventory, HolderLookup.Provider lookup) {
ItemStack itemstack = inventory.getItem(1).transmuteCopy(this.result.getItem(), this.result.getCount());
2023-06-08 04:04:01 +02:00
2024-04-25 17:13:36 +02:00
+ if (this.copyDataComponents) { // Paper - Option to prevent data components copy
2024-04-24 17:27:28 +02:00
itemstack.applyComponents(this.result.getComponentsPatch());
2024-04-25 17:13:36 +02:00
+ } // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
return itemstack;
}
2024-04-24 17:27:28 +02:00
@@ -79,7 +88,7 @@ public class SmithingTransformRecipe implements SmithingRecipe {
2023-09-22 14:22:24 +02:00
public Recipe toBukkitRecipe(NamespacedKey id) {
2023-06-08 04:04:01 +02:00
CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
2023-09-22 14:22:24 +02:00
- CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(id, result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition));
2024-04-25 17:13:36 +02:00
+ CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(id, result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyDataComponents); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
return recipe;
}
diff --git a/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java b/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
2024-04-25 17:13:36 +02:00
index f1207df56718ad2a62fb7d567b397ceaa668e1e7..45a7ad173b7025305ce83b51f94e2af47644b829 100644
2023-06-08 04:04:01 +02:00
--- a/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
2024-04-24 17:27:28 +02:00
@@ -31,8 +31,15 @@ public class SmithingTrimRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
final Ingredient template;
final Ingredient base;
final Ingredient addition;
2024-04-25 17:13:36 +02:00
+ final boolean copyDataComponents; // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
2023-09-22 14:22:24 +02:00
public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition) {
2024-04-25 17:13:36 +02:00
+ // Paper start - Option to prevent data components copy
2023-09-22 14:22:24 +02:00
+ this(template, base, addition, true);
2023-06-08 04:04:01 +02:00
+ }
2024-04-25 17:13:36 +02:00
+ public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition, boolean copyDataComponents) {
+ this.copyDataComponents = copyDataComponents;
+ // Paper end - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
this.template = template;
this.base = base;
2023-09-22 14:22:24 +02:00
this.addition = addition;
2024-04-24 17:27:28 +02:00
@@ -58,7 +65,7 @@ public class SmithingTrimRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
return ItemStack.EMPTY;
}
2024-04-24 17:27:28 +02:00
- ItemStack itemstack1 = itemstack.copyWithCount(1);
2024-04-25 17:13:36 +02:00
+ ItemStack itemstack1 = this.copyDataComponents ? itemstack.copyWithCount(1) : new ItemStack(itemstack.getItem(), 1); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
2024-04-24 17:27:28 +02:00
itemstack1.set(DataComponents.TRIM, new ArmorTrim((Holder) optional.get(), (Holder) optional1.get()));
return itemstack1;
@@ -109,7 +116,7 @@ public class SmithingTrimRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
// CraftBukkit start
@Override
2023-09-22 14:22:24 +02:00
public Recipe toBukkitRecipe(NamespacedKey id) {
- return new CraftSmithingTrimRecipe(id, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition));
2024-04-25 17:13:36 +02:00
+ return new CraftSmithingTrimRecipe(id, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyDataComponents); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
}
// CraftBukkit end
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
2024-04-25 17:13:36 +02:00
index 8c381e2745e7d5b63e72a60c5541b549f0d1b9bf..38690b28b6f67624d68877c1e89ebe30b402b233 100644
2023-06-08 04:04:01 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
2023-09-22 14:22:24 +02:00
@@ -12,12 +12,17 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
2023-06-08 04:04:01 +02:00
public CraftSmithingTransformRecipe(NamespacedKey key, ItemStack result, RecipeChoice template, RecipeChoice base, RecipeChoice addition) {
super(key, result, template, base, addition);
}
2024-04-25 17:13:36 +02:00
+ // Paper start - Option to prevent data components copy
+ public CraftSmithingTransformRecipe(NamespacedKey key, ItemStack result, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyDataComponents) {
+ super(key, result, template, base, addition, copyDataComponents);
2023-06-08 04:04:01 +02:00
+ }
2024-04-25 17:13:36 +02:00
+ // Paper end - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
public static CraftSmithingTransformRecipe fromBukkitRecipe(SmithingTransformRecipe recipe) {
if (recipe instanceof CraftSmithingTransformRecipe) {
return (CraftSmithingTransformRecipe) recipe;
}
- CraftSmithingTransformRecipe ret = new CraftSmithingTransformRecipe(recipe.getKey(), recipe.getResult(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition());
2024-04-25 17:13:36 +02:00
+ CraftSmithingTransformRecipe ret = new CraftSmithingTransformRecipe(recipe.getKey(), recipe.getResult(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition(), recipe.willCopyDataComponents()); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
return ret;
}
2023-09-22 14:22:24 +02:00
@@ -25,6 +30,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
2023-06-08 04:04:01 +02:00
public void addToCraftingManager() {
ItemStack result = this.getResult();
2023-10-27 01:34:58 +02:00
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result))));
2024-04-25 17:13:36 +02:00
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
2024-04-25 17:13:36 +02:00
index 87f20a4811d082f217638768417c1c0feb84f741..5d7782b168138383c606a2c52fbdebe1732364ac 100644
2023-06-08 04:04:01 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
2023-09-22 14:22:24 +02:00
@@ -12,17 +12,22 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft
2023-06-08 04:04:01 +02:00
public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition) {
super(key, template, base, addition);
}
2024-04-25 17:13:36 +02:00
+ // Paper start - Option to prevent data components copy
+ public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyDataComponents) {
+ super(key, template, base, addition, copyDataComponents);
2023-06-08 04:04:01 +02:00
+ }
2024-04-25 17:13:36 +02:00
+ // Paper end - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
public static CraftSmithingTrimRecipe fromBukkitRecipe(SmithingTrimRecipe recipe) {
if (recipe instanceof CraftSmithingTrimRecipe) {
return (CraftSmithingTrimRecipe) recipe;
}
- CraftSmithingTrimRecipe ret = new CraftSmithingTrimRecipe(recipe.getKey(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition());
2024-04-25 17:13:36 +02:00
+ CraftSmithingTrimRecipe ret = new CraftSmithingTrimRecipe(recipe.getKey(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition(), recipe.willCopyDataComponents()); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
return ret;
}
@Override
public void addToCraftingManager() {
2023-10-27 01:34:58 +02:00
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true))));
2024-04-25 17:13:36 +02:00
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
2023-06-08 04:04:01 +02:00
}
}