forked from a-Bouchez/PanSlotMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPressUseToolButtonPatch.cs
More file actions
47 lines (37 loc) · 1.75 KB
/
Copy pathPressUseToolButtonPatch.cs
File metadata and controls
47 lines (37 loc) · 1.75 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
using HarmonyLib;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
namespace PanSlotMod
{
[HarmonyPatch(typeof(Game1), nameof(Game1.pressUseToolButton))]
public class PressUseToolButtonPatch
{
public static bool Prefix()
{
if (PanSlotState.StoredPan == null) return true;
if (!Context.IsWorldReady || !Context.CanPlayerMove) return true;
var player = Game1.player;
var location = player.currentLocation;
Vector2 position = Game1.wasMouseVisibleThisFrame
? new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y)
: player.GetToolLocation(false);
var cursorTile = new Vector2((int)(position.X / 64), (int)(position.Y / 64));
if (location.orePanPoint.Value == Point.Zero) return true;
if (location.orePanPoint.Value != new Point((int)cursorTile.X, (int)cursorTile.Y)) return true;
int previousIndex = player.CurrentToolIndex;
var previousItem = player.Items[previousIndex];
player.Items[previousIndex] = PanSlotState.StoredPan;
player.lastClick = new Vector2((int)position.X, (int)position.Y);
player.BeginUsingTool();
void OnUpdateTicked(object s, StardewModdingAPI.Events.UpdateTickedEventArgs e)
{
if (player.UsingTool) return;
player.Items[previousIndex] = previousItem;
ModEntry.ModHelper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
}
ModEntry.ModHelper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
return false;
}
}
}