net.minecraft.world.item.crafting

This commit is contained in:
Jake Potrebic 2024-12-14 10:07:36 -08:00
parent b602dc968e
commit db81fd3455
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
29 changed files with 421 additions and 682 deletions

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/item/crafting/BlastingRecipe.java
+++ b/net/minecraft/world/item/crafting/BlastingRecipe.java
@@ -31,4 +_,17 @@
case FOOD, MISC -> RecipeBookCategories.BLAST_FURNACE_MISC;
};
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result());
+
+ org.bukkit.craftbukkit.inventory.CraftBlastingRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftBlastingRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/item/crafting/CampfireCookingRecipe.java
+++ b/net/minecraft/world/item/crafting/CampfireCookingRecipe.java
@@ -28,4 +_,17 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.CAMPFIRE;
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result());
+
+ org.bukkit.craftbukkit.inventory.CraftCampfireRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftCampfireRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -0,0 +1,22 @@
--- a/net/minecraft/world/item/crafting/CustomRecipe.java
+++ b/net/minecraft/world/item/crafting/CustomRecipe.java
@@ -30,6 +_,19 @@
@Override
public abstract RecipeSerializer<? extends CustomRecipe> getSerializer();
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.EMPTY);
+
+ org.bukkit.craftbukkit.inventory.CraftComplexRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftComplexRecipe(id, result, this);
+ recipe.setGroup(this.group());
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
+
public static class Serializer<T extends CraftingRecipe> implements RecipeSerializer<T> {
private final MapCodec<T> codec;
private final StreamCodec<RegistryFriendlyByteBuf, T> streamCodec;

View file

@ -0,0 +1,55 @@
--- a/net/minecraft/world/item/crafting/Ingredient.java
+++ b/net/minecraft/world/item/crafting/Ingredient.java
@@ -33,6 +_,25 @@
public static final Codec<Ingredient> CODEC = ExtraCodecs.nonEmptyHolderSet(NON_AIR_HOLDER_SET_CODEC)
.xmap(Ingredient::new, ingredient -> ingredient.values);
private final HolderSet<Item> values;
+ // CraftBukkit start
+ @javax.annotation.Nullable
+ private java.util.List<ItemStack> itemStacks;
+
+ public boolean isExact() {
+ return this.itemStacks != null;
+ }
+
+ @javax.annotation.Nullable
+ public java.util.List<ItemStack> itemStacks() {
+ return this.itemStacks;
+ }
+
+ public static Ingredient ofStacks(java.util.List<ItemStack> stacks) {
+ Ingredient recipe = Ingredient.of(stacks.stream().map(ItemStack::getItem));
+ recipe.itemStacks = stacks;
+ return recipe;
+ }
+ // CraftBukkit end
private Ingredient(HolderSet<Item> values) {
values.unwrap().ifRight(list -> {
@@ -60,6 +_,17 @@
@Override
public boolean test(ItemStack stack) {
+ // CraftBukkit start
+ if (this.isExact()) {
+ for (ItemStack itemstack1 : this.itemStacks()) {
+ if (itemstack1.getItem() == stack.getItem() && ItemStack.isSameItemSameComponents(stack, itemstack1)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // CraftBukkit end
return stack.is(this.values);
}
@@ -70,7 +_,7 @@
@Override
public boolean equals(Object other) {
- return other instanceof Ingredient ingredient && Objects.equals(this.values, ingredient.values);
+ return other instanceof Ingredient ingredient && Objects.equals(this.values, ingredient.values) && Objects.equals(this.itemStacks, ingredient.itemStacks); // CraftBukkit
}
public static Ingredient of(ItemLike item) {

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/crafting/Recipe.java
+++ b/net/minecraft/world/item/crafting/Recipe.java
@@ -44,4 +44,6 @@
@@ -44,4 +_,6 @@
}
RecipeBookCategory recipeBookCategory();

View file

@ -0,0 +1,15 @@
--- a/net/minecraft/world/item/crafting/RecipeHolder.java
+++ b/net/minecraft/world/item/crafting/RecipeHolder.java
@@ -10,6 +_,12 @@
ResourceKey.streamCodec(Registries.RECIPE), RecipeHolder::id, Recipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new
);
+ // CraftBukkit start
+ public final org.bukkit.inventory.Recipe toBukkitRecipe() {
+ return this.value.toBukkitRecipe(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.id.location()));
+ }
+ // CraftBukkit end
+
@Override
public boolean equals(Object other) {
return this == other || other instanceof RecipeHolder<?> recipeHolder && this.id == recipeHolder.id;

View file

@ -0,0 +1,64 @@
--- a/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
@@ -87,7 +_,26 @@
LOGGER.info("Loaded {} recipes", object.values().size());
}
+ // CraftBukkit start
+ public void addRecipe(RecipeHolder<?> irecipe) {
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
+ this.recipes.addRecipe(irecipe);
+ this.finalizeRecipeLoading();
+ }
+
+ private FeatureFlagSet featureflagset;
+
+ public void finalizeRecipeLoading() {
+ if (this.featureflagset != null) {
+ this.finalizeRecipeLoading(this.featureflagset);
+
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().reloadRecipes();
+ }
+ }
+
public void finalizeRecipeLoading(FeatureFlagSet enabledFeatures) {
+ this.featureflagset = enabledFeatures;
+ // CraftBukkit end
List<SelectableRecipe.SingleInputEntry<StonecutterRecipe>> list = new ArrayList<>();
List<RecipeManager.IngredientCollector> list1 = RECIPE_PROPERTY_SETS.entrySet()
.stream()
@@ -147,7 +_,10 @@
}
public <I extends RecipeInput, T extends Recipe<I>> Optional<RecipeHolder<T>> getRecipeFor(RecipeType<T> recipeType, I input, Level level) {
- return this.recipes.getRecipesFor(recipeType, input, level).findFirst();
+ // CraftBukkit start
+ List<RecipeHolder<T>> list = this.recipes.getRecipesFor(recipeType, input, level).toList();
+ return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority
+ // CraftBukkit end
}
public Optional<RecipeHolder<?>> byKey(ResourceKey<Recipe<?>> key) {
@@ -199,6 +_,22 @@
Recipe<?> recipe1 = Recipe.CODEC.parse(registries.createSerializationContext(JsonOps.INSTANCE), json).getOrThrow(JsonParseException::new);
return new RecipeHolder<>(recipe, recipe1);
}
+
+ // CraftBukkit start
+ public boolean removeRecipe(ResourceKey<Recipe<?>> mcKey) {
+ boolean removed = this.recipes.removeRecipe((ResourceKey<Recipe<RecipeInput>>) (ResourceKey) mcKey); // Paper - generic fix
+ if (removed) {
+ this.finalizeRecipeLoading();
+ }
+
+ return removed;
+ }
+
+ public void clearRecipes() {
+ this.recipes = RecipeMap.create(java.util.Collections.emptyList());
+ this.finalizeRecipeLoading();
+ }
+ // CraftBukkit end
public static <I extends RecipeInput, T extends Recipe<I>> RecipeManager.CachedCheck<I, T> createCheck(final RecipeType<T> recipeType) {
return new RecipeManager.CachedCheck<I, T>() {

View file

@ -1,25 +1,15 @@
--- a/net/minecraft/world/item/crafting/RecipeMap.java
+++ b/net/minecraft/world/item/crafting/RecipeMap.java
@@ -11,6 +11,10 @@
import javax.annotation.Nullable;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Maps;
+// CraftBukkit end
public class RecipeMap {
@@ -35,11 +39,56 @@
com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder);
@@ -30,8 +_,53 @@
builder1.put(recipeHolder.id(), recipeHolder);
}
- return new RecipeMap(builder.build(), com_google_common_collect_immutablemap_builder.build());
- return new RecipeMap(builder.build(), builder1.build());
- }
+ // CraftBukkit start - mutable
+ return new RecipeMap(LinkedHashMultimap.create(builder.build()), Maps.newHashMap(com_google_common_collect_immutablemap_builder.build()));
}
+ return new RecipeMap(com.google.common.collect.LinkedHashMultimap.create(builder.build()), com.google.common.collect.Maps.newHashMap(builder1.build()));
+ }
+
+ public void addRecipe(RecipeHolder<?> irecipe) {
+ Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType());
+
@ -63,10 +53,6 @@
+ // Paper end - why are you using a loop???
+ }
+ // Paper end - replace removeRecipe implementation
+
public <I extends RecipeInput, T extends Recipe<I>> Collection<RecipeHolder<T>> byType(RecipeType<T> type) {
- return this.byType.get(type);
+ return (Collection) this.byType.get(type); // CraftBukkit - decompile error
}
public Collection<RecipeHolder<?>> values() {
public <I extends RecipeInput, T extends Recipe<I>> Collection<RecipeHolder<T>> byType(RecipeType<T> type) {
return (Collection)this.byType.get(type);

View file

@ -1,30 +1,16 @@
--- a/net/minecraft/world/item/crafting/ShapedRecipe.java
+++ b/net/minecraft/world/item/crafting/ShapedRecipe.java
@@ -16,6 +16,13 @@
import net.minecraft.world.item.crafting.display.ShapedCraftingRecipeDisplay;
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
+import org.bukkit.inventory.RecipeChoice;
+// CraftBukkit end
public class ShapedRecipe implements CraftingRecipe {
@@ -39,7 +46,69 @@
this(group, category, raw, result, true);
@@ -103,6 +_,68 @@
);
}
+ // CraftBukkit start
@Override
+ public org.bukkit.inventory.ShapedRecipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
+ CraftShapedRecipe recipe = new CraftShapedRecipe(id, result, this);
+ @Override
+ public org.bukkit.inventory.ShapedRecipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result);
+ org.bukkit.craftbukkit.inventory.CraftShapedRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftShapedRecipe(id, result, this);
+ recipe.setGroup(this.group);
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ switch (this.pattern.height()) {
+ case 1:
@ -69,8 +55,8 @@
+ }
+ char c = 'a';
+ for (Optional<Ingredient> list : this.pattern.ingredients()) {
+ RecipeChoice choice = CraftRecipe.toBukkit(list);
+ if (choice != RecipeChoice.empty()) { // Paper
+ org.bukkit.inventory.RecipeChoice choice = org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(list);
+ if (choice != org.bukkit.inventory.RecipeChoice.empty()) { // Paper
+ recipe.setIngredient(c, choice);
+ }
+
@ -80,7 +66,6 @@
+ }
+ // CraftBukkit end
+
+ @Override
public RecipeSerializer<? extends ShapedRecipe> getSerializer() {
return RecipeSerializer.SHAPED_RECIPE;
}
public static class Serializer implements RecipeSerializer<ShapedRecipe> {
public static final MapCodec<ShapedRecipe> CODEC = RecordCodecBuilder.mapCodec(
instance -> instance.group(

View file

@ -0,0 +1,24 @@
--- a/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -31,6 +_,21 @@
this.ingredients = ingredients;
}
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.ShapelessRecipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result);
+ org.bukkit.craftbukkit.inventory.CraftShapelessRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftShapelessRecipe(id, result, this);
+ recipe.setGroup(this.group);
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ for (Ingredient list : this.ingredients) {
+ recipe.addIngredient(org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(list));
+ }
+ return recipe;
+ }
+ // CraftBukkit end
+
@Override
public RecipeSerializer<ShapelessRecipe> getSerializer() {
return RecipeSerializer.SHAPELESS_RECIPE;

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/item/crafting/SmeltingRecipe.java
+++ b/net/minecraft/world/item/crafting/SmeltingRecipe.java
@@ -32,4 +_,17 @@
case MISC -> RecipeBookCategories.FURNACE_MISC;
};
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result());
+
+ org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -0,0 +1,46 @@
--- a/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
+++ b/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
@@ -21,8 +_,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;
@@ -32,7 +_,9 @@
@Override
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;
}
@@ -77,6 +_,17 @@
)
);
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result);
+
+ org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.template), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.base), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.addition), this.copyDataComponents); // Paper - Option to prevent data components copy
+
+ return recipe;
+ }
+ // CraftBukkit end
public static class Serializer implements RecipeSerializer<SmithingTransformRecipe> {
private static final MapCodec<SmithingTransformRecipe> CODEC = RecordCodecBuilder.mapCodec(

View file

@ -0,0 +1,58 @@
--- a/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
+++ b/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
@@ -27,8 +_,15 @@
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;
@@ -36,10 +_,15 @@
@Override
public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider registries) {
- return applyTrim(registries, input.base(), input.addition(), input.template());
+ return applyTrim(registries, input.base(), input.addition(), input.template(), this.copyDataComponents); // Paper - Option to prevent data components copy
}
public static ItemStack applyTrim(HolderLookup.Provider registries, ItemStack base, ItemStack addition, ItemStack template) {
+ // Paper start - Option to prevent data components copy
+ return applyTrim(registries, base, addition, template, true);
+ }
+ public static ItemStack applyTrim(HolderLookup.Provider registries, ItemStack base, ItemStack addition, ItemStack template, boolean copyDataComponents) {
+ // Paper end - Option to prevent data components copy
Optional<Holder.Reference<TrimMaterial>> fromIngredient = TrimMaterials.getFromIngredient(registries, addition);
Optional<Holder.Reference<TrimPattern>> fromTemplate = TrimPatterns.getFromTemplate(registries, template);
if (fromIngredient.isPresent() && fromTemplate.isPresent()) {
@@ -47,7 +_,7 @@
if (armorTrim != null && armorTrim.hasPatternAndMaterial(fromTemplate.get(), fromIngredient.get())) {
return ItemStack.EMPTY;
} else {
- ItemStack itemStack = base.copyWithCount(1);
+ ItemStack itemStack = copyDataComponents ? base.copyWithCount(1) : new ItemStack(base.getItem(), 1); // Paper - Option to prevent data components copy
itemStack.set(DataComponents.TRIM, new ArmorTrim(fromIngredient.get(), fromTemplate.get()));
return itemStack;
}
@@ -100,6 +_,13 @@
)
);
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ return new org.bukkit.craftbukkit.inventory.CraftSmithingTrimRecipe(id, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.template), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.base), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.addition), this.copyDataComponents); // Paper - Option to prevent data components copy
+ }
+ // CraftBukkit end
public static class Serializer implements RecipeSerializer<SmithingTrimRecipe> {
private static final MapCodec<SmithingTrimRecipe> CODEC = RecordCodecBuilder.mapCodec(

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/item/crafting/SmokingRecipe.java
+++ b/net/minecraft/world/item/crafting/SmokingRecipe.java
@@ -28,4 +_,17 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.SMOKER_FOOD;
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result());
+
+ org.bukkit.craftbukkit.inventory.CraftSmokingRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftSmokingRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -0,0 +1,19 @@
--- a/net/minecraft/world/item/crafting/StonecutterRecipe.java
+++ b/net/minecraft/world/item/crafting/StonecutterRecipe.java
@@ -35,4 +_,16 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.STONECUTTER;
}
+
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack result = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.result());
+
+ org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe(id, result, org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input()));
+ recipe.setGroup(this.group());
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -0,0 +1,16 @@
--- a/net/minecraft/world/item/crafting/TransmuteRecipe.java
+++ b/net/minecraft/world/item/crafting/TransmuteRecipe.java
@@ -88,6 +_,13 @@
);
}
+ // CraftBukkit start
+ @Override
+ public org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id) {
+ return new org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe(id, org.bukkit.craftbukkit.inventory.CraftItemType.minecraftToBukkit(this.result.value()), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.input), org.bukkit.craftbukkit.inventory.CraftRecipe.toBukkit(this.material));
+ }
+ // CraftBukkit end
+
@Override
public RecipeSerializer<TransmuteRecipe> getSerializer() {
return RecipeSerializer.TRANSMUTE;

View file

@ -1,35 +0,0 @@
--- a/net/minecraft/world/item/crafting/BlastingRecipe.java
+++ b/net/minecraft/world/item/crafting/BlastingRecipe.java
@@ -4,6 +4,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftBlastingRecipe;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class BlastingRecipe extends AbstractCookingRecipe {
public BlastingRecipe(String group, CookingBookCategory category, Ingredient ingredient, ItemStack result, float experience, int cookingTime) {
@@ -43,4 +51,17 @@
return recipebookcategory;
}
+
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
+
+ CraftBlastingRecipe recipe = new CraftBlastingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -1,35 +0,0 @@
--- a/net/minecraft/world/item/crafting/CampfireCookingRecipe.java
+++ b/net/minecraft/world/item/crafting/CampfireCookingRecipe.java
@@ -4,6 +4,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftCampfireRecipe;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class CampfireCookingRecipe extends AbstractCookingRecipe {
public CampfireCookingRecipe(String group, CookingBookCategory category, Ingredient ingredient, ItemStack result, float experience, int cookingTime) {
@@ -29,4 +37,17 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.CAMPFIRE;
}
+
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
+
+ CraftCampfireRecipe recipe = new CraftCampfireRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -1,54 +0,0 @@
--- a/net/minecraft/world/item/crafting/CustomRecipe.java
+++ b/net/minecraft/world/item/crafting/CustomRecipe.java
@@ -8,6 +8,15 @@
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
+// CraftBukkit start
+import net.minecraft.world.item.ItemStack;
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftComplexRecipe;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public abstract class CustomRecipe implements CraftingRecipe {
private final CraftingBookCategory category;
@@ -34,6 +43,19 @@
@Override
public abstract RecipeSerializer<? extends CustomRecipe> getSerializer();
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(ItemStack.EMPTY);
+
+ CraftComplexRecipe recipe = new CraftComplexRecipe(id, result, this);
+ recipe.setGroup(this.group());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
+
public static class Serializer<T extends CraftingRecipe> implements RecipeSerializer<T> {
private final MapCodec<T> codec;
@@ -41,13 +63,13 @@
public Serializer(CustomRecipe.Serializer.Factory<T> factory) {
this.codec = RecordCodecBuilder.mapCodec((instance) -> {
- P1 p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CraftingRecipe::category));
+ P1<RecordCodecBuilder.Mu<T>, CraftingBookCategory> p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CraftingRecipe::category)); // CraftBukkit - decompile error
Objects.requireNonNull(factory);
return p1.apply(instance, factory::create);
});
StreamCodec streamcodec = CraftingBookCategory.STREAM_CODEC;
- Function function = CraftingRecipe::category;
+ Function<CraftingRecipe, CraftingBookCategory> function = CraftingRecipe::category; // CraftBukkit - decompile error
Objects.requireNonNull(factory);
this.streamCodec = StreamCodec.composite(streamcodec, function, factory::create);

View file

@ -1,66 +0,0 @@
--- a/net/minecraft/world/item/crafting/Ingredient.java
+++ b/net/minecraft/world/item/crafting/Ingredient.java
@@ -20,6 +20,10 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.level.ItemLike;
+// CraftBukkit start
+import java.util.List;
+import javax.annotation.Nullable;
+// CraftBukkit end
public final class Ingredient implements StackedContents.IngredientInfo<Holder<Item>>, Predicate<ItemStack> {
@@ -38,7 +42,25 @@
return recipeitemstack.values;
});
private final HolderSet<Item> values;
+ // CraftBukkit start
+ @Nullable
+ private List<ItemStack> itemStacks;
+ public boolean isExact() {
+ return this.itemStacks != null;
+ }
+
+ public List<ItemStack> itemStacks() {
+ return this.itemStacks;
+ }
+
+ public static Ingredient ofStacks(List<ItemStack> stacks) {
+ Ingredient recipe = Ingredient.of(stacks.stream().map(ItemStack::getItem));
+ recipe.itemStacks = stacks;
+ return recipe;
+ }
+ // CraftBukkit end
+
private Ingredient(HolderSet<Item> entries) {
entries.unwrap().ifRight((list) -> {
if (list.isEmpty()) {
@@ -70,6 +92,17 @@
}
public boolean test(ItemStack itemstack) {
+ // CraftBukkit start
+ if (this.isExact()) {
+ for (ItemStack itemstack1 : this.itemStacks()) {
+ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // CraftBukkit end
return itemstack.is(this.values);
}
@@ -79,7 +112,7 @@
public boolean equals(Object object) {
if (object instanceof Ingredient recipeitemstack) {
- return Objects.equals(this.values, recipeitemstack.values);
+ return Objects.equals(this.values, recipeitemstack.values) && Objects.equals(this.itemStacks, recipeitemstack.itemStacks); // CraftBukkit
} else {
return false;
}

View file

@ -1,26 +0,0 @@
--- a/net/minecraft/world/item/crafting/RecipeHolder.java
+++ b/net/minecraft/world/item/crafting/RecipeHolder.java
@@ -5,10 +5,21 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceKey;
-public record RecipeHolder<T extends Recipe<?>>(ResourceKey<Recipe<?>> id, T value) {
+// CraftBukkit start
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
- public static final StreamCodec<RegistryFriendlyByteBuf, RecipeHolder<?>> STREAM_CODEC = StreamCodec.composite(ResourceKey.streamCodec(Registries.RECIPE), RecipeHolder::id, Recipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new);
+public record RecipeHolder<T extends net.minecraft.world.item.crafting.Recipe<?>>(ResourceKey<net.minecraft.world.item.crafting.Recipe<?>> id, T value) {
+ // CraftBukkit start
+ public final Recipe toBukkitRecipe() {
+ return this.value.toBukkitRecipe(CraftNamespacedKey.fromMinecraft(this.id.location()));
+ }
+ // CraftBukkit end
+
+ public static final StreamCodec<RegistryFriendlyByteBuf, RecipeHolder<?>> STREAM_CODEC = StreamCodec.composite(ResourceKey.streamCodec(Registries.RECIPE), RecipeHolder::id, net.minecraft.world.item.crafting.Recipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new);
+
public boolean equals(Object object) {
if (this == object) {
return true;

View file

@ -1,111 +0,0 @@
--- a/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
@@ -26,11 +26,6 @@
import net.minecraft.resources.FileToIdConverter;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
-import net.minecraft.server.level.ServerLevel;
-import net.minecraft.server.packs.resources.ResourceManager;
-import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
-import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
-import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.display.RecipeDisplay;
@@ -39,6 +34,16 @@
import net.minecraft.world.level.Level;
import org.slf4j.Logger;
+// CraftBukkit start
+import java.util.Collections;
+import net.minecraft.server.MinecraftServer;
+// CraftBukkit end
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.packs.resources.ResourceManager;
+import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
+import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
+import net.minecraft.util.profiling.ProfilerFiller;
+
public class RecipeManager extends SimplePreparableReloadListener<RecipeMap> implements RecipeAccess {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -111,7 +116,26 @@
RecipeManager.LOGGER.info("Loaded {} recipes", prepared.values().size());
}
+ // CraftBukkit start
+ public void addRecipe(RecipeHolder<?> irecipe) {
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
+ this.recipes.addRecipe(irecipe);
+ this.finalizeRecipeLoading();
+ }
+
+ private FeatureFlagSet featureflagset;
+
+ public void finalizeRecipeLoading() {
+ if (this.featureflagset != null) {
+ this.finalizeRecipeLoading(this.featureflagset);
+
+ MinecraftServer.getServer().getPlayerList().reloadRecipes();
+ }
+ }
+
public void finalizeRecipeLoading(FeatureFlagSet features) {
+ this.featureflagset = features;
+ // CraftBukkit end
List<SelectableRecipe.SingleInputEntry<StonecutterRecipe>> list = new ArrayList();
List<RecipeManager.IngredientCollector> list1 = RecipeManager.RECIPE_PROPERTY_SETS.entrySet().stream().map((entry) -> {
return new RecipeManager.IngredientCollector((ResourceKey) entry.getKey(), (RecipeManager.IngredientExtractor) entry.getValue());
@@ -130,7 +154,7 @@
StonecutterRecipe recipestonecutting = (StonecutterRecipe) irecipe;
if (RecipeManager.isIngredientEnabled(features, recipestonecutting.input()) && recipestonecutting.resultDisplay().isEnabled(features)) {
- list.add(new SelectableRecipe.SingleInputEntry<>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of(recipeholder))));
+ list.add(new SelectableRecipe.SingleInputEntry<StonecutterRecipe>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of((RecipeHolder<StonecutterRecipe>) recipeholder)))); // CraftBukkit - decompile error
}
}
@@ -172,7 +196,10 @@
}
public <I extends RecipeInput, T extends Recipe<I>> Optional<RecipeHolder<T>> getRecipeFor(RecipeType<T> type, I input, Level world) {
- return this.recipes.getRecipesFor(type, input, world).findFirst();
+ // CraftBukkit start
+ List<RecipeHolder<T>> list = this.recipes.getRecipesFor(type, input, world).toList();
+ return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority
+ // CraftBukkit end
}
public Optional<RecipeHolder<?>> byKey(ResourceKey<Recipe<?>> key) {
@@ -183,7 +210,7 @@
private <T extends Recipe<?>> RecipeHolder<T> byKeyTyped(RecipeType<T> type, ResourceKey<Recipe<?>> key) {
RecipeHolder<?> recipeholder = this.recipes.byKey(key);
- return recipeholder != null && recipeholder.value().getType().equals(type) ? recipeholder : null;
+ return recipeholder != null && recipeholder.value().getType().equals(type) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error
}
public Map<ResourceKey<RecipePropertySet>, RecipePropertySet> getSynchronizedItemProperties() {
@@ -231,6 +258,22 @@
return new RecipeHolder<>(key, irecipe);
}
+ // CraftBukkit start
+ public boolean removeRecipe(ResourceKey<Recipe<?>> mcKey) {
+ boolean removed = this.recipes.removeRecipe((ResourceKey<Recipe<RecipeInput>>) (ResourceKey) mcKey); // Paper - generic fix
+ if (removed) {
+ this.finalizeRecipeLoading();
+ }
+
+ return removed;
+ }
+
+ public void clearRecipes() {
+ this.recipes = RecipeMap.create(Collections.emptyList());
+ this.finalizeRecipeLoading();
+ }
+ // CraftBukkit end
+
public static <I extends RecipeInput, T extends Recipe<I>> RecipeManager.CachedCheck<I, T> createCheck(final RecipeType<T> type) {
return new RecipeManager.CachedCheck<I, T>() {
@Nullable

View file

@ -1,39 +0,0 @@
--- a/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -16,6 +16,12 @@
import net.minecraft.world.item.crafting.display.ShapelessCraftingRecipeDisplay;
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
+// CraftBukkit end
public class ShapelessRecipe implements CraftingRecipe {
@@ -33,7 +39,23 @@
this.ingredients = ingredients;
}
+ // CraftBukkit start
+ @SuppressWarnings("unchecked")
@Override
+ public org.bukkit.inventory.ShapelessRecipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
+ CraftShapelessRecipe recipe = new CraftShapelessRecipe(id, result, this);
+ recipe.setGroup(this.group);
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ for (Ingredient list : this.ingredients) {
+ recipe.addIngredient(CraftRecipe.toBukkit(list));
+ }
+ return recipe;
+ }
+ // CraftBukkit end
+
+ @Override
public RecipeSerializer<ShapelessRecipe> getSerializer() {
return RecipeSerializer.SHAPELESS_RECIPE;
}

View file

@ -1,35 +0,0 @@
--- a/net/minecraft/world/item/crafting/SmeltingRecipe.java
+++ b/net/minecraft/world/item/crafting/SmeltingRecipe.java
@@ -4,6 +4,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class SmeltingRecipe extends AbstractCookingRecipe {
public SmeltingRecipe(String group, CookingBookCategory category, Ingredient ingredient, ItemStack result, float experience, int cookingTime) {
@@ -45,4 +53,17 @@
return recipebookcategory;
}
+
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
+
+ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -1,61 +0,0 @@
--- a/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
+++ b/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
@@ -14,6 +14,14 @@
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.item.crafting.display.SmithingRecipeDisplay;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class SmithingTransformRecipe implements SmithingRecipe {
final Optional<Ingredient> template;
@@ -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)));
}
+ // CraftBukkit start
+ @Override
+ 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), this.copyDataComponents); // Paper - Option to prevent data components copy
+
+ return recipe;
+ }
+ // CraftBukkit end
+
public static class Serializer implements RecipeSerializer<SmithingTransformRecipe> {
private static final MapCodec<SmithingTransformRecipe> CODEC = RecordCodecBuilder.mapCodec((instance) -> {

View file

@ -1,69 +0,0 @@
--- a/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
+++ b/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
@@ -21,6 +21,13 @@
import net.minecraft.world.item.equipment.trim.TrimPattern;
import net.minecraft.world.item.equipment.trim.TrimPatterns;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftSmithingTrimRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class SmithingTrimRecipe implements SmithingRecipe {
final Optional<Ingredient> template;
@@ -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), this.copyDataComponents); // Paper - Option to prevent data components copy
+ }
+ // CraftBukkit end
+
public static class Serializer implements RecipeSerializer<SmithingTrimRecipe> {
private static final MapCodec<SmithingTrimRecipe> CODEC = RecordCodecBuilder.mapCodec((instance) -> {

View file

@ -1,35 +0,0 @@
--- a/net/minecraft/world/item/crafting/SmokingRecipe.java
+++ b/net/minecraft/world/item/crafting/SmokingRecipe.java
@@ -4,6 +4,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftSmokingRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class SmokingRecipe extends AbstractCookingRecipe {
public SmokingRecipe(String group, CookingBookCategory category, Ingredient ingredient, ItemStack result, float experience, int cookingTime) {
@@ -29,4 +37,17 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.SMOKER_FOOD;
}
+
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
+
+ CraftSmokingRecipe recipe = new CraftSmokingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
+ recipe.setGroup(this.group());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -1,34 +0,0 @@
--- a/net/minecraft/world/item/crafting/StonecutterRecipe.java
+++ b/net/minecraft/world/item/crafting/StonecutterRecipe.java
@@ -7,6 +7,14 @@
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.item.crafting.display.StonecutterRecipeDisplay;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public class StonecutterRecipe extends SingleItemRecipe {
public StonecutterRecipe(String group, Ingredient ingredient, ItemStack result) {
@@ -36,4 +44,16 @@
public RecipeBookCategory recipeBookCategory() {
return RecipeBookCategories.STONECUTTER;
}
+
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
+
+ CraftStonecuttingRecipe recipe = new CraftStonecuttingRecipe(id, result, CraftRecipe.toBukkit(this.input()));
+ recipe.setGroup(this.group());
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View file

@ -1,31 +0,0 @@
--- a/net/minecraft/world/item/crafting/TransmuteRecipe.java
+++ b/net/minecraft/world/item/crafting/TransmuteRecipe.java
@@ -19,6 +19,13 @@
import net.minecraft.world.item.crafting.display.SlotDisplay;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemType;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
public class TransmuteRecipe implements CraftingRecipe {
@@ -84,7 +91,14 @@
return List.of(new ShapelessCraftingRecipeDisplay(List.of(this.input.display(), this.material.display()), new SlotDisplay.ItemSlotDisplay(this.result), new SlotDisplay.ItemSlotDisplay(Items.CRAFTING_TABLE)));
}
+ // CraftBukkit start
@Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ return new CraftTransmuteRecipe(id, CraftItemType.minecraftToBukkit(this.result.value()), CraftRecipe.toBukkit(this.input), CraftRecipe.toBukkit(this.material));
+ }
+ // CraftBukkit end
+
+ @Override
public RecipeSerializer<TransmuteRecipe> getSerializer() {
return RecipeSerializer.TRANSMUTE;
}