mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Option to prevent data components copy in smithing recipes
This commit is contained in:
parent
b96b8f7723
commit
65ec6cf342
4 changed files with 83 additions and 8 deletions
|
@ -15,7 +15,33 @@
|
|||
public class SmithingTransformRecipe implements SmithingRecipe {
|
||||
|
||||
final Optional<Ingredient> template;
|
||||
@@ -71,6 +79,17 @@
|
||||
@@ -22,8 +30,15 @@
|
||||
final ItemStack result;
|
||||
@Nullable
|
||||
private PlacementInfo placementInfo;
|
||||
+ final boolean copyDataComponents; // Paper - Option to prevent data components copy
|
||||
|
||||
public SmithingTransformRecipe(Optional<Ingredient> template, Optional<Ingredient> base, Optional<Ingredient> addition, ItemStack result) {
|
||||
+ // Paper start - Option to prevent data components copy
|
||||
+ this(template, base, addition, result, true);
|
||||
+ }
|
||||
+ public SmithingTransformRecipe(Optional<Ingredient> template, Optional<Ingredient> base, Optional<Ingredient> addition, ItemStack result, boolean copyDataComponents) {
|
||||
+ this.copyDataComponents = copyDataComponents;
|
||||
+ // Paper end - Option to prevent data components copy
|
||||
this.template = template;
|
||||
this.base = base;
|
||||
this.addition = addition;
|
||||
@@ -33,7 +48,9 @@
|
||||
public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider registries) {
|
||||
ItemStack itemstack = input.base().transmuteCopy(this.result.getItem(), this.result.getCount());
|
||||
|
||||
+ if (this.copyDataComponents) { // Paper - Option to prevent data components copy
|
||||
itemstack.applyComponents(this.result.getComponentsPatch());
|
||||
+ } // Paper - Option to prevent data components copy
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@@ -71,6 +88,17 @@
|
||||
return List.of(new SmithingRecipeDisplay(Ingredient.optionalIngredientToDisplay(this.template), Ingredient.optionalIngredientToDisplay(this.base), Ingredient.optionalIngredientToDisplay(this.addition), new SlotDisplay.ItemStackSlotDisplay(this.result), new SlotDisplay.ItemSlotDisplay(Items.SMITHING_TABLE)));
|
||||
}
|
||||
|
||||
|
@ -24,7 +50,7 @@
|
|||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
||||
+
|
||||
+ 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.copyDataComponents); // Paper - Option to prevent data components copy
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
|
|
|
@ -14,14 +14,53 @@
|
|||
public class SmithingTrimRecipe implements SmithingRecipe {
|
||||
|
||||
final Optional<Ingredient> template;
|
||||
@@ -97,6 +104,13 @@
|
||||
@@ -28,18 +35,28 @@
|
||||
final Optional<Ingredient> addition;
|
||||
@Nullable
|
||||
private PlacementInfo placementInfo;
|
||||
+ final boolean copyDataComponents; // Paper - Option to prevent data components copy
|
||||
|
||||
public SmithingTrimRecipe(Optional<Ingredient> template, Optional<Ingredient> base, Optional<Ingredient> addition) {
|
||||
+ // Paper start - Option to prevent data components copy
|
||||
+ this(template, base, addition, true);
|
||||
+ }
|
||||
+ public SmithingTrimRecipe(Optional<Ingredient> template, Optional<Ingredient> base, Optional<Ingredient> addition, boolean copyDataComponents) {
|
||||
+ this.copyDataComponents = copyDataComponents;
|
||||
+ // Paper end - Option to prevent data components copy
|
||||
this.template = template;
|
||||
this.base = base;
|
||||
this.addition = addition;
|
||||
}
|
||||
|
||||
public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider registries) {
|
||||
- return SmithingTrimRecipe.applyTrim(registries, input.base(), input.addition(), input.template());
|
||||
+ return SmithingTrimRecipe.applyTrim(registries, input.base(), input.addition(), input.template(), this.copyDataComponents);
|
||||
}
|
||||
|
||||
public static ItemStack applyTrim(HolderLookup.Provider registries, ItemStack base, ItemStack addition, ItemStack template) {
|
||||
+ return applyTrim(registries, base, addition, template, true);
|
||||
+ }
|
||||
+ public static ItemStack applyTrim(HolderLookup.Provider registries, ItemStack base, ItemStack addition, ItemStack template, boolean copyDataComponents) {
|
||||
Optional<Holder.Reference<TrimMaterial>> optional = TrimMaterials.getFromIngredient(registries, addition);
|
||||
Optional<Holder.Reference<TrimPattern>> optional1 = TrimPatterns.getFromTemplate(registries, template);
|
||||
|
||||
@@ -49,7 +66,7 @@
|
||||
if (armortrim != null && armortrim.hasPatternAndMaterial((Holder) optional1.get(), (Holder) optional.get())) {
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
- ItemStack itemstack3 = base.copyWithCount(1);
|
||||
+ ItemStack itemstack3 = copyDataComponents ? base.copyWithCount(1) : new ItemStack(base.getItem(), 1); // Paper - Option to prevent data components copy
|
||||
|
||||
itemstack3.set(DataComponents.TRIM, new ArmorTrim((Holder) optional.get(), (Holder) optional1.get()));
|
||||
return itemstack3;
|
||||
@@ -97,6 +114,13 @@
|
||||
return List.of(new SmithingRecipeDisplay(slotdisplay2, slotdisplay, slotdisplay1, new SlotDisplay.SmithingTrimDemoSlotDisplay(slotdisplay, slotdisplay1, slotdisplay2), new SlotDisplay.ItemSlotDisplay(Items.SMITHING_TABLE)));
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ 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.copyDataComponents); // Paper - Option to prevent data components copy
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
|
|
@ -11,12 +11,17 @@ 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 - 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);
|
||||
}
|
||||
// Paper end - Option to prevent data components copy
|
||||
|
||||
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.willCopyDataComponents()); // Paper - Option to prevent data components copy
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -24,6 +29,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
|
|||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMSOptional(this.getTemplate(), false), this.toNMSOptional(this.getBase(), false), this.toNMSOptional(this.getAddition(), false), CraftItemStack.asNMSCopy(result))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMSOptional(this.getTemplate(), false), this.toNMSOptional(this.getBase(), false), this.toNMSOptional(this.getAddition(), false), CraftItemStack.asNMSCopy(result), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,17 +11,22 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft
|
|||
public CraftSmithingTrimRecipe(NamespacedKey key, RecipeChoice template, RecipeChoice base, RecipeChoice addition) {
|
||||
super(key, template, base, addition);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
// Paper end - Option to prevent data components copy
|
||||
|
||||
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.willCopyDataComponents()); // Paper - Option to prevent data components copy
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMSOptional(this.getTemplate(), false), this.toNMSOptional(this.getBase(), false), this.toNMSOptional(this.getAddition(), false))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMSOptional(this.getTemplate(), false), this.toNMSOptional(this.getBase(), false), this.toNMSOptional(this.getAddition(), false), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue