Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with mods that override harvest tool or mods that add new custom tools #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions BetterRanching/BetterRanching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using StardewValley;
using StardewValley.Characters;
using StardewValley.GameData.FarmAnimals;
using StardewValley.Tools;

namespace BetterRanching
{
Expand Down Expand Up @@ -139,28 +140,28 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
toolRect);

OverrideRanching(Game1.currentLocation, (int)who.GetToolLocation().X, (int)who.GetToolLocation().Y, who,
e.Button, who.CurrentTool?.Name);
e.Button, who.CurrentTool);
}

private void OverrideRanching(GameLocation currentLocation, int x, int y, Farmer who, SButton button,
string toolName)
Tool tool)
{
AnimalBeingRanched = null;
FarmAnimal animal = null;
var ranchAction = string.Empty;
var ranchActionPresent = string.Empty;
var ranchProduct = string.Empty;

if (toolName == null) return;
if (tool == null) return;

switch (toolName)
switch (tool)
{
case GameConstants.Tools.MilkPail:
case MilkPail:
ranchAction = Helper.Translation.Get("action.unable.milk");
ranchActionPresent = Helper.Translation.Get("action.out_of_range.milk");
ranchProduct = Helper.Translation.Get("product.milk");
break;
case GameConstants.Tools.Shears:
case Shears:
ranchAction = Helper.Translation.Get("action.unable.shear");
ranchActionPresent = Helper.Translation.Get("action.out_of_range.shear");
ranchProduct = Helper.Translation.Get("product.wool");
Expand All @@ -178,14 +179,14 @@ private void OverrideRanching(GameLocation currentLocation, int x, int y, Farmer

FarmAnimalData animalData = animal.GetAnimalData();

if (animal.CanBeRanched(toolName))
if (animal.CanBeRanched(tool))
{
if (who.couldInventoryAcceptThisItem(animal.currentProduce.Value, (!animal.hasEatenAnimalCracker.Value) ? 1 : 2, animal.produceQuality.Value))
AnimalBeingRanched = animal;
else
Helper.Input.OverwriteState(button, Helper.Translation.Get("notification.inventory_full"));
}
else if (animal.isBaby() && animalData.HarvestTool == toolName)
else if (animal.isBaby() && animal.CanGetProduceWithTool(tool))
{
Helper.Input.OverwriteState(button);
DelayedAction.showDialogueAfterDelay(
Expand Down Expand Up @@ -215,4 +216,4 @@ private void OnRenderedWorld(object sender, RenderedWorldEventArgs e)
() => !pet.lastPetDay.TryGetValue(Game1.player.UniqueMultiplayerID, out var lastValue) || lastValue != Game1.Date.TotalDays);
}
}
}
}
6 changes: 3 additions & 3 deletions BetterRanching/BetterRanchingApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using StardewValley;
using StardewValley.Characters;
using StardewValley.GameData.Pets;
using StardewValley.GameData.FarmAnimals;
using StardewValley.ItemTypeDefinitions;

namespace BetterRanching
Expand Down Expand Up @@ -65,8 +66,7 @@ public void DrawItemBubble(SpriteBatch spriteBatch, FarmAnimal animal, bool ranc
animal.GetSpriteWidthForPositioning() * (animal.buildingTypeILiveIn.Contains("Coop") && animal.isAdult() ? -1 : 1),
animal.buildingTypeILiveIn.Contains("Coop") && animal.isAdult(),
produceId,
() => !ranchingInProgress && (animal.CanBeRanched(GameConstants.Tools.MilkPail) ||
animal.CanBeRanched(GameConstants.Tools.Shears)),
() => !ranchingInProgress && animal.currentProduce.Value != null && animal.isAdult() && animal.GetHarvestType() == FarmAnimalHarvestType.HarvestWithTool,
() => !animal.wasPet.Value,
true,
false,
Expand Down Expand Up @@ -164,4 +164,4 @@ public void DrawItemBubble(SpriteBatch spriteBatch, float xPosition, float yPosi
false, false, -1);
}
}
}
}
7 changes: 4 additions & 3 deletions BetterRanching/GameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
using StardewModdingAPI;
using StardewValley;
using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using xTile.Dimensions;
using xTile.Tiles;

namespace BetterRanching
{
public static class GameExtensions
{
public static bool CanBeRanched(this FarmAnimal animal, string toolName)
public static bool CanBeRanched(this FarmAnimal animal, Tool tool)
{
return animal.currentProduce.Value != null && animal.isAdult() &&
animal.GetAnimalData().HarvestTool == toolName;
animal.CanGetProduceWithTool(tool);
}

public static void OverwriteState(this IInputHelper input, SButton button, string message = null)
Expand Down Expand Up @@ -50,4 +51,4 @@ public static bool PlayerCanGrabSomething()
return Utility.canGrabSomethingFromHere((int)position.X, (int)position.Y, Game1.player);
}
}
}
}