diff --git a/BetterRanching/BetterRanching.cs b/BetterRanching/BetterRanching.cs index c7ab864..866c8b1 100644 --- a/BetterRanching/BetterRanching.cs +++ b/BetterRanching/BetterRanching.cs @@ -124,7 +124,7 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e) if (!Context.IsWorldReady) return; if (!e.Button.IsUseToolButton() || !Config.PreventFailedHarvesting || - !GameExtensions.HoldingOverridableTool() || !GameExtensions.IsClickableArea()) return; + !GameExtensions.HoldingOverridableTool() || !GameExtensions.IsClickableArea() || GameExtensions.PlayerCanGrabSomething()) return; var who = Game1.player; Vector2 position = ((!Game1.wasMouseVisibleThisFrame) ? who.GetToolLocation() : new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y)); @@ -167,6 +167,7 @@ private void OverrideRanching(GameLocation currentLocation, int x, int y, Farmer break; } + animal = Utility.GetBestHarvestableFarmAnimal(toolRect: new Rectangle(x - 32, y - 32, 64, 64), animals: currentLocation.animals.Values, tool: who.CurrentTool); if (animal == null) diff --git a/BetterRanching/GameExtensions.cs b/BetterRanching/GameExtensions.cs index 801570d..51b8e3c 100644 --- a/BetterRanching/GameExtensions.cs +++ b/BetterRanching/GameExtensions.cs @@ -1,6 +1,12 @@ -using System.Linq; +using System; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; using StardewModdingAPI; using StardewValley; +using StardewValley.TerrainFeatures; +using xTile.Dimensions; +using xTile.Tiles; namespace BetterRanching { @@ -31,5 +37,17 @@ public static bool IsClickableArea() var (x, y) = Game1.getMousePosition(); return Game1.onScreenMenus.All(screen => !screen.isWithinBounds(x, y)); } + + public static bool PlayerCanGrabSomething() + { + var who = Game1.player; + GameLocation location = Game1.currentLocation; + Point tilePoint = who.TilePoint; + + if (Game1.player.canOnlyWalk) + return true; + Vector2 position = !Game1.wasMouseVisibleThisFrame ? Game1.player.GetToolLocation() : new Vector2((float)(Game1.getOldMouseX() + Game1.viewport.X), (float)(Game1.getOldMouseY() + Game1.viewport.Y)); + return Utility.canGrabSomethingFromHere((int)position.X, (int)position.Y, Game1.player); + } } } \ No newline at end of file diff --git a/BetterRanching/manifest.json b/BetterRanching/manifest.json index 5b165ac..945e211 100644 --- a/BetterRanching/manifest.json +++ b/BetterRanching/manifest.json @@ -1,7 +1,7 @@ { "Name": "Better Ranching", "Author": "Urbanyeti", - "Version": "2.0.4", + "Version": "2.0.5", "Description": "Prevents failed milk/shear attempts and displays when animals can be milked/sheared and petted.", "UniqueID": "BetterRanching", "EntryDll": "BetterRanching.dll", diff --git a/README.md b/README.md index b8698f2..ccb34a4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Stardew Valley mod that prevents failing milking/shearing attempts and adds an i Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4.0.0 or later. -**Update 2.0.4 (2024/04/30)**: Fixed a bug that was causing the wrong icon to show for custom items. Thank you to kitsutsune and their awesome [Chocobo Valley](https://www.nexusmods.com/stardewvalley/mods/22226/) mod for bringing this to my attention! Also fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets. +**Update 2.0.5 (2024/05/02)**: Fixed a bug preventing items from being picked up while holding tool. Fixed a bug that was causing the wrong icon to show for custom items. Thank you to kitsutsune and their awesome [Chocobo Valley](https://www.nexusmods.com/stardewvalley/mods/22226/) mod for bringing this to my attention! Also fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets. ![Preview image](/better_ranching_preview.gif) @@ -81,6 +81,8 @@ Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4 * 2.0.4: * Added support for custom harvest items to display above animals! * Fixed bug causing "Hide Hearts w/ Max Friendship" setting to be ignored for pets +* 2.0.5: + * Fixed bug causing items to not be able to be picked up while holding tool

Other Contributors