-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandbookPatches.cs
More file actions
61 lines (51 loc) · 2.02 KB
/
Copy pathHandbookPatches.cs
File metadata and controls
61 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Reflection;
using HarmonyLib;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
namespace QuickCraft;
[HarmonyPatch]
public static class CreatedByInfoPatch
{
public static IEnumerable<MethodBase> TargetMethods()
{
Type? type = AccessTools.TypeByName("Vintagestory.GameContent.CollectibleBehaviorHandbookTextAndExtraInfo");
MethodInfo? method = type == null ? null : AccessTools.Method(type, "addCreatedByInfo");
if (method != null)
{
yield return method;
}
}
public static void Postfix(List<RichTextComponentBase>? components)
{
ICoreClientAPI? api = HandbookSpaceCrafting.ClientApi;
if (api == null || components == null)
{
return;
}
for (int i = 0; i < components.Count; i++)
{
if (components[i] is not SlideshowGridRecipeTextComponent gridComponent)
{
continue;
}
GridRecipeAndUnnamedIngredients[] group = SlideshowRecipeReader.GetRecipeGroup(gridComponent);
if (group.Length == 0)
{
continue;
}
GridRecipe[] recipes = RecipeVariantCollector.IncludeSameOutputVariants(api, group.Select(entry => entry.Recipe));
if (recipes.Length == 0)
{
continue;
}
RichTextComponentBase[] buttons =
{
RecipeActionLinks.Create(api, "[ + ]", "addone", new double[] { 0.68, 1.0, 0.72, 1.0 }, () => HandbookSpaceCrafting.TryFillRecipes(recipes, max: false)),
RecipeActionLinks.Create(api, "[ * ]", "craftmax", new double[] { 1.0, 0.86, 0.42, 1.0 }, () => HandbookSpaceCrafting.TryCraftRecipes(recipes)),
RecipeActionLinks.Create(api, "[ ALL ]", "craftall", new double[] { 0.55, 0.9, 1.0, 1.0 }, () => HandbookSpaceCrafting.TryCraftAllRecipes(recipes))
};
components.InsertRange(i + 1, buttons);
i += buttons.Length;
}
}
}