Skip to content

Commit

Permalink
Fix bug preventing items from being picked up
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanyeti committed May 3, 2024
1 parent 9ff8d74 commit 98df011
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion BetterRanching/BetterRanching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion BetterRanching/GameExtensions.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion BetterRanching/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

<h2>Other Contributors</h2>

Expand Down

0 comments on commit 98df011

Please sign in to comment.