--- a/net/minecraft/world/item/crafting/CraftingManager.java
+++ b/net/minecraft/world/item/crafting/CraftingManager.java
@@ -39,6 +39,11 @@
 import net.minecraft.world.level.World;
 import org.slf4j.Logger;
 
+// CraftBukkit start
+import java.util.Collections;
+import net.minecraft.server.MinecraftServer;
+// CraftBukkit end
+
 public class CraftingManager extends ResourceDataAbstract<RecipeMap> implements RecipeAccess {
 
     private static final Logger LOGGER = LogUtils.getLogger();
@@ -111,7 +116,25 @@
         CraftingManager.LOGGER.info("Loaded {} recipes", recipemap.values().size());
     }
 
+    // CraftBukkit start
+    public void addRecipe(RecipeHolder<?> irecipe) {
+        this.recipes.addRecipe(irecipe);
+        finalizeRecipeLoading();
+    }
+
+    private FeatureFlagSet featureflagset;
+
+    public void finalizeRecipeLoading() {
+        if (featureflagset != null) {
+            finalizeRecipeLoading(featureflagset);
+
+            MinecraftServer.getServer().getPlayerList().reloadRecipes();
+        }
+    }
+
     public void finalizeRecipeLoading(FeatureFlagSet featureflagset) {
+        this.featureflagset = featureflagset;
+        // CraftBukkit end
         List<SelectableRecipe.a<RecipeStonecutting>> list = new ArrayList();
         List<CraftingManager.b> list1 = CraftingManager.RECIPE_PROPERTY_SETS.entrySet().stream().map((entry) -> {
             return new CraftingManager.b((ResourceKey) entry.getKey(), (CraftingManager.c) entry.getValue());
@@ -130,7 +153,7 @@
                     RecipeStonecutting recipestonecutting = (RecipeStonecutting) irecipe;
 
                     if (isIngredientEnabled(featureflagset, recipestonecutting.input()) && recipestonecutting.resultDisplay().isEnabled(featureflagset)) {
-                        list.add(new SelectableRecipe.a<>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of(recipeholder))));
+                        list.add(new SelectableRecipe.a<RecipeStonecutting>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of((RecipeHolder<RecipeStonecutting>) recipeholder)))); // CraftBukkit - decompile error
                     }
                 }
 
@@ -172,7 +195,10 @@
     }
 
     public <I extends RecipeInput, T extends IRecipe<I>> Optional<RecipeHolder<T>> getRecipeFor(Recipes<T> recipes, I i0, World world) {
-        return this.recipes.getRecipesFor(recipes, i0, world).findFirst();
+        // CraftBukkit start
+        List<RecipeHolder<T>> list = this.recipes.getRecipesFor(recipes, i0, 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<IRecipe<?>> resourcekey) {
@@ -183,7 +209,7 @@
     private <T extends IRecipe<?>> RecipeHolder<T> byKeyTyped(Recipes<T> recipes, ResourceKey<IRecipe<?>> resourcekey) {
         RecipeHolder<?> recipeholder = this.recipes.byKey(resourcekey);
 
-        return recipeholder != null && recipeholder.value().getType().equals(recipes) ? recipeholder : null;
+        return recipeholder != null && recipeholder.value().getType().equals(recipes) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error
     }
 
     public Map<ResourceKey<RecipePropertySet>, RecipePropertySet> getSynchronizedItemProperties() {
@@ -231,6 +257,22 @@
         return new RecipeHolder<>(resourcekey, irecipe);
     }
 
+    // CraftBukkit start
+    public boolean removeRecipe(ResourceKey<IRecipe<?>> mcKey) {
+        boolean removed = this.recipes.removeRecipe(mcKey);
+        if (removed) {
+            finalizeRecipeLoading();
+        }
+
+        return removed;
+    }
+
+    public void clearRecipes() {
+        this.recipes = RecipeMap.create(Collections.emptyList());
+        finalizeRecipeLoading();
+    }
+    // CraftBukkit end
+
     public static <I extends RecipeInput, T extends IRecipe<I>> CraftingManager.a<I, T> createCheck(final Recipes<T> recipes) {
         return new CraftingManager.a<I, T>() {
             @Nullable
