-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModState.cs
46 lines (38 loc) · 1.76 KB
/
ModState.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
using System.Linq;
using Microsoft.Xna.Framework;
using Netcode;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Network;
using StardewValley.TerrainFeatures;
using Object = StardewValley.Object;
namespace PlacementPlus
{
/// <summary> Static class holding and maintaining data used primarily in Harmony patches. </summary>
public static class ModState
{
internal static Vector2 CursorTile;
internal static Item HeldItem;
internal static bool HoldingToolButton;
internal static Object TileObject;
internal static NetVector2Dictionary<TerrainFeature,NetRef<TerrainFeature>> TerrainFeatures;
internal static readonly IMonitor Monitor = PlacementPlus.Instance.Monitor;
private static bool initialized;
/// <summary> Initializes ModState to begin tracking values. </summary>
/// <param name="helper">An <see cref="IModHelper">IModHelper</see> reference for hooking into events.</param>
public static void Initialize(ref IModHelper helper)
{
if (initialized) return;
helper.Events.Input.ButtonsChanged += (_, e) => {
if (!Context.IsWorldReady) return;
// Updating mod state fields.
TerrainFeatures = Game1.player.currentLocation.terrainFeatures;
CursorTile = e.Cursor.Tile;
HeldItem = Game1.player.CurrentItem;
HoldingToolButton = e.Held.Any(button => button.IsUseToolButton()); // (i.e. left click)
TileObject = Game1.player.currentLocation.getObjectAtTile((int) e.Cursor.Tile.X, (int) e.Cursor.Tile.Y);
};
initialized = true;
}
}
}