StrangeLoopGames / EcoModKit

Eco Modkit
https://docs.play.eco
69 stars 25 forks source link

Modding: Allow disabling/removing vanilla recipes #28

Open jlai opened 2 years ago

jlai commented 2 years ago

Right now (9.4.x), there doesn't appear to be a good way to remove or disable vanilla recipes from the game short of copying & pasting the entire item cs into a .override.cs -- which is quite fragile, especially for mods intended for distribution.

ModsPreInitialize/ModsPostInitialize allows tweaking some of the recipe options but there's no way to skip the calls to Initialize and CraftingComponent.AddRecipe or remove a recipe from a crafting object (also meaning the crafting component can't be customized this way).

I'm thinking the default template constructor could be updated to something like this

this.CraftingObject = typeof(RockerBoxObject); // allow overriding

this.ModsPreInitialize();
if (!this.Recipes.Any()) return; // don't register recipe family if all recipes removed by mod
this.Initialize(Localizer.DoStr("Gold Concentrate"), typeof(GoldConcentrateRecipe));
this.ModsPostInitialize();
CraftingComponent.AddRecipe(this.CraftingObject, this);

There probably also needs to be some tweaks to whatever this code is doing, to skip empty recipe family classes:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Eco.Gameplay.Items.RecipeFamily.get_DefaultRecipe()
   at Eco.Gameplay.Items.RecipeFamily.get_Ingredients()
   at Eco.Gameplay.Items.RecipeFamily.<>c.<Initialize>b__77_14(RecipeFamily recipe)
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Eco.Gameplay.Items.RecipeFamily.Initialize()
   at Eco.ModKit.ModDataSync..ctor()
   at Eco.ModKit.ModKitPlugin.<LoadModsDataAsync>b__34_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
D3nnis3n commented 2 years ago

Moved to the ModKit repository.