Skip to content

Fix crop count inflation on non-farm locations#41

Open
ktiedt wants to merge 1 commit into
FlashShifter:masterfrom
ktiedt:fix/farm-computer-inflation
Open

Fix crop count inflation on non-farm locations#41
ktiedt wants to merge 1 commit into
FlashShifter:masterfrom
ktiedt:fix/farm-computer-inflation

Conversation

@ktiedt

@ktiedt ktiedt commented Jul 11, 2026

Copy link
Copy Markdown

SVE Bug Report: Farm Computer Crop Count Inflation on Custom/Non-Farm Locations

Description

A bug in Stardew Valley Expanded's HarmonyPatch_FarmComputerLocations class causes crop, ready-to-harvest, unwatered, and open hoe dirt counts to be inflated on every single location in the game (including vanilla NPC homes, cellars, and other mods' custom maps).


Root Cause Analysis

Stardew Valley Expanded patches the base GameLocation class methods to aggregate crop statistics for custom SVE farm areas (like Grandpa's Shed Greenhouse).

The patches are registered on:

  • GameLocation.getTotalCrops()
  • GameLocation.getTotalCropsReadyForHarvest()
  • GameLocation.getTotalUnwateredCrops()
  • GameLocation.getTotalOpenHoeDirt()

However, because these postfixes are applied to GameLocation (which is the base class for all maps/locations) and lack a type-check for the main Farm, the SVE postfixes run on every location in the game. Every time a location's crop count is queried, SVE adds the crop count of Custom_GrandpasShedGreenhouse (144) to the result.


Suggested Code Patch

To fix this, the Harmony patches in StardewValleyExpanded.HarmonyPatch_FarmComputerLocations must verify that the method is executing on the main Farm instance (or check the location name) before modifying __result.

Before:

public static void Farm_getTotalCrops(ref int __result)
{
    // Bug: Runs on every single GameLocation in the game
    GameLocation shedGreenhouse = Game1.getLocationFromName("Custom_GrandpasShedGreenhouse");
    if (shedGreenhouse != null)
    {
        __result += shedGreenhouse.getTotalCrops();
    }
}

After (Proposed Fix):

public static void Farm_getTotalCrops(GameLocation __instance, ref int __result)
{
    // Fix: Only apply crop counts aggregation if the caller is the main Farm
    if (__instance is StardewValley.Farm)
    {
        GameLocation shedGreenhouse = Game1.getLocationFromName("Custom_GrandpasShedGreenhouse");
        if (shedGreenhouse != null)
        {
            __result += shedGreenhouse.getTotalCrops();
        }
    }
}

This same type-check (if (__instance is Farm)) should be added to the other three postfixes in the class:

  • Farm_getTotalCropsReadyForHarvest
  • Farm_getTotalUnwateredCrops
  • Farm_getTotalOpenHoeDirt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant