From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java +++ b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java @@ -0,0 +0,0 @@ public class SmithingTransformRecipe implements SmithingRecipe { final Ingredient base; final Ingredient addition; final ItemStack result; + final boolean copyNBT; // Paper public SmithingTransformRecipe(ResourceLocation id, Ingredient template, Ingredient base, Ingredient addition, ItemStack result) { + // Paper start + this(id, template, base, addition, result, true); + } + public SmithingTransformRecipe(ResourceLocation id, Ingredient template, Ingredient base, Ingredient addition, ItemStack result, boolean copyNBT) { + this.copyNBT = copyNBT; + // Paper end this.id = id; this.template = template; this.base = base; @@ -0,0 +0,0 @@ public class SmithingTransformRecipe implements SmithingRecipe { @Override public ItemStack assemble(Container inventory, RegistryAccess registryManager) { ItemStack itemstack = this.result.copy(); + if (this.copyNBT) { // Paper - copy nbt conditionally CompoundTag nbttagcompound = inventory.getItem(1).getTag(); if (nbttagcompound != null) { itemstack.setTag(nbttagcompound.copy()); } + } // Paper return itemstack; } @@ -0,0 +0,0 @@ public class SmithingTransformRecipe implements SmithingRecipe { public Recipe toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(CraftNamespacedKey.fromMinecraft(this.id), result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition)); + CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(CraftNamespacedKey.fromMinecraft(this.id), result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyNBT); // Paper 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java +++ b/src/main/java/net/minecraft/world/item/crafting/SmithingTrimRecipe.java @@ -0,0 +0,0 @@ public class SmithingTrimRecipe implements SmithingRecipe { final Ingredient template; final Ingredient base; final Ingredient addition; + final boolean copyNbt; // Paper public SmithingTrimRecipe(ResourceLocation id, Ingredient template, Ingredient base, Ingredient addition) { + // Paper start + this(id, template, base, addition, true); + } + public SmithingTrimRecipe(ResourceLocation id, Ingredient template, Ingredient base, Ingredient addition, boolean copyNbt) { + this.copyNbt = copyNbt; + // Paper end this.id = id; this.template = template; this.base = base; @@ -0,0 +0,0 @@ public class SmithingTrimRecipe implements SmithingRecipe { return ItemStack.EMPTY; } - ItemStack itemstack1 = itemstack.copy(); + ItemStack itemstack1 = this.copyNbt ? itemstack.copy() : new ItemStack(itemstack.getItem(), itemstack.getCount()); // Paper itemstack1.setCount(1); ArmorTrim armortrim = new ArmorTrim((Holder) optional.get(), (Holder) optional1.get()); @@ -0,0 +0,0 @@ public class SmithingTrimRecipe implements SmithingRecipe { // CraftBukkit start @Override public Recipe toBukkitRecipe() { - return new CraftSmithingTrimRecipe(CraftNamespacedKey.fromMinecraft(this.id), CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition)); + return new CraftSmithingTrimRecipe(CraftNamespacedKey.fromMinecraft(this.id), CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition), this.copyNbt); // Paper } // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java @@ -0,0 +0,0 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem public CraftSmithingTransformRecipe(NamespacedKey key, ItemStack result, RecipeChoice template, RecipeChoice base, RecipeChoice addition) { super(key, result, template, base, addition); } + // Paper start + public CraftSmithingTransformRecipe(NamespacedKey key, ItemStack result, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyNbt) { + super(key, result, template, base, addition, copyNbt); + } + // Paper end 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 return ret; } @@ -0,0 +0,0 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTransformRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTransformRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result), this.willCopyNbt())); // Paper } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java @@ -0,0 +0,0 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition) { super(key, template, base, addition); } + // Paper start + public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition, boolean copyNbt) { + super(key, template, base, addition, copyNbt); + } + // Paper end 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 return ret; } @Override public void addToCraftingManager() { - MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTrimRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTrimRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), this.willCopyNbt())); // Paper } }