Jump to content

Modding:Farm data: Difference between revisions

From Stardew Valley Wiki
imported>Tlitookilakin
add example
imported>Sunbeam135
mNo edit summary
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Stub}}
← [[Modding:Index|Index]]
{{upcoming|1.6}}


← [[Modding:Index|Index]]
This page explains how the game stores and parses [[Farm Maps|farm types]], maps, and related data. This is an advanced guide for mod developers.


This page explains how to create a custom farm type. It is an advanced guide for modders.
'''Before reading this page''', see [[Modding:Editing XNB files]] for the basic concepts.
'''Before reading this page''', see [[Modding:Editing XNB files]] for the basic concepts.


==Files to Edit==
==Assets==
Creating a custom farm requires editing some files and adding new ones. However, you don't need any programming experience and it can be done with [[Modding:Content Patcher|Content Patcher]].
===Farm type data===
You can define custom farm types by editing the <samp>Data/AdditionalFarms</samp> asset.


==Farm Map==
This consists of a list of models, where each model has the fields listed below.
A map controls the general appearance and layout of your farm. [[Modding:Maps|Modding:Maps]] describes the basic process of creating a map. Copying and editing an existing farm map is recommended to avoid problems with missing information. The map must be added to the game files, and not replace an existing one.


===Entry Properties===
These map properties can change where a player enters the farm when arriving from other locations, such as the backwoods, bus stop, or forest.
===Building Properties===
These map properties can change where some objects are positioned by default, such as the greenhouse, farmhouse, or grandpa's shrine.
===Farmhouse Interior===
The starter interior layout of the farmhouse and cabins can be modified using these map properties '''on the farm'''.
===Other Properties===
These map properties can change other aspects of the farm, such as regenerating hardwood stumps or rock-spawning quarries.
==Farm Type==
To use a custom farm type, it must be added to the game by editing Data/AdditionalFarms. Each entry is an object with these fields:
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 33: Line 17:
|-
|-
| <samp>ID</samp>
| <samp>ID</samp>
| A unique ID value. This must be '''globally''' unique across all mods, so you should prefix your mod ID (''e.g.,'' <samp>Example.PineapplesAnywhere/PineappleFarm</samp>). You should avoid commas for compatibility with Content Patcher packs checking the <samp><nowiki>{{FarmType}}</nowiki></samp> token. This is not shown in-game. It should be the same as the key for this entry.
| A [[Modding:Common data field types#Unique string ID|unique string ID]] for the farm type.
|-
|-
| <samp>TooltipStringPath</samp>
| <samp>TooltipStringPath</samp>
| Where to get the translatable farm name and description. This must be a key in the form <samp>{{t|asset name}}:{{t|key}}</samp>; for example, <samp>Strings/UI:Farm_Description</samp> will get it from the <samp>Farm_Description</samp> entry in the <samp>Strings/UI</samp> file. The translated text must be in the form "<samp>{{t|name}}_{{t|description}}</samp>", like "Pineapple Farm_A farm shaped like a pineapple".
| The [[Modding:Common data field types#Translation key|translation key]] containing the translatable farm name and description. For example, <samp>Strings/UI:Farm_Description</samp> will get it from the <samp>Farm_Description</samp> entry in the <samp>Strings/UI</samp> file.
 
The translated text must be in the form "<samp>{{t|name}}_{{t|description}}</samp>", like "Pineapple Farm_A farm shaped like a pineapple".
|-
|-
| <samp>MapName</samp>
| <samp>MapName</samp>
| The map asset name relative to the <samp>Maps</samp> folder. For example, <samp>Farm_Pineapple</samp> would load <samp>Maps/Farm_Pineapple</samp>.
| The [[Modding:Common data field types#Asset name|asset name]] for the farm's [[Modding:Maps|map asset]], relative to the <samp>Maps</samp> folder. For example, <samp>Farm_Pineapple</samp> would load <samp>Maps/Farm_Pineapple</samp>.
|-
|-
| <samp>IconTexture</samp>
| <samp>IconTexture</samp>
| ''(optional)'' The asset name for a 22x20 pixel icon texture, shown on the 'New Game' and co-op join screens.
| ''(Optional)'' The [[Modding:Common data field types#Asset name|asset name]] for a 22x20 pixel icon texture, shown on the 'New Game' and co-op join screens.
|-
| <samp>SpawnMonstersByDefault</samp>
| ''(Optional)'' The default value of the 'spawn monsters at night' [[Options#Advanced Game Options|advanced save option]].
|-
|-
| <samp>WorldMapTexture</samp>
| <samp>WorldMapTexture</samp>
| ''(optional)'' The asset name for a 131x61 pixel texture that's drawn over the farm area in the in-game world map.
| ''(Optional)'' The [[Modding:Common data field types#Asset name|asset name]] for a 131x61 pixel texture that's drawn over the farm area in the in-game world map.
|-
|-
| <samp>ModData</samp>
| <samp>ModData</samp>
| ''(optional)'' A string→string dictionary of mod-specific metadata for the farm, which can be accessed in C# code via <samp>Game1.GetFarmTypeModData(key)</samp>.
| ''(Optional)'' The [[Modding:Common data field types#Mod data|mod data fields]] for this farm type, which can be accessed in C# code via <samp>Game1.GetFarmTypeModData(key)</samp>.
|}
|}


==Location Data==
===Farm map===
'''This step is optional.''' [[Modding:Location data|Data/Locations]] contains additional information about the game's locations. Each farm type has its own entry. A custom farm type can use an entry identified by <samp>Farm_{{t|Unique_ID}}</samp> to change the location data of the farm when it is used. If this location data does not exist, the location data of the standard farm layout will be used instead.
The farm [[Modding:Maps|map]] contains the general appearance and layout of your farm. [[Modding:Maps|Modding:Maps]] describes the basic process of creating a map.


For custom farms, some fields should have specific values to preserve expected behavior.
Copying and editing an existing farm map is recommended to avoid problems with missing information. The map must be added to the game files, and not replace an existing one.
 
===Farm map properties===
You can customize the farm behavior by [[Modding:Maps|setting map properties in the map asset]].
 
When testing map property changes, it's best to create a new save since some of these are only applied when the save is created. These properties are optional, and the game will use default values for any properties that aren't specified.
 
Some notable map properties are:
 
* [[Modding:Maps#Warps & map positions|Warp & map positions]] set the player position when arriving on the farm (e.g. <samp>BackwoodsEntry</samp> when arriving from the [[backwoods]], or <samp>WarpTotemEntry</samp> when using a [[Warp Totem: Farm|warp totem]] or [[Farm Obelisk|farm obelisk]]), and the default positions of some location contents (e.g. <samp>MailboxLocation</samp> for the default mailbox position).
* [[Modding:Maps#Farmhouse interior|Farmhouse interior properties]] set the appearance and contents of the [[farmhouse]] (e.g. <samp>FarmHouseFlooring</samp> for the default flooring, or <samp>FarmHouseStarterGift</samp> for what's in the starter giftbox).
* [[Modding:Maps#Fishing|Fishing properties]] override fishing and crab pot behavior.
* [[Modding:Maps#Plants, forage, & item spawning|Plants, forage, & item spawning properties]] override how crops, forage, artifact spots, etc work on the farm.
 
===Location data===
'''Optionally''', you can override additional farm location behavior by [[Modding:Location data|editing <samp>Data/Locations</samp>]]. Each farm type can have its own entry, with a key in the form <samp>Farm_{{t|farm type ID}}</samp>. If omitted, it defaults to the location data for the standard farm layout.
 
This can be used to override forage, fish, crab pot catches, artifact spots, etc.
 
For custom farms, some fields should have specific values to preserve expected behavior:
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 61: Line 69:
|-
|-
| <samp>DisplayName</samp>
| <samp>DisplayName</samp>
| This is used to display the farm name. It should contain at least the <samp>FarmName</samp> token to be sure the farm name is shown. The standard value is  
| A [[Modding:Common data field types#Tokenizable string|tokenizable string]] for the farm name. It should contain at least the <samp>FarmName</samp> token to be sure the farm name is shown. The standard value is <code>[LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]]</code>.
<samp>[LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]]</samp>
|-
|-
| <samp>CreateOnLoad</samp>
| <samp>CreateOnLoad</samp>
| Must be <samp>null</samp> or absent. Any other value will create duplicate locations.
| Must be <samp>null</samp> or omitted. Any other value will create duplicate locations.
|-
|-
| <samp>CanPlantHere</samp>
| <samp>CanPlantHere</samp>
| Should be <samp>true</samp>. If <samp>false</samp> or absent, crops can't be grown on your farm.
| Should be <samp>true</samp> or omitted. If <samp>false</samp>, crops can't be grown on your farm.
|-
|}
|}


==Example==
==Example==
This is an example of a [[Modding:Content Patcher|Content Patcher]] pack adding a custom farm type with custom location data.
For example, this [[Modding:Content Patcher|Content Patcher]] pack adds a farm type with custom location data.
{{#tag:syntaxhighlight|
<syntaxhighlight lang="json">
{
{
    "Format": "{{Content Patcher version}}",
     "Changes": [
     "Changes": [
         // add farm type
         // add farm type
Line 83: Line 88:
             "Target": "Data/AdditionalFarms",
             "Target": "Data/AdditionalFarms",
             "Entries": {
             "Entries": {
                 "ExampleAuthor.PineappleFarm/PineappleFarm": { // for technical reasons, you need to specify the ID here *and* in the "ID" field
                 "{{ModId}}_PineappleFarm": { // for technical reasons, you need to specify the ID here *and* in the 'ID' field
                     "ID": "ExampleAuthor.PineappleFarm/PineappleFarm",
                     "ID": "{{ModId}}_PineappleFarm",
                     "TooltipStringPath": "Strings/UI:ExampleAuthor_PineappleFarm",
                     "TooltipStringPath": "Strings/UI:{{ModId}}",
                     "MapName": "ExampleAuthor_PineappleFarm",
                     "MapName": "{{ModId}}",
                     "IconTexture": "Mods/ExampleAuthor.PineappleFarm/Icon",
                     "IconTexture": "Mods/{{ModId}}/Icon",
                     "WorldMapTexture": "Mods/ExampleAuthor.PineappleFarm/WorldMap"
                     "WorldMapTexture": "Mods/{{ModId}}/WorldMap"
                 }
                 }
             }
             }
Line 98: Line 103:
             "Target": "Strings/UI",
             "Target": "Strings/UI",
             "Entries": {
             "Entries": {
                 "ExampleAuthor_PineappleFarm": "Pineapple Farm_A farm shaped like a pineapple!" // tip: use <nowiki>{{i18n}}</nowiki> to translate it
                 "{{ModId}}": "Pineapple Farm_A farm shaped like a pineapple!" // tip: use {{i18n}} to translate it
             }
             }
         },
         },
Line 105: Line 110:
         {
         {
             "Action": "Load",
             "Action": "Load",
             "Target": "Maps/ExampleAuthor_PineappleFarm",
             "Target": "Maps/{{ModId}}",
             "FromFile": "assets/map.tmx"
             "FromFile": "assets/map.tmx"
         },
         },
Line 112: Line 117:
         {
         {
             "Action": "Load",
             "Action": "Load",
             "Target": "Mods/ExampleAuthor.PineappleFarm/Icon, Mods/ExampleAuthor.PineappleFarm/WorldMap",
             "Target": "Mods/{{ModId}}/Icon, Mods/{{ModId}}/WorldMap",
             "FromFile": "assets/<nowiki>{{TargetWithoutPath}}</nowiki>.png"
             "FromFile": "assets/{{TargetWithoutPath}}.png"
         },
         },


Line 121: Line 126:
             "Target": "Data/Locations",
             "Target": "Data/Locations",
             "Entries": {
             "Entries": {
                 "ExampleAuthor.PineappleFarm/PineappleFarm": {
                 "Farm_{{ModId}}_PineappleFarm": {
                     "DisplayName": "[LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]]",
                     "DisplayName": "[LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]]",
                     "CanPlantHere": true,
                     "CanPlantHere": true,
                     "DefaultArrivalTile": {"X": 64, "Y": 15},
                     "DefaultArrivalTile": {"X": 64, "Y": 15},
                    "MinDailyWeeds": 5,
                    "MaxDailyWeeds": 11,
                     "ArtifactSpots": [
                     "ArtifactSpots": [
                         // default artifact data
                         // default artifact data
Line 134: Line 141:
                         },
                         },
                         {
                         {
                             "Id": "Mixed_Seeds",
                             "Id": "MixedSeeds",
                             "ItemId": "(O)770",
                             "ItemId": "(O)770",
                             "Chance": 0.1,
                             "Chance": 0.1,
Line 147: Line 154:
                         // custom artifacts
                         // custom artifacts
                         {
                         {
                             "Id": "Spring seeds",
                             "Id": "SpringSeeds",
                             "ItemId": "(O)495",
                             "ItemId": "(O)495",
                             "Chance": 0.2,
                             "Chance": 0.2,
Line 155: Line 162:
                         },
                         },
                         {
                         {
                             "Id": "Summer seeds",
                             "Id": "SummerSeeds",
                             "ItemId": "(O)496",
                             "ItemId": "(O)496",
                             "Chance": 0.2,
                             "Chance": 0.2,
Line 163: Line 170:
                         },
                         },
                         {
                         {
                             "Id": "Fall seeds",
                             "Id": "FallSeeds",
                             "ItemId": "(O)497",
                             "ItemId": "(O)497",
                             "Chance": 0.2,
                             "Chance": 0.2,
Line 171: Line 178:
                         },
                         },
                         {
                         {
                             "Id": "Winter seeds",
                             "Id": "WinterSeeds",
                             "ItemId": "(O)498",
                             "ItemId": "(O)498",
                             "Chance": 0.2,
                             "Chance": 0.2,
Line 183: Line 190:
         }
         }
     ]
     ]
}|lang=javascript}}
}
</syntaxhighlight>


[[Category:Modding]]
[[Category:Modding]]
[[ru:Модификации:Ферма]]
[[zh:模组:农场数据]]

Latest revision as of 18:07, 6 March 2026

← Index

This page explains how the game stores and parses farm types, maps, and related data. This is an advanced guide for mod developers.

Before reading this page, see Modding:Editing XNB files for the basic concepts.

Assets

Farm type data

You can define custom farm types by editing the Data/AdditionalFarms asset.

This consists of a list of models, where each model has the fields listed below.

field description
ID A unique string ID for the farm type.
TooltipStringPath The translation key containing the translatable farm name and description. For example, Strings/UI:Farm_Description will get it from the Farm_Description entry in the Strings/UI file.

The translated text must be in the form "<name>_<description>", like "Pineapple Farm_A farm shaped like a pineapple".

MapName The asset name for the farm's map asset, relative to the Maps folder. For example, Farm_Pineapple would load Maps/Farm_Pineapple.
IconTexture (Optional) The asset name for a 22x20 pixel icon texture, shown on the 'New Game' and co-op join screens.
SpawnMonstersByDefault (Optional) The default value of the 'spawn monsters at night' advanced save option.
WorldMapTexture (Optional) The asset name for a 131x61 pixel texture that's drawn over the farm area in the in-game world map.
ModData (Optional) The mod data fields for this farm type, which can be accessed in C# code via Game1.GetFarmTypeModData(key).

Farm map

The farm map contains the general appearance and layout of your farm. Modding:Maps describes the basic process of creating a map.

Copying and editing an existing farm map is recommended to avoid problems with missing information. The map must be added to the game files, and not replace an existing one.

Farm map properties

You can customize the farm behavior by setting map properties in the map asset.

When testing map property changes, it's best to create a new save since some of these are only applied when the save is created. These properties are optional, and the game will use default values for any properties that aren't specified.

Some notable map properties are:

Location data

Optionally, you can override additional farm location behavior by editing Data/Locations. Each farm type can have its own entry, with a key in the form Farm_<farm type ID>. If omitted, it defaults to the location data for the standard farm layout.

This can be used to override forage, fish, crab pot catches, artifact spots, etc.

For custom farms, some fields should have specific values to preserve expected behavior:

field description
DisplayName A tokenizable string for the farm name. It should contain at least the FarmName token to be sure the farm name is shown. The standard value is [LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]].
CreateOnLoad Must be null or omitted. Any other value will create duplicate locations.
CanPlantHere Should be true or omitted. If false, crops can't be grown on your farm.

Example

For example, this Content Patcher pack adds a farm type with custom location data.

{
    "Changes": [
        // add farm type
        {
            "Action": "EditData",
            "Target": "Data/AdditionalFarms",
            "Entries": {
                "{{ModId}}_PineappleFarm": { // for technical reasons, you need to specify the ID here *and* in the 'ID' field
                    "ID": "{{ModId}}_PineappleFarm",
                    "TooltipStringPath": "Strings/UI:{{ModId}}",
                    "MapName": "{{ModId}}",
                    "IconTexture": "Mods/{{ModId}}/Icon",
                    "WorldMapTexture": "Mods/{{ModId}}/WorldMap"
                }
            }
        },

        // add farm name + description
        {
            "Action": "EditData",
            "Target": "Strings/UI",
            "Entries": {
                "{{ModId}}": "Pineapple Farm_A farm shaped like a pineapple!" // tip: use {{i18n}} to translate it
            }
        },

        // load map
        {
            "Action": "Load",
            "Target": "Maps/{{ModId}}",
            "FromFile": "assets/map.tmx"
        },

        // load icon
        {
            "Action": "Load",
            "Target": "Mods/{{ModId}}/Icon, Mods/{{ModId}}/WorldMap",
            "FromFile": "assets/{{TargetWithoutPath}}.png"
        },

        // custom location data
        {
            "Action": "EditData",
            "Target": "Data/Locations",
            "Entries": {
                "Farm_{{ModId}}_PineappleFarm": {
                    "DisplayName": "[LocalizedText Strings\\StringsFromCSFiles:MapPage.cs.11064 [EscapedText [FarmName]]]",
                    "CanPlantHere": true,
                    "DefaultArrivalTile": {"X": 64, "Y": 15},
                    "MinDailyWeeds": 5,
                    "MaxDailyWeeds": 11,
                    "ArtifactSpots": [
                        // default artifact data
                        {
                            "Id": "Coal",
                            "ItemId": "(O)382",
                            "Chance": 0.5,
                            "MaxStack": 3
                        },
                        {
                            "Id": "MixedSeeds",
                            "ItemId": "(O)770",
                            "Chance": 0.1,
                            "MaxStack": 3
                        },
                        {
                            "Id": "Stone",
                            "ItemId": "(O)390",
                            "Chance": 0.25,
                            "MaxStack": 3
                        },
                        // custom artifacts
                        {
                            "Id": "SpringSeeds",
                            "ItemId": "(O)495",
                            "Chance": 0.2,
                            "MaxStack": 4,
                            "Condition": "SEASON Spring",
                            "Precedence": 1
                        },
                        {
                            "Id": "SummerSeeds",
                            "ItemId": "(O)496",
                            "Chance": 0.2,
                            "MaxStack": 4,
                            "Condition": "SEASON Summer",
                            "Precedence": 1
                        },
                        {
                            "Id": "FallSeeds",
                            "ItemId": "(O)497",
                            "Chance": 0.2,
                            "MaxStack": 4,
                            "Condition": "SEASON Fall",
                            "Precedence": 1
                        },
                        {
                            "Id": "WinterSeeds",
                            "ItemId": "(O)498",
                            "Chance": 0.2,
                            "MaxStack": 4,
                            "Condition": "SEASON Winter",
                            "Precedence": 1
                        }
                    ]
                }
            }
        }
    ]
}