From d953eafc461a82686f6c45aea9c66d70ab630695 Mon Sep 17 00:00:00 2001 From: zombifier Date: Sat, 31 Aug 2024 17:33:05 -0400 Subject: [PATCH 1/2] Fix integration with Better Crafting and SpaceCore recipes. The fix on BetterCrafting side: https://github.com/KhloeLeclair/StardewMods/pull/34 --- CookingSkillRedux/Core/Events.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CookingSkillRedux/Core/Events.cs b/CookingSkillRedux/Core/Events.cs index ab9440e4..4be5f4c9 100644 --- a/CookingSkillRedux/Core/Events.cs +++ b/CookingSkillRedux/Core/Events.cs @@ -62,9 +62,10 @@ private static void AfterGiftGiven(object sender, EventArgsGiftGiven e) private static void BetterCraftingPerformCraftEvent(IGlobalPerformCraftEvent @event) { - if (@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) + if ((@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) || + (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.TryGetValue(@event.Recipe.Name, out var vanillaCookingRecipe))) { - @event.Item = PreCook(@event.Recipe.CraftingRecipe, @event.Item, true); + @event.Item = PreCook(@event.Recipe.CraftingRecipe ?? new CraftingRecipe(@event.Recipe.Name, true), @event.Item, true); @event.Complete(); } @event.Complete(); @@ -73,7 +74,9 @@ private static void BetterCraftingPerformCraftEvent(IGlobalPerformCraftEvent @ev private static void BetterCraftingPostCraftEvent(IPostCraftEvent @event) { - if (@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) + // SpaceCore override recipes don't have CraftingRecipe set. In this case compare against vanilla cooking recipes + if ((@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) || + (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.TryGetValue(@event.Recipe.Name, out var vanillaCookingRecipe))) { //it's easier for me to use a dictionary to not override item stack sized Dictionary consumed_items_dict = new Dictionary(); @@ -82,9 +85,9 @@ private static void BetterCraftingPostCraftEvent(IPostCraftEvent @event) consumed_items_dict.Add(consumed, consumed.Stack); } - @event.Item = PostCook(@event.Recipe.CraftingRecipe, @event.Item, consumed_items_dict, @event.Player, true); + @event.Item = PostCook(@event.Recipe.CraftingRecipe ?? new CraftingRecipe(@event.Recipe.Name, true), @event.Item, consumed_items_dict, @event.Player, true); } - + } [SEvent.MenuChanged] @@ -311,7 +314,7 @@ public static void OnItemEat(object sender, EventArgs e) } } } - + // If the player has the right profession, give them an extra buff if (player.HasCustomProfession(Cooking_Skill.Cooking10b2)) @@ -454,7 +457,7 @@ public static Item PostCook(CraftingRecipe recipe, Item item, Dictionary Date: Sat, 31 Aug 2024 17:38:11 -0400 Subject: [PATCH 2/2] Minor fix --- CookingSkillRedux/Core/Events.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CookingSkillRedux/Core/Events.cs b/CookingSkillRedux/Core/Events.cs index 4be5f4c9..6041825a 100644 --- a/CookingSkillRedux/Core/Events.cs +++ b/CookingSkillRedux/Core/Events.cs @@ -63,7 +63,7 @@ private static void AfterGiftGiven(object sender, EventArgsGiftGiven e) private static void BetterCraftingPerformCraftEvent(IGlobalPerformCraftEvent @event) { if ((@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) || - (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.TryGetValue(@event.Recipe.Name, out var vanillaCookingRecipe))) + (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.ContainsKey(@event.Recipe.Name))) { @event.Item = PreCook(@event.Recipe.CraftingRecipe ?? new CraftingRecipe(@event.Recipe.Name, true), @event.Item, true); @event.Complete(); @@ -76,7 +76,7 @@ private static void BetterCraftingPostCraftEvent(IPostCraftEvent @event) { // SpaceCore override recipes don't have CraftingRecipe set. In this case compare against vanilla cooking recipes if ((@event.Recipe.CraftingRecipe is not null && @event.Recipe.CraftingRecipe.isCookingRecipe) || - (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.TryGetValue(@event.Recipe.Name, out var vanillaCookingRecipe))) + (@event.Recipe.Name is not null && CraftingRecipe.cookingRecipes.ContainsKey(@event.Recipe.Name))) { //it's easier for me to use a dictionary to not override item stack sized Dictionary consumed_items_dict = new Dictionary();