-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Patches.cs
66 lines (60 loc) · 1.86 KB
/
Patches.cs
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
62
63
64
65
66
using System;
using System.Diagnostics;
using System.Linq;
using Terraria;
namespace RecipeBrowser
{
public static class Patches
{
private static bool AdjTilesActive = false;
public static void Apply()
{
// Patches are automatically unapplied on unload by TerrariaHooks. -ade
// This patch Invalidates the precomputed extended craft unless the reason for FindRecipes was just AdjTiles, since we ignore AdjTiles changes.
if(!Main.dedServ)
Terraria.On_Recipe.FindRecipes += (orig, canDelayCheck) =>
{
orig(canDelayCheck);
if(!AdjTilesActive)
//if (!new StackTrace().GetFrames().Any(x => x.GetMethod().Name.StartsWith("AdjTiles")))
{
RecipeCatalogueUI.instance.InvalidateExtendedCraft();
//Main.NewText("FindRecipes postfix: InvalidateExtendedCraft");
}
else
{
//Main.NewText("FindRecipes postfix: skipped");
}
};
// This patch will call FindRecipes even if the player inventory is closed, keeping Craft tool buttons accurate.
Terraria.On_Player.AdjTiles += (orig, player) => {
AdjTilesActive = true;
orig(player);
// AdjTiles does the opposite. This way recipes will be calculated
if (!Main.playerInventory && RecipeBrowserUI.instance.ShowRecipeBrowser) // Inverted condition.
{
bool flag = false;
for (int l = 0; l < Main.LocalPlayer.adjTile.Length; l++) {
if (Main.LocalPlayer.oldAdjTile[l] != Main.LocalPlayer.adjTile[l]) {
flag = true;
break;
}
}
if (Main.LocalPlayer.adjWater != Main.LocalPlayer.oldAdjWater) {
flag = true;
}
if (Main.LocalPlayer.adjHoney != Main.LocalPlayer.oldAdjHoney) {
flag = true;
}
if (Main.LocalPlayer.adjLava != Main.LocalPlayer.oldAdjLava) {
flag = true;
}
if (flag) {
Recipe.FindRecipes();
}
}
AdjTilesActive = false;
};
}
}
}