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

[FarmerHelper] Update to 1.6 #126

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion FarmerHelper/FarmerHelper.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion FarmerHelper/IGenericModConfigMenuApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public interface IGenericModConfigMenuApi
/// <param name="min">The minimum allowed value, or <c>null</c> to allow any.</param>
/// <param name="max">The maximum allowed value, or <c>null</c> to allow any.</param>
/// <param name="interval">The interval of values that can be selected.</param>
/// <param name="formatValue">Get the display text to show for a value, or <c>null</c> to show the number as-is.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, string fieldId = null);
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, Func<int, string> formatValue = null, string fieldId = null);

/// <summary>Remove a mod from the config UI and delete all its options and pages.</summary>
/// <param name="mod">The mod's manifest.</param>
Expand Down
40 changes: 19 additions & 21 deletions FarmerHelper/MethodPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ private static bool Utility_tryToPlaceItem_Prefix(GameLocation location, Item it
Vector2 tileLocation = new Vector2((float)(x / 64), (float)(y / 64));
if (!location.terrainFeatures.TryGetValue(tileLocation, out TerrainFeature f) || f is not HoeDirt)
return true;
Crop c = new Crop(item.ParentSheetIndex, 0, 0);
if (c == null)
return true;
Crop c = new Crop(item.ItemId, 0, 0, location);
if (c.phaseDays.Count == 0 || EnoughDaysLeft(c, f as HoeDirt))
return true;
__result = false;
Expand All @@ -45,10 +43,8 @@ private static bool Object_placementAction_Prefix(Object __instance, GameLocatio

if (location.SeedsIgnoreSeasonsHere())
return true;

Crop c = new Crop(__instance.ParentSheetIndex, x, y);
if (c == null)
return true;

Crop c = new Crop(__instance.ItemId, x, y, location);
if (c.phaseDays.Count == 0 || EnoughDaysLeft(c, f as HoeDirt))
return true;
SMonitor.Log($"Preventing planting {__instance.Name}");
Expand All @@ -61,8 +57,8 @@ private static void IClickableMenu_drawToolTip_Prefix(string hoverText, ref stri
if (!Config.EnableMod || !Config.LabelLatePlanting || hoveredItem == null)
return;

Crop crop = new Crop(hoveredItem.ParentSheetIndex, 0, 0);
if (crop == null || crop.phaseDays.Count == 0 || !crop.seasonsToGrowIn.Contains(Game1.currentSeason) || EnoughDaysLeft(crop, null) || (new int[] { 495, 496, 497, 498, 770 }).Contains(hoveredItem.ParentSheetIndex))
Crop crop = new Crop(hoveredItem.ItemId, 0, 0, Game1.currentLocation);
if (crop.phaseDays.Count == 0 || !crop.GetData().Seasons.Contains(Game1.season) || EnoughDaysLeft(crop, null) || (new int[] { 495, 496, 497, 498, 770 }).Contains(hoveredItem.ParentSheetIndex))
return;

hoverTitle = string.Format(SHelper.Translation.Get("too-late"), hoverTitle);
Expand All @@ -81,7 +77,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
{
if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).crop != null && !(terrainFeature as HoeDirt).hasPaddyCrop() && (terrainFeature as HoeDirt).state.Value == 0 && (terrainFeature as HoeDirt).crop.currentPhase.Value < (terrainFeature as HoeDirt).crop.phaseDays.Count - 1)
{
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is unwatered");
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is unwatered");
if (!added)
{
added = true;
Expand All @@ -93,7 +89,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
{
if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).crop != null && !(terrainFeature as HoeDirt).hasPaddyCrop() && (terrainFeature as HoeDirt).state.Value == 0 && (terrainFeature as HoeDirt).crop.currentPhase.Value < (terrainFeature as HoeDirt).crop.phaseDays.Count - 1)
{
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is unwatered");
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is unwatered");
if (!added)
{
added = true;
Expand All @@ -111,7 +107,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
{
if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).readyForHarvest() && (!Config.IgnoreFlowers || new Object((terrainFeature as HoeDirt).crop.indexOfHarvest.Value, 1, false, -1, 0).Category != -80) && (!ignoreCrops.Contains((terrainFeature as HoeDirt).crop?.indexOfHarvest.Value + "")))
{
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is ready to harvest");
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is ready to harvest");
if (!added)
{
added = true;
Expand All @@ -123,7 +119,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
{
if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).readyForHarvest())
{
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is ready to harvest");
logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is ready to harvest");
if (!added)
{
added = true;
Expand All @@ -134,7 +130,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
}
if (Config.WarnAboutAnimalsOutsideBeforeSleep)
{
if(Game1.getFarm().Animals.Count() > 0)
if(Game1.getFarm().Animals.Any())
{
logMessage.Add($"{Game1.getFarm().Animals.Count()} animals outside on farm.");
question = string.Format(SHelper.Translation.Get("animals-outside"), question);
Expand All @@ -145,7 +141,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
bool added = false;
foreach (FarmAnimal animal in Game1.getFarm().Animals.Values)
{
if (animal.currentProduce.Value > 0 && !animal.type.Value.Contains("Pig"))
if (animal.currentProduce.Value != null && !animal.type.Value.Contains("Pig"))
{
logMessage.Add($"{animal.type.Value} {animal.Name} on farm is ready to harvest");
if (!added)
Expand All @@ -157,13 +153,14 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
}
foreach (Building building in Game1.getFarm().buildings)
{
if (building.indoors.Value is not AnimalHouse)
if (building.GetIndoors() is not AnimalHouse)
continue;
foreach (FarmAnimal animal in (building.indoors.Value as AnimalHouse).animals.Values)

foreach (FarmAnimal animal in (building.GetIndoors() as AnimalHouse).animals.Values)
{
if (animal.currentProduce.Value > 0 && !animal.type.Value.Contains("Pig"))
if (animal.currentProduce.Value != null && !animal.type.Value.Contains("Pig"))
{
logMessage.Add($"{animal.type.Value} {animal.Name} in {building.nameOfIndoors} is ready to harvest");
logMessage.Add($"{animal.type.Value} {animal.Name} in {building.GetIndoorsName()} is ready to harvest");

if (!added)
{
Expand Down Expand Up @@ -193,11 +190,12 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi
{
if (building.indoors.Value is not AnimalHouse)
continue;
foreach (FarmAnimal animal in (building.indoors.Value as AnimalHouse).animals.Values)

foreach (FarmAnimal animal in (building.GetIndoors() as AnimalHouse).animals.Values)
{
if (!animal.wasPet.Value && !animal.wasAutoPet.Value)
{
logMessage.Add($"{animal.type.Value} {animal.Name} in {building.nameOfIndoors} needs petting");
logMessage.Add($"{animal.type.Value} {animal.Name} in {building.GetIndoorsName()} needs petting");

if (!added)
{
Expand Down
7 changes: 3 additions & 4 deletions FarmerHelper/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,15 @@ private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStar
Helper.GameContent.InvalidateCache("Data/ObjectInformation");
}

public static string[] seasons = new string[] { "spring", "summer", "fall", "winter" };
private static bool EnoughDaysLeft(Crop c, HoeDirt hoeDirt)
{
if (c.seasonsToGrowIn.Contains(seasons[(Utility.getSeasonNumber(Game1.currentSeason) + 1) % 4]))
if (c.GetData().Seasons.Contains((Season)((Game1.seasonIndex + 1) % 4)))
return true;
if(hoeDirt is not null)
{
HoeDirt d = new HoeDirt(hoeDirt.state.Value, c);
d.currentLocation = hoeDirt.currentLocation;
d.currentTileLocation = hoeDirt.currentTileLocation;
d.Location = hoeDirt.Location;
d.Tile = hoeDirt.Tile;
d.fertilizer.Value = hoeDirt.fertilizer.Value;
AccessTools.Method(typeof(HoeDirt), "applySpeedIncreases").Invoke(d, new object[] { Game1.player });
c = d.crop;
Expand Down
4 changes: 2 additions & 2 deletions FarmerHelper/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Name": "Farmer Helper",
"Author": "aedenthorn",
"Version": "0.4.2",
"Version": "0.4.3",
"Description": "Farmer Helper.",
"UniqueID": "aedenthorn.FarmerHelper",
"EntryDll": "FarmerHelper.dll",
"MinimumApiVersion": "3.13.0",
"MinimumApiVersion": "4.0.0",
"ModUpdater": {
"Repository": "StardewValleyMods",
"User": "aedenthorn",
Expand Down