3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/unapplied/server/0623-Option-to-prevent-NBT-copy-in-smithing-recipes.patch

148 Zeilen
9.7 KiB
Diff

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
Subject: [PATCH] Option to prevent NBT copy in smithing recipes
diff --git a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
index 566b588006da2b46ec1727be85560ccd59c42c6f..67f7eb89570934b73ff5b894ae3e89fdb874b923 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;
+ final boolean copyNBT; // Paper - Option to prevent NBT 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) {
+ // Paper start - Option to prevent NBT copy
2023-09-22 14:22:24 +02:00
+ this(template, base, addition, result, true);
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, boolean copyNBT) {
2023-06-08 04:04:01 +02:00
+ this.copyNBT = copyNBT;
+ // Paper end - Option to prevent NBT 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;
@@ -39,11 +46,13 @@ public class SmithingTransformRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
@Override
public ItemStack assemble(Container inventory, RegistryAccess registryManager) {
ItemStack itemstack = this.result.copy();
+ if (this.copyNBT) { // Paper - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
CompoundTag nbttagcompound = inventory.getItem(1).getTag();
if (nbttagcompound != null) {
itemstack.setTag(nbttagcompound.copy());
}
+ } // Paper - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
return itemstack;
}
2023-09-22 14:22:24 +02:00
@@ -83,7 +92,7 @@ public class SmithingTransformRecipe implements SmithingRecipe {
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));
+ CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(id, result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyNBT); // Paper - Option to prevent NBT 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
index e0b24c140e04a159a7b8aaef64ab94e19fc03dfd..a3686cede266c0205247abcec3ce082ae4a048a0 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
2023-09-22 14:22:24 +02:00
@@ -29,8 +29,15 @@ public class SmithingTrimRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
final Ingredient template;
final Ingredient base;
final Ingredient addition;
+ final boolean copyNbt; // Paper - Option to prevent NBT 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) {
+ // Paper start - Option to prevent NBT copy
2023-09-22 14:22:24 +02:00
+ this(template, base, addition, true);
2023-06-08 04:04:01 +02:00
+ }
2023-09-22 19:25:18 +02:00
+ public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition, boolean copyNbt) {
2023-06-08 04:04:01 +02:00
+ this.copyNbt = copyNbt;
+ // Paper end - Option to prevent NBT 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;
@@ -56,7 +63,7 @@ public class SmithingTrimRecipe implements SmithingRecipe {
2023-06-08 04:04:01 +02:00
return ItemStack.EMPTY;
}
- ItemStack itemstack1 = itemstack.copy();
+ ItemStack itemstack1 = this.copyNbt ? itemstack.copy() : new ItemStack(itemstack.getItem(), itemstack.getCount()); // Paper - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
itemstack1.setCount(1);
ArmorTrim armortrim = new ArmorTrim((Holder) optional.get(), (Holder) optional1.get());
2023-09-22 14:22:24 +02:00
@@ -116,7 +123,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));
+ return new CraftSmithingTrimRecipe(id, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyNbt); // Paper - Option to prevent NBT 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
index 8c381e2745e7d5b63e72a60c5541b549f0d1b9bf..3301711afbcf39a5db15d9a7b37bbd95a63dd375 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);
}
+ // Paper start - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
+ public CraftSmithingTransformRecipe(NamespacedKey key, ItemStack result, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyNbt) {
+ super(key, result, template, base, addition, copyNbt);
+ }
+ // Paper end - Option to prevent NBT 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());
+ CraftSmithingTransformRecipe ret = new CraftSmithingTransformRecipe(recipe.getKey(), recipe.getResult(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition(), recipe.willCopyNbt()); // Paper - Option to prevent NBT 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))));
+ 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.willCopyNbt()))); // Paper - Option to prevent NBT 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
index 87f20a4811d082f217638768417c1c0feb84f741..2217e7ed9533c52a3b7d27d4dfff23ada6f2cef1 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);
}
+ // Paper start - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
+ public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyNbt) {
+ super(key, template, base, addition, copyNbt);
+ }
+ // Paper end - Option to prevent NBT 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());
+ CraftSmithingTrimRecipe ret = new CraftSmithingTrimRecipe(recipe.getKey(), recipe.getTemplate(), recipe.getBase(), recipe.getAddition(), recipe.willCopyNbt()); // Paper - Option to prevent NBT 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))));
+ 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.willCopyNbt()))); // Paper - Option to prevent NBT copy
2023-06-08 04:04:01 +02:00
}
}