Jump to content

Modding:Items: Difference between revisions

From Stardew Valley Wiki
imported>Pathoschild
imported>Malevolent-bagel
mNo edit summary
 
(15 intermediate revisions by 5 users not shown)
Line 3: Line 3:
This page explains how the game stores and parses item data. This is an advanced guide for mod developers.
This page explains how the game stores and parses item data. This is an advanced guide for mod developers.


==Overview==
===Item IDs===
Every item is identified in the game data using a unique item ID. This has two forms:


==Introduction==
* The ''unqualified item ID'' (<code>item.ItemId</code>) is a [[Modding:Common data field types#Unique string ID|unique string ID]] for the item, like <samp>128</samp> (vanilla item) or <samp>Example.ModId_Watermelon</samp> (custom item). For legacy reasons, the unqualified ID for vanilla items may not be globally unique; for example, Pufferfish (object 128) and Mushroom Box (bigcraftable 128) both have item ID <samp>128</samp>.
===Overview===
* The ''qualified item ID'' (<code>item.QualifiedItemId</code>) is a globally unique identifier which combines the item's [[#Item types|type ID]] and unqualified item ID, like <samp>(O)128</samp> for [[Modding:Objects|object]] ID 128.
As of Stardew Valley 1.6, there are a few important features of Items in the game.


# Each item as a string ID (<samp>ItemId</samp>) and a globally-unique string ID (<samp>QualifiedItemId</samp>). The <samp>QualifiedItemId</samp> is auto-generated by prefixing the <samp>ItemId</samp> with the item type identifier.<p>For legacy reasons, the <samp>ItemId</samp> for vanilla items may not be globally unique. For example, Pufferfish (object 128) and Mushroom Box (bigcraftable 128) both have <samp>ItemId: 128</samp>. They can be distinguished by their <samp>QualifiedItemId</samp>, which are <samp>(O)128</samp> and <samp>(BC)128</samp> respectively.
With [[Modding:Player Guide/Getting Started|SMAPI installed]], you can [[Modding:Console commands#Console commands|run the <samp>list_items</samp> console command]] in-game to search item IDs.
# Each item type has an ''item data definition'' in the game code which tells the game how to handle it. [[#For C# mods|C# mods can add or edit definitions]]. Each definition has a unique prefix which is used in the qualified item IDs. The vanilla types are bigcraftables (<samp>(BC)</samp>), boots (<samp>(B)</samp>), farmhouse flooring (<samp>(FL)</samp>), furniture (<samp>(F)</samp>), hats (<samp>(H)</samp>), objects (<samp>(O)</samp>), pants (<samp>(P)</samp>), shirts (<samp>(S)</samp>), tools (<samp>(T)</samp>), wallpaper (<samp>(WP)</samp>), and weapons (<samp>(W)</samp>).</li>
# Custom items can now provide their own item texture, specified in a new field in the item data assets (see below). The item's <samp>ParentSheetIndex</samp> field is the index within that texture.


In other words, the four important fields for items are:
'''Note:''' mods created before Stardew Valley 1.6 may use the <samp>item.ParentSheetIndex</samp> field as an item identifier. This is ''not'' a valid identifier; multiple items of the same type may have the same sprite index for different textures.


{| class="wikitable"
===Item types===
|-
Items are defined by ''item type data definitions'', which handle parsing data of a certain type. For example, the game's <samp>ObjectDataDefinition</samp> class handles producing [[Modding:Objects|object-type items]] by parsing the <samp>Data/Objects</samp> asset.
! name
! type
! description
|-
| <samp>ItemId</samp>
| <samp>string</samp>
| A [[Modding:Common data field types#Unique string ID|unique string ID]] for this item which should be globally unique (but may not be for existing vanilla items for backwards compatibility). For example, <samp>128</samp> (vanilla item) or <samp>Example.ModId_Watermelon</samp> (custom item).
|-
| <samp>QualifiedItemId</samp>
| <samp>string</samp>
| A globally unique item key, like <samp>(O)128</samp> for a vanilla item or <samp>(O)Example.ModId_Watermelon</samp> for a custom one. This is auto-generated from the <samp>TypeDefinitionId</samp> and <samp>ItemId</samp> fields.
|-
| <samp>ParentSheetIndex</samp>
| <samp>int</samp>
| The item's sprite index within its spritesheet.
|-
| <samp>TypeDefinitionId</samp>
| <samp>string</samp>
| The ID for the data definition which defines the item, like <samp>(O)</samp> for an object. You can use <samp>ItemRegistry.type_*</samp> constants with this field:
<syntaxhighlight lang="c#">
if (item.TypeDefinitionId == ItemRegistry.type_object)
  ...
</syntaxhighlight>
|}
 
===Item references===
Item references throughout the game code now use the <samp>ItemId</samp> instead of the <samp>ParentSheetIndex</samp>. Since the <samp>ItemId</samp> is identical to the index for existing vanilla items, most data assets are unaffected by this change. For example, here's from <samp>Data/NPCGiftTastes</samp> with one custom item:
<syntaxhighlight lang="json">
"Universal_Like": "-2 -7 -26 -75 -80 72 395 613 634 635 636 637 638 724 459 Example.ModID_watermelon"
</syntaxhighlight>


Unless otherwise noted, unqualified item IDs will produce [[Modding:Items|objects]]. Some assets let you override that by specifying a <samp>QualifiedItemId</samp> value instead. For example, you can add <code>(O)128</code> to the gift taste list to explicitly add for an object. Here's a partial list of data assets and their supported item ID formats:
Each definition has a unique ID like <code>(O)</code>, which is used to form globally unique [[#Item IDs|qualified item IDs]]. In C# code, this is tracked by the <code>item.TypeDefinitionId</code> field, which matches <code>ItemRegistry.type_*</code> constants for vanilla item types.


{| class="wikitable"
|-
! data asset
! item ID format
|-
| [[Modding:Recipe data|<samp>Data/CraftingRecipes</samp><br /><samp>Data/CookingRecipes</samp>]]
| &#32;
* Ingredients: both supported.
* Output: set field 2 to the unqualified item ID, and field 3 to one of <samp>true</samp> (bigcraftable) or <samp>false</samp> (object).
|-
| [[Modding:Fruit_trees|<samp>Data/FruitTrees</samp>]]
| &#32;
* Fruit: both supported.
* Sapling: unqualified only.
|-
| [[Modding:Gift taste data|<samp>Data/NPCGiftTastes</samp>]]
| Both supported, but only <samp>(O)</samp> items can be gifted.
|}
===Item types===
These are the item types for which custom items can added/edited:
These are the item types for which custom items can added/edited:


Line 76: Line 26:
! type identifier
! type identifier
! data asset
! data asset
! brief summary
|-
| [[Modding:Objects|Objects]]
| <samp>(O)</samp>
| <samp>Data/Objects</samp>
| The most common item type. Depending on their data, they can be placed in the world, picked up, eaten, sold to shops, etc.
|-
|-
| [[Modding:Items#Big_craftables|Big craftables]]
| [[Modding:Big craftables|Big craftables]]
| <samp>(BC)</samp>
| <samp>(BC)</samp>
| <samp>Data/BigCraftables</samp><br /><small>Each item can set a custom texture name in the <samp>Texture</samp> field, and sprite index in the <samp>SpriteIndex</samp> field. The default texture is <samp>TileSheets/Craftables</samp>.</small>
| <samp>Data/BigCraftables</samp>
| Items which can be placed in the world and are two tiles tall (instead of one like objects).
|-
|-
| [[Modding:Items#Boots|Boots]]
| [[Modding:Boots|Boots]]
| <samp>(B)</samp>
| <samp>(B)</samp>
| <samp>Data/Boots</samp><br /><small>Each item can set a custom texture name in fields 9 (item) and 7 (shoe color), and sprite index in fields 8 (item) and 5 (shoe color). The default textures are <samp>Maps/springobjects</samp> (item) and <samp>Characters/Farmer/shoeColors</samp> (shoe color).</small>
| <samp>Data/Boots</samp>
|-
| Items which can be equipped in the player's [[boots]] slot. These change the player sprite and may provide buffs.
| [[Modding:Crop data|Crops]]
| <small>''not technically an item type''</small>
| <samp>Data/Crops</samp><br /><small>Each crop can set a custom texture name and sprite index. The default texture is <samp>TileSheets/crops</samp>.</small>
|-
| [[Modding:Fish data|Fish (in fish tanks)]]
| <small>''not technically an item type''</small>
| <samp>Data/AquariumFish</samp><br /><small>Each fish can set a custom aquarium texture name in field 6, and sprite index in field 0. The default texture is <samp>LooseSprites/AquariumFish</samp>.</small>
|-
|-
| [[Modding:Items#Furniture|Furniture]]
| [[Modding:Furniture|Furniture]]
| <samp>(F)</samp>
| <samp>(F)</samp>
| <samp>Data/Furniture</samp><br /><small>Each item can set a custom texture name in field 9, and sprite index in field 8. The default texture is <samp>TileSheets/furniture</samp>.</small>
| <samp>Data/Furniture</samp>
| Decorative items which can be placed in the world. In some cases players can sit on them or place items on them.
|-
|-
| [[Modding:Fruit_trees|Fruit Trees]]
| [[Modding:Hats|Hats]]
| <small>''not technically an item type''</small>
| <samp>Data/FruitTrees</samp><br /><small>Each fruit tree can set a custom texture name and sprite index. The default texture is <samp>TileSheets/fruitTrees</samp>.</small>
|-
| [[Modding:Items#Hats|Hats]]
| <samp>(H)</samp>
| <samp>(H)</samp>
| <samp>Data/Hats</samp><br /><small>Each item can set a custom texture name in field 7, and sprite index in field 6. The default texture is <samp>Characters/Farmer/hats</samp>.</small>
| <samp>Data/Hats</samp>
| Items which can be equipped in the player's [[Hats|hat]] slot. These change the player sprite.
|-
|-
| [[Modding:Items#Objects|Objects]]
| [[Modding:Mannequins|Mannequins]]
| <samp>(O)</samp>
| <samp>(M)</samp>
| <samp>Data/Objects</samp><br /><small>Each item can set a custom texture name in the <samp>Texture</samp> field, and sprite index in the <samp>SpriteIndex</samp> field. The default texture is <samp>Maps/springobjects</samp>.</small>
| <samp>Data/Mannequins</samp>
| Decorative items which can be placed in the world, and used to store and display clothing.
|-
|-
| [[Modding:Items#Pants|Pants]]
| [[Modding:Pants|Pants]]
| <samp>(P)</samp>
| <samp>(P)</samp>
| <samp>Data/pantsData</samp><br /><small>Each item can set a custom texture name in the <samp>Texture</samp> field, and sprite index in the <samp>SpriteIndex</samp> field. The default texture is <samp>Characters/Farmer/pants</samp>.</small>
| <samp>Data/Pants</samp>
| Items which can be equipped in the player's [[Tailoring#Pants|pants]] slot. These change the player sprite.
|-
|-
| [[Modding:Items#Shirts|Shirts]]
| [[Modding:Shirts|Shirts]]
| <samp>(S)</samp>
| <samp>(S)</samp>
| <samp>Data/shirtData</samp><br /><small>Each item can set a custom texture name in the <samp>Texture</samp> field, and sprite index in the <samp>SpriteIndex</samp> field. The default texture is <samp>Characters/Farmer/shirts</samp>.</small>
| <samp>Data/Shirts</samp>
 
| Items which can be equipped in the player's [[Tailoring#Shirts|shirt]] slot. These change the player sprite.
<small>Shirt textures must be exactly 256 pixels wide, divided into two halves: the left half for the shirt sprites, and the right half for any dye masks. The remaining space can be left blank if needed.</small>
<pre>
      sprites      dye masks
  /-----------\  /-----------\
┌────────────────────────────────┐
│ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ │
│ │ 0 ││ 1 ││ 2 ││ a ││ b ││ c │ │
│ └───┘└───┘└───┘└───┘└───┘└───┘ │
│ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ │
│ │ 3 ││ 4 ││ 5 ││ d ││ e ││ f │ │
│ └───┘└───┘└───┘└───┘└───┘└───┘ │
└────────────────────────────────┘
</pre>
|-
|-
| [[#Custom tools|Tools]]
| [[Modding:Tools|Tools]]
| <samp>(T)</samp>
| <samp>(T)</samp>
| <samp>Data/Tools</samp><br /><small>Each item can set a custom texture name in the <samp>Texture</samp> field, and sprite index in the <samp>SpriteIndex</samp> field. The vanilla tools use the <samp>TileSheets/Tools</samp> texture.</small>
| <samp>Data/Tools</samp>
| Items that can be swung or used by the player to perform some effect (e.g. dig dirt, chop trees, milk or shear animals, etc).
|-
|-
| Wallpaper & flooring
| [[Modding:Trinkets|Trinkets]]
| <samp>(TR)</samp>
| <samp>Data/Trinkets</samp>
| Items that can be equipped in the player's [[Trinkets|trinket]] slot to enable special effects.
|-
| [[Modding:Wallpaper and flooring|Wallpaper & flooring]]
| <samp>(WP)</samp> and <samp>(FL)</samp>
| <samp>(WP)</samp> and <samp>(FL)</samp>
| <samp>Data/AdditionalWallpaperFlooring</samp><br /><small>See [[Modding:Migrate to Stardew Valley 1.5.5#In the furniture catalogue|format docs]].</small>
| <samp>Data/AdditionalWallpaperFlooring</samp>
| Items which can be applied to a decoratable location (e.g. a [[farmhouse]] or [[shed]]) to visually change its floor or wall design. (These are separate from placeable items like [[Brick Floor|brick floor]].)
|-
|-
| [[Modding:Items#Weapons|Weapons]]
| [[Modding:Weapons|Weapons]]
| <samp>(W)</samp>
| <samp>(W)</samp>
| <samp>Data/Weapons</samp><br />
| <samp>Data/Weapons</samp>
| Items which can be swung or used by the player to damage monsters.
|}
|}


When resolving an unqualified item ID like <samp>128</samp>, the game will get the first item type for which it exists in this order: object, big craftable, furniture, weapon, boots, hat, pants, shirt, tool, wallpaper, and floorpaper.
When resolving an unqualified item ID like <samp>128</samp>, the game will get the first item type for which it exists in this order: object, big craftable, furniture, weapon, boots, hat, mannequin, pants, shirt, tool, trinket, wallpaper, and floorpaper.


===Item sprites===
For each item type, the game has two files in its <samp>Content</samp> folder (which can be [[Modding:Editing XNB files#unpacking|unpacked for editing]]):
For each item type, the game has two files in its <samp>Content</samp> folder (which can be [[Modding:Editing XNB files#unpacking|unpacked for editing]]):
* a ''data asset'' for the text data for its items (names, descriptions, prices, etc);
* a ''data asset'' for the text data for its items (names, descriptions, prices, etc);
* and a ''spritesheet'' for the in-game item icons.
* and a ''spritesheet'' for the in-game item icons.


Each item has a <samp>ParentSheetIndex</samp> field which is its position in the item type's spritesheet, starting at 0 in the top-left and incrementing by one as you move across and then down. For example, hat #0 is the first sprite in <samp>Characters/Farmer/hats</samp>. The <samp>ParentSheetIndex</samp> is also used to identify the item itself; since spritesheet indexes aren't unique (''e.g.,'' there's both a hat #10 and object #10), code needs to check the type too like <code>item is Weapon weapon && weapon.ParentSheetIndex == 4</code>.
Each item has a <samp>ParentSheetIndex</samp> field which is its position in the item type's spritesheet, starting at 0 in the top-left and incrementing by one as you move across and then down. For example, hat #0 is the first sprite in <samp>Characters/Farmer/hats</samp>.
 
===Get a list of items===
With [[Modding:Player Guide/Getting Started|SMAPI installed]], you can [[Modding:Console commands#Console commands|run the <samp>list_items</samp> console command]] in-game to view/search items and their IDs.


===Define a custom item===
===Define a custom item===
Line 160: Line 103:
For example, this content pack adds a new Pufferchick item with a custom image, custom gift tastes, and a custom crop that produces it. Note that item references in other data assets like <samp>Data/Crops</samp> and <samp>Data/NPCGiftTastes</samp> use the item ID.
For example, this content pack adds a new Pufferchick item with a custom image, custom gift tastes, and a custom crop that produces it. Note that item references in other data assets like <samp>Data/Crops</samp> and <samp>Data/NPCGiftTastes</samp> use the item ID.


{{#tag:syntaxhighlight|<nowiki>
{{Content Patcher example|<nowiki>
{
    "Format": "</nowiki>{{Content Patcher version}}<nowiki>",
     "Changes": [
     "Changes": [
         // add item
         // add item
Line 220: Line 161:
         }
         }
     ]
     ]
}</nowiki>|lang=javascript}}
</nowiki>}}


Most item data assets work just like <samp>Data/Objects</samp>. See also specific info for [[Modding:Fruit_trees|custom fruit trees]], [[Modding:Items#Tools|custom tools]], and [[Modding:Items#Weapons|melee weapons]].
Most item data assets work just like <samp>Data/Objects</samp>. See also specific info for [[Modding:Fruit_trees|custom fruit trees]], [[Modding:Tools|custom tools]], and [[Modding:Weapons|melee weapons]].


===Error items===
===Error items===
Prior to 1.6, in-game items with no underlying data (e.g. because you removed the mod which adds them) would previously cause issues like invisible items, errors, and crashes. This was partly mitigated by the bundled Error Handler mod.
When an item is broken (e.g. due to deleting the mod which adds it), it's represented in-game as a default [[Error Item]] with a <samp>🛇</samp> sprite. This keeps the previous item data in case the item data is re-added.
 
Stardew Valley 1.6 added comprehensive handling for such items. They'll be shown with a <samp>🛇</samp> sprite in inventory UIs and in-game, the name Error Item, and a description which indicates the missing item ID for troubleshooting.
 
===For C# mods===
<dl style="margin-left: 2em;">
 
<dt>Compare items</dt>
<dd>
Since <samp>Item.QualifiedItemId</samp> is globally unique, it can be used to simplify comparing items. For example:
 
{| class="wikitable"
|-
! old code
! new code
|-
|-
| <samp>item.ParentSheetIndex == 128</samp>
| <samp>item.QualifiedItemId == "(O)128"</samp>
|-
| <samp>IsNormalObjectAtParentSheetIndex(item, 128)</samp>
| <samp>item.QualifiedItemId == "(O)128"</samp>
|-
| <samp>!item.bigCraftable && item.ParentSheetIndex == 128</samp>
| <samp>item.QualifiedItemId == "(O)128"</samp>
|-
| <samp>item is Boots && item.ParentSheetIndex == 505</samp>
| <samp>item.QualifiedItemId == "(B)505"</samp>
|}
 
You can also use <samp>ItemRegistry.QualifyItemId</samp> to convert any item ID into a qualified one (if it's valid), and <samp>ItemRegistry.HasItemId</samp> to check if an item has a qualified or unqualified item ID.
 
Note that flavored item don't have their own ID. For example, Blueberry Wine and Wine are both <samp>(O)348</samp>. This affects flavored jellies, juices, pickles, and wines. In those cases you should still compare their separate fields like <samp>preservedParentSheetIndex</samp> (which actually contains the preserved item's <samp>ItemId</samp>, not its <samp>ParentSheetIndex</samp>).
</dd>
 
<dt>Construct items</dt>
<dd>When constructing items, specify the item's <samp>ItemId</samp> (''not'' <samp>QualifiedItemId</samp>). For example:
 
<syntaxhighlight lang="c#">
new Object("128", 1);                      // vanilla item
new Object("Example.ModId_Watermelon", 1); // custom item
</syntaxhighlight>
 
You can use a utility method to construct items from their <samp>QualifiedItemId</samp>:
 
<syntaxhighlight lang="c#">
Item item = ItemRegistry.Create("(B)505"); // Rubber Boots
</syntaxhighlight>
</dd>
 
<dt>Define custom item types</dt>
<dd>You can implement <samp>IItemDataDefinition</samp> for your own item type, and call <samp>ItemRegistry.AddTypeDefinition</samp> to register it. This provides all the logic needed by the game to handle the item type: where to get item data, how to draw them, etc.
 
'''This is extremely specialized''', and multiplayer compatibility is unknown. Most mods should add custom items within the existing types instead.</dd>
 
<dt>New <samp>Is*</samp> methods</dt>
<dd>1.6 added some <samp>StardewValley.Object</samp> methods to handle custom items in a generic way (and to let mods patch the logic):
{| class="wikitable"
|-
! method
! effect
|-
| <samp>object.IsBar()</samp>
| Whether the item is a [[Copper Bar|copper bar]], [[Iron Bar|iron bar]], [[Gold Bar|gold bar]], [[Iridium Bar|iridium bar]], or [[Radioactive Bar|radioactive bar]].
|-
| <samp>object.IsBreakableStone()</samp>
| Whether the item is a stone debris item which can be broken by a pickaxe.
|-
| <samp>object.IsFence()</samp>
| Whether the item is a [[Crafting#Fences|fence]].
|-
| <samp>object.IsFruitTreeSapling()</samp>
| Whether the item is a [[Fruit Trees|fruit tree]] sapling. This checks the <samp>Data\fruitTrees</samp> keys, so it works with custom fruit trees too.
|-
| <samp>object.IsHeldOverHead()</samp>
| Whether the player is shown holding up the item when it's selected in their toolbar. Default true (except for furniture).
|-
| <samp>object.IsIncubator()</samp>
| Whether the item can incubate [[Animals|farm animal]] eggs when placed in a building.
|-
| <samp>object.IsTapper()</samp>
| Whether the item is a [[Tapper|tapper]] or [[Heavy Tapper|heavy tapper]].
|-
| <samp>object.IsTeaSapling()</samp>
| Whether the item is a [[Tea Sapling|tea sapling]].
|-
| <samp>object.IsTwig()</samp>
| Whethere the item is a twig debris item.
|-
| <samp>object.IsWeeds()</samp>
| Whether the item is a weed debris item.
|}
</dd>
 
<dt>Work with item metadata</dt>
<dd>
1.6 added an <samp>ItemRegistry</samp> API for working with the new item system. Some of the provided methods are:
 
{| class="wikitable"
|-
! method
! effect
|-
| <samp>ItemRegistry.Create</samp>
| Create an item from its item ID (qualified or unqualified). If the ID doesn't match a real item, the optional <samp>allowNull</samp> parameter indicates whether to return null or an Error Item. For example:
<syntaxhighlight lang="c#">
Item item = ItemRegistry.Create("(B)505"); // Rubber Boots
</syntaxhighlight>
 
You can also get a specific value type instead of <samp>Item</samp> if needed. This will throw a descriptive exception if the type isn't compatible (e.g. you try to convert furniture to boots).
<syntaxhighlight lang="c#">
Boots item = ItemRegistry.Create<Boots>("(B)505"); // Rubber Boots
</syntaxhighlight>
|-
| <samp>ItemRegistry.Exists</samp>
| Get whether a qualified or unqualified item ID matches an existing item. For example:
<syntaxhighlight lang="c#">
bool pufferfishExist = ItemRegistry.Exists("(O)128");
</syntaxhighlight>
|-
| <samp>ItemRegistry.IsQualifiedId</samp>
| Get whether the given item ID is qualified with the type prefix (like <samp>(O)128</samp> instead of <samp>128</samp>).
|-
| <samp>ItemRegistry.QualifyItemId</samp>
| Get the unique qualified item ID given an unqualified or qualified one. For example:
<syntaxhighlight lang="c#">
string qualifiedId = ItemRegistry.QualifyItemId("128"); // returns (O)128
</syntaxhighlight>
|-
| <samp>ItemRegistry.GetMetadata</samp>
| This lets you get high-level info about an item:
<syntaxhighlight lang="c#">
// get info about Rubber Boots
ItemMetadata info = ItemRegistry.GetMetadata("(B)505");
 
// get item ID info
$"The item has unqualified ID {info.LocalId}, qualified ID {info.QualifiedId}, and is defined by the {info.TypeIdentifier} item data definition.";
 
// does the item exist in the data files?
bool exists = info.Exists();
</syntaxhighlight>
 
And get common parsed item data:
<syntaxhighlight lang="c#">
// get parsed info
ParsedItemData data = info.GetParsedData();
$"The internal name is {data.InternalName}, translated name {data.DisplayName}, description {data.Description}, etc.";
 
// draw an item sprite
Texture2D texture = data.GetTexture();
Rectangle sourceRect = data.GetSourceRect();
spriteBatch.Draw(texture, Vector2.Zero, sourceRect, Color.White);
</syntaxhighlight>
 
And create an item:
<syntaxhighlight lang="c#">
Item item = metadata.CreateItem();
</syntaxhighlight>
 
And get the type definition (note that this is very specialized, and you should usually use <samp>ItemRegistry</samp> instead to benefit from its caching and optimizations):
<syntaxhighlight lang="c#">
IItemDataDefinition typeDefinition = info.GetTypeDefinition();
</syntaxhighlight>
|-
| <samp>ItemRegistry.ResolveMetadata</samp>
| Equivalent to <samp>ItemRegistry.GetMetadata</samp>, except that it'll return null if the item doesn't exist.
|-
| <samp>ItemRegistry.GetData</samp>
| Get the parsed data about an item, or <samp>null</samp> if the item doesn't exist. This is a shortcut for <code>ItemRegistry.ResolveMetadata(id)?.GetParsedData()</code>; see the previous method for info on the parsed data.
|-
| <samp>ItemRegistry.GetDataOrErrorItem</samp>
| Equivalent to <samp>ItemRegistry.GetData</samp>, except that it'll return info for an Error Item if the item doesn't exist (e.g. for drawing in inventory).
|-
| <samp>ItemRegistry.GetErrorItemName</samp>
| Get a translated ''Error Item'' label.
|}
</dd>
</dl>


==Common data==
==Common data==
Line 432: Line 196:


===Categories===
===Categories===
Each item also has a category (represented by a negative integer). In code, you can get an item's category value from <samp>item.Category</samp>, and its translated name from <samp>item.getCategoryName()</samp>. Here are the valid categories:
Each item also has a category (represented by a negative integer). In code, you can get an item's category value from <samp>item.Category</samp>, and its translated name from <samp>item.getCategoryName()</samp>. 0 can be used as a blank value. Here are the valid categories:


{| class="wikitable sortable"
{| class="wikitable sortable"
Line 438: Line 202:
! value
! value
! internal constant
! internal constant
! [[#Context tags|context tag]]
! [[Modding:Context tags|context tag]]
! English translation
! English translation
! Color
! Properties
! Properties
|-
|-
Line 446: Line 211:
| <samp>category_gem</samp>
| <samp>category_gem</samp>
| Mineral
| Mineral
|style="background-color:#6E005A;color:#fff;text-align:center"|<samp>#6E005A</samp>
| Affected by [[Skills#Mining|Gemologist]] profession
| Affected by [[Skills#Mining|Gemologist]] profession
|-
|-
Line 452: Line 218:
| <samp>category_fish</samp>
| <samp>category_fish</samp>
| Fish
| Fish
|style="background-color:#00008B;color:#fff;text-align:center"|<samp>#00008B</samp> (DarkBlue)
| Affected by [[Skills#Fishing|Fisher]] and [[Skills#Fishing|Angler]] professions
| Affected by [[Skills#Fishing|Fisher]] and [[Skills#Fishing|Angler]] professions
|-
|-
Line 458: Line 225:
| <samp>category_egg</samp>
| <samp>category_egg</samp>
| Animal Product
| Animal Product
|style="background-color:#FF0064;color:#000;text-align:center"|<samp>#FF0064</samp>
| Affected by [[Skills#Farming|Rancher]] profession, can be used in a slingshot
| Affected by [[Skills#Farming|Rancher]] profession, can be used in a slingshot
|-
|-
Line 464: Line 232:
| <samp>category_milk</samp>
| <samp>category_milk</samp>
| Animal Product
| Animal Product
|style="background-color:#FF0064;color:#000;text-align:center"|<samp>#FF0064</samp>
| Affected by [[Skills#Farming|Rancher]] profession
| Affected by [[Skills#Farming|Rancher]] profession
|-
|-
Line 470: Line 239:
| <samp>category_cooking</samp>
| <samp>category_cooking</samp>
| Cooking
| Cooking
|style="background-color:#DC3C00;color:#000;text-align:center"|<samp>#DC3C00</samp>
|
|
|-
|-
Line 476: Line 246:
| <samp>category_crafting</samp>
| <samp>category_crafting</samp>
| Crafting
| Crafting
|style="background-color:#943D28;color:#FFF;text-align:center">|<samp>#943D28</samp>
| Is Placeable
| Is Placeable
|-
|-
Line 481: Line 252:
| <samp>Object.BigCraftableCategory</samp>
| <samp>Object.BigCraftableCategory</samp>
| <samp>category_big_craftable</samp>
| <samp>category_big_craftable</samp>
|
|  
|  
| Is Placeable
| Is Placeable
Line 488: Line 260:
| <samp>category_minerals</samp>
| <samp>category_minerals</samp>
| Mineral
| Mineral
|style="background-color:#6E005A;color:#fff;text-align:center"|<samp>#6E005A</samp>
| Affected by [[Skills#Mining|Gemologist]] profession
| Affected by [[Skills#Mining|Gemologist]] profession
|-
|-
Line 494: Line 267:
| <samp>category_meat</samp>
| <samp>category_meat</samp>
| Animal Product
| Animal Product
|style="background-color:#FF0064;color:#000;text-align:center"|<samp>#FF0064</samp>
|
|
|-
|-
Line 500: Line 274:
| <samp>category_metal_resources</samp>
| <samp>category_metal_resources</samp>
| Resource
| Resource
|style="background-color:#406672;color:#FFF;text-align:center"|<samp>#406672</samp>
|
|
|-
|-
Line 506: Line 281:
| <samp>category_building_resources</samp>
| <samp>category_building_resources</samp>
| Resource
| Resource
|style="background-color:#406672;color:#FFF;text-align:center"|<samp>#406672</samp>
|
|
|-
|-
Line 511: Line 287:
| <samp>Object.sellAtPierres</samp>
| <samp>Object.sellAtPierres</samp>
| <samp>category_sell_at_pierres</samp>
| <samp>category_sell_at_pierres</samp>
|
|  
|  
|
|
Line 518: Line 295:
| <samp>category_sell_at_pierres_and_marnies</samp>
| <samp>category_sell_at_pierres_and_marnies</samp>
| Animal Product
| Animal Product
|style="background-color:#FF0064;color:#000;text-align:center"|<samp>#FF0064</samp>
| Affected by [[Skills#Farming|Rancher]] profession
| Affected by [[Skills#Farming|Rancher]] profession
|-
|-
Line 524: Line 302:
| <samp>category_fertilizer</samp>
| <samp>category_fertilizer</samp>
| Fertilizer
| Fertilizer
|style="background-color:#708090;color:#000;text-align:center"|<samp>#708090</samp> (SlateGray)
| Is Placeable, is always passable
| Is Placeable, is always passable
|-
|-
Line 530: Line 309:
| <samp>category_junk</samp>
| <samp>category_junk</samp>
| Trash
| Trash
|style="background-color:#696969;color:#000;text-align:center"|<samp>#696969</samp> (DimGray)
|
|
|-
|-
Line 536: Line 316:
| <samp>category_bait</samp>
| <samp>category_bait</samp>
| Bait
| Bait
|style="background-color:#8b0000;color:#FFF;text-align:center"|<samp>#8B0000</samp> (DarkRed)
| Can be attached to a fishing rod
| Can be attached to a fishing rod
|-
|-
Line 542: Line 323:
| <samp>category_tackle</samp>
| <samp>category_tackle</samp>
| Fishing Tackle
| Fishing Tackle
|style="background-color:#008b8b;color:#FFF;text-align:center"|<samp>#008B8B</samp> (DarkCyan)
| Can be attached to a fishing rod, cannot stack
| Can be attached to a fishing rod, cannot stack
|-
|-
Line 548: Line 330:
| <samp>category_sell_at_fish_shop</samp>
| <samp>category_sell_at_fish_shop</samp>
|  
|  
|
|
|
|-
|-
Line 554: Line 337:
| <samp>category_furniture</samp>
| <samp>category_furniture</samp>
| Decor
| Decor
|style="background-color:#9650be;color:#FFF;text-align:center"|<samp>#9650BE</samp>
|
|
|-
|-
Line 560: Line 344:
| <samp>category_ingredients</samp>
| <samp>category_ingredients</samp>
| Cooking
| Cooking
|
|
|
|-
|-
Line 566: Line 351:
| <samp>category_artisan_goods</samp>
| <samp>category_artisan_goods</samp>
| Artisan Goods
| Artisan Goods
|style="background-color:#009b6f;color:#000;text-align:center"|<samp>#009B6F</samp>
| Affected by [[Skills#Farming|Artisan]] profession
| Affected by [[Skills#Farming|Artisan]] profession
|-
|-
Line 572: Line 358:
| <samp>category_syrup</samp>
| <samp>category_syrup</samp>
| Artisan Goods
| Artisan Goods
|style="background-color:#009b6f;color:#000;text-align:center"|<samp>#009B6F</samp>
| Affected by [[Skills#Foraging|Tapper]] profession
| Affected by [[Skills#Foraging|Tapper]] profession
|-
|-
Line 578: Line 365:
| <samp>category_monster_loot</samp>
| <samp>category_monster_loot</samp>
| Monster Loot
| Monster Loot
|style="background-color:#320a46;color:#fff;text-align:center"|<samp>#320A46</samp>
|
|
|-
|-
Line 584: Line 372:
| <samp>category_equipment</samp>
| <samp>category_equipment</samp>
|  
|  
|
|
|
|-
|-
Line 590: Line 379:
| <samp>category_seeds</samp>
| <samp>category_seeds</samp>
| Seed
| Seed
|style="background-color:#a52a2a;color:#fff;text-align:center"|<samp>#A52A2A</samp> (Brown)
| Is Placeable, is always passable
| Is Placeable, is always passable
|-
|-
Line 596: Line 386:
| <samp>category_vegetable</samp>
| <samp>category_vegetable</samp>
| Vegetable
| Vegetable
|style="background-color:#008000;color:#FFF;text-align:center"|<samp>#008000</samp> (Green)
| Affected by [[Skills#Farming|Tiller]] profession, can be used in a slingshot
| Affected by [[Skills#Farming|Tiller]] profession, can be used in a slingshot
|-
|-
Line 602: Line 393:
| <samp>category_fruits</samp>
| <samp>category_fruits</samp>
| Fruit
| Fruit
|style="background-color:#ff1493;color:#000;text-align:center"|<samp>#FF1493</samp> (DeepPink)
| Affected by [[Skills#Farming|Tiller]] profession (if not foraged), can be used in a slingshot
| Affected by [[Skills#Farming|Tiller]] profession (if not foraged), can be used in a slingshot
|-
|-
Line 608: Line 400:
| <samp>category_flowers</samp>
| <samp>category_flowers</samp>
| Flower
| Flower
|style="background-color:#db36d3;color:#000;text-align:center"|<samp>#DB36D3</samp>
| Affected by [[Skills#Farming|Tiller]] profession
| Affected by [[Skills#Farming|Tiller]] profession
|-
|-
Line 614: Line 407:
| <samp>category_greens</samp>
| <samp>category_greens</samp>
| Forage
| Forage
|style="background-color:#0a8232;color:#FFF;text-align:center"|<samp>#0A8232</samp>
|
|
|-
|-
Line 620: Line 414:
| <samp>category_hat</samp>
| <samp>category_hat</samp>
|  
|  
|
|
|
|-
|-
Line 626: Line 421:
| <samp>category_ring</samp>
| <samp>category_ring</samp>
|  
|  
|
|
|
|-
|-
Line 632: Line 428:
| <samp>category_boots</samp>
| <samp>category_boots</samp>
|  
|  
|
|
|
|-
|-
Line 638: Line 435:
| <samp>category_weapon</samp>
| <samp>category_weapon</samp>
|  
|  
|
|
|
|-
|-
Line 644: Line 442:
| <samp>category_tool</samp>
| <samp>category_tool</samp>
|  
|  
|
|
|
|-
|-
Line 650: Line 449:
| <samp>category_clothing</samp>
| <samp>category_clothing</samp>
|  
|  
|
|
|
|-
|-
Line 656: Line 456:
| <samp>category_trinket</samp>
| <samp>category_trinket</samp>
|  
|  
|
|
|
|-
|-
Line 662: Line 463:
|  
|  
|  
|  
|style="background-color:#552f1b;color:#fff;text-align:center"|<samp>#552F1B</samp>
|
|
|-
|-
Line 668: Line 470:
|  
|  
|  
|  
|style="background-color:#7a5d27;color:#fff;text-align:center"|<samp>#7A5d27</samp>
|
|
|-
|-
Line 674: Line 477:
| <samp>category_litter</samp>
| <samp>category_litter</samp>
|  
|  
|
|
|
|}
|}
Line 688: Line 492:
See [[Modding:Context tags]] for more info.
See [[Modding:Context tags]] for more info.


==Objects==
==Specific item types==
See [[Modding:Objects]] for more info.
For docs about each item type (e.g. objects or weapons), see the [[#Item types|''item types'']] table above.


==Big craftables==
==For C# mods==
Big craftables are objects which can be placed in the world and are two tiles tall (instead of one like objects). See [[Modding:Big craftables]] for more info.
===Identify items===
You can uniquely identify items by checking their [[#Item IDs|item ID]] fields. For example:


==Boots==
<syntaxhighlight lang="c#">
See [[Modding:Boots]] for more info.
bool isPufferfish = item.QualifiedItemId == "(O)128";
</syntaxhighlight>
 
The <samp>ItemRegistry</samp> class also provides methods to work with items. For example:
<syntaxhighlight lang="c#">
// check if item would be matched by a qualified or unqualified item ID
bool isPufferfish = ItemRegistry.HasItemId(item, "128");


==Pants==
// qualify an item ID if needed
See [[Modding:Pants]] for more info.
string pufferfishQualifiedId = ItemRegistry.QualifyItemId("128"); // returns "(O)128"
</syntaxhighlight>


==Shirts==
Note that flavored items like [[Jellies and Pickles|jellies]] and [[wine]] don't have their own ID. For example, Blueberry Wine and Wine are both <samp>(O)348</samp>. You can get the flavor item ID from the <samp>preservedParentSheetIndex</samp> field; for example, Blueberry Wine will have the item ID for blueberry. (Despite the name, it contains the item's ID rather than its <samp>ParentSheetIndex</samp>).
See [[Modding:Shirts]] for more info.


==Furniture==
===Create item instances===
Furniture are decorative items which can be placed in the world, including chairs which the player can sit on.
The <samp>ItemRegistry.Create</samp> method is the main way to construct items. For example:
<syntaxhighlight lang="c#">
Item pufferfish = ItemRegistry.Create("(O)128"); // can optionally specify count and quality
</syntaxhighlight>


See [[Modding:Furniture]] for more info.
If the ID doesn't match a real item, the <samp>ItemRegistry</samp> will return an [[Error Item]] by default. You can override that by setting <samp>allowNull: true</samp> when calling the method.


==Hats==
You can also get a specific value type instead of <samp>Item</samp> if needed. This will throw a descriptive exception if the type isn't compatible (e.g. you try to convert furniture to boots).
Hats are items that can be equipped in the player's [[hats|hat]] slot.
<syntaxhighlight lang="c#">
Boots boots = ItemRegistry.Create<Boots>("(B)505"); // Rubber Boots
</syntaxhighlight>


See [[Modding:Hats]] for more info.
When creating an item manually instead, make sure to pass its <samp>ItemId</samp> (''not'' <samp>QualifiedItemId</samp>) to the constructor. For example:
<syntaxhighlight lang="c#">
Item pufferfish = new Object("128", 1);
</syntaxhighlight>


==Tools==
===Work with item metadata===
[[Tools]] are items that can be swung or used by the player to perform some effect (e.g. dig dirt, chop trees, etc).
The <samp>ItemRegistry</samp> class provides several methods for working with item metadata. Some useful methods include:


See [[Modding:Tools]] for more info.
{| class="wikitable"
|-
! method
! effect
|-
| <samp>ItemRegistry.Create</samp>
| [[#Create item instances|Create an item instance]].
|-
| <samp>ItemRegistry.Exists</samp>
| Get whether a qualified or unqualified item ID matches an existing item. For example:
<syntaxhighlight lang="c#">
bool pufferfishExists = ItemRegistry.Exists("(O)128");
</syntaxhighlight>
|-
| <samp>ItemRegistry.IsQualifiedId</samp>
| Get whether the given item ID is qualified with the type prefix (like <samp>(O)128</samp> instead of <samp>128</samp>).
|-
| <samp>ItemRegistry.QualifyItemId</samp>
| Get the unique qualified item ID given an unqualified or qualified one. For example:
<syntaxhighlight lang="c#">
string qualifiedId = ItemRegistry.QualifyItemId("128"); // returns (O)128
</syntaxhighlight>
|-
| <samp>ItemRegistry.GetMetadata</samp>
| Get high-level info about an item:
<syntaxhighlight lang="c#">
// get info about Rubber Boots
ItemMetadata metadata = ItemRegistry.GetMetadata("(B)505");
 
// get item ID info
$"The item has unqualified ID {metadata.LocalId}, qualified ID {metadata.QualifiedId}, and is defined by the {metadata.TypeIdentifier} item data definition.";
 
// does the item exist in the data files?
bool exists = metadata.Exists();
</syntaxhighlight>
 
And get common parsed item data:
<syntaxhighlight lang="c#">
// get parsed info
ParsedItemData data = metadata.GetParsedData();
$"The internal name is {data.InternalName}, translated name {data.DisplayName}, description {data.Description}, etc.";
 
// draw an item sprite
Texture2D texture = data.GetTexture();
Rectangle sourceRect = data.GetSourceRect();
spriteBatch.Draw(texture, Vector2.Zero, sourceRect, Color.White);
</syntaxhighlight>
 
And create an item:
<syntaxhighlight lang="c#">
Item item = metadata.CreateItem();
</syntaxhighlight>
 
And get the type definition (note that this is very specialized, and you should usually use <samp>ItemRegistry</samp> instead to benefit from its caching and optimizations):
<syntaxhighlight lang="c#">
IItemDataDefinition typeDefinition = info.GetTypeDefinition();
</syntaxhighlight>
|-
| <samp>ItemRegistry.ResolveMetadata</samp>
| Equivalent to <samp>ItemRegistry.GetMetadata</samp>, except that it'll return null if the item doesn't exist.
|-
| <samp>ItemRegistry.GetData</samp>
| Get the parsed data about an item, or <samp>null</samp> if the item doesn't exist. This is a shortcut for <code>ItemRegistry.ResolveMetadata(id)?.GetParsedData()</code>; see the previous method for info on the parsed data.
|-
| <samp>ItemRegistry.GetDataOrErrorItem</samp>
| Equivalent to <samp>ItemRegistry.GetData</samp>, except that it'll return info for an [[Error Item]] if the item doesn't exist (e.g. for drawing in inventory).
|-
| <samp>ItemRegistry.GetErrorItemName</samp>
| Get a translated ''Error Item'' label.
|}


==Weapons==
===Define custom item types===
[[Weapons]] are tools that can be used by the player to damage monsters.
You can implement <samp>IItemDataDefinition</samp> for your own item type, and call <samp>ItemRegistry.AddTypeDefinition</samp> to register it. This provides all the logic needed by the game to handle the item type: where to get item data, how to draw them, etc.


See [[Modding:Weapons]] for more info.
'''This is extremely specialized''', and multiplayer compatibility is unknown. Most mods should add custom items within the existing types instead.


==See also==
==See also==
* For specific item types, see the [[#Item types|''item types'']] table above.
* [[Modding:Index]] for related content like [[Modding:Crop data|crops]], [[Modding:Fish data|fish]], [[Modding:Gift taste data|gift tastes]], and [[Modding:Recipe data|recipes]]
* [[Modding:Index]] for related content like [[Modding:Crop data|crops]], [[Modding:Fish data|fish]], [[Modding:Gift taste data|gift tastes]], and [[Modding:Recipe data|recipes]]


[[Category:Modding]]
[[Category:Modding]]


[[ru:Модификации:Предметы]]
[[zh:模组:物品数据]]
[[zh:模组:物品数据]]

Latest revision as of 16:15, 4 August 2026

← Index

This page explains how the game stores and parses item data. This is an advanced guide for mod developers.

Overview

Item IDs

Every item is identified in the game data using a unique item ID. This has two forms:

  • The unqualified item ID (item.ItemId) is a unique string ID for the item, like 128 (vanilla item) or Example.ModId_Watermelon (custom item). For legacy reasons, the unqualified ID for vanilla items may not be globally unique; for example, Pufferfish (object 128) and Mushroom Box (bigcraftable 128) both have item ID 128.
  • The qualified item ID (item.QualifiedItemId) is a globally unique identifier which combines the item's type ID and unqualified item ID, like (O)128 for object ID 128.

With SMAPI installed, you can run the list_items console command in-game to search item IDs.

Note: mods created before Stardew Valley 1.6 may use the item.ParentSheetIndex field as an item identifier. This is not a valid identifier; multiple items of the same type may have the same sprite index for different textures.

Item types

Items are defined by item type data definitions, which handle parsing data of a certain type. For example, the game's ObjectDataDefinition class handles producing object-type items by parsing the Data/Objects asset.

Each definition has a unique ID like (O), which is used to form globally unique qualified item IDs. In C# code, this is tracked by the item.TypeDefinitionId field, which matches ItemRegistry.type_* constants for vanilla item types.

These are the item types for which custom items can added/edited:

item type type identifier data asset brief summary
Objects (O) Data/Objects The most common item type. Depending on their data, they can be placed in the world, picked up, eaten, sold to shops, etc.
Big craftables (BC) Data/BigCraftables Items which can be placed in the world and are two tiles tall (instead of one like objects).
Boots (B) Data/Boots Items which can be equipped in the player's boots slot. These change the player sprite and may provide buffs.
Furniture (F) Data/Furniture Decorative items which can be placed in the world. In some cases players can sit on them or place items on them.
Hats (H) Data/Hats Items which can be equipped in the player's hat slot. These change the player sprite.
Mannequins (M) Data/Mannequins Decorative items which can be placed in the world, and used to store and display clothing.
Pants (P) Data/Pants Items which can be equipped in the player's pants slot. These change the player sprite.
Shirts (S) Data/Shirts Items which can be equipped in the player's shirt slot. These change the player sprite.
Tools (T) Data/Tools Items that can be swung or used by the player to perform some effect (e.g. dig dirt, chop trees, milk or shear animals, etc).
Trinkets (TR) Data/Trinkets Items that can be equipped in the player's trinket slot to enable special effects.
Wallpaper & flooring (WP) and (FL) Data/AdditionalWallpaperFlooring Items which can be applied to a decoratable location (e.g. a farmhouse or shed) to visually change its floor or wall design. (These are separate from placeable items like brick floor.)
Weapons (W) Data/Weapons Items which can be swung or used by the player to damage monsters.

When resolving an unqualified item ID like 128, the game will get the first item type for which it exists in this order: object, big craftable, furniture, weapon, boots, hat, mannequin, pants, shirt, tool, trinket, wallpaper, and floorpaper.

Item sprites

For each item type, the game has two files in its Content folder (which can be unpacked for editing):

  • a data asset for the text data for its items (names, descriptions, prices, etc);
  • and a spritesheet for the in-game item icons.

Each item has a ParentSheetIndex field which is its position in the item type's spritesheet, starting at 0 in the top-left and incrementing by one as you move across and then down. For example, hat #0 is the first sprite in Characters/Farmer/hats.

Define a custom item

You can define custom items for most vanilla item types using only Content Patcher or SMAPI's content API.

For example, this content pack adds a new Pufferchick item with a custom image, custom gift tastes, and a custom crop that produces it. Note that item references in other data assets like Data/Crops and Data/NPCGiftTastes use the item ID.

{
    "Format": "2.8.0",
    "Changes": [
        // add item
        {
            "Action": "EditData",
            "Target": "Data/Objects",
            "Entries": {
                "{{ModId}}_Pufferchick": {
                    "Name": "{{ModId}}_Pufferchick", // best practice to match the ID, since it's sometimes used as an alternate ID (e.g. in Data/CraftingRecipes)
                    "Displayname": "Pufferchick",
                    "Description": "An example object.",
                    "Type": "Seeds",
                    "Category": -74,
                    "Price": 1200,

                    "Texture": "Mods/{{ModId}}/Objects",
                    "SpriteIndex": 0
                }
            }
        },

        // add gift tastes
        {
            "Action": "EditData",
            "Target": "Data/NPCGiftTastes",
            "TextOperations": [
                {
                    "Operation": "Append",
                    "Target": ["Entries", "Universal_Love"],
                    "Value": "{{ModId}}_Pufferchick",
                    "Delimiter": " " // if there are already values, add a space between them and the new one
                }
            ]
        },

        // add crop (Pufferchick is both seed and produce, like coffee beans)
        {
            "Action": "EditData",
            "Target": "Data/Crops",
            "Entries": {
                "{{ModId}}_Pufferchick": {
                    "Seasons": [ "spring", "summer", "fall" ],
                    "DaysInPhase": [ 1, 1, 1, 1, 1 ],
                    "HarvestItemId": "{{ModId}}_Pufferchick",

                    "Texture": "Mods/{{ModId}}/Crops",
                    "SpriteIndex": 0
                }
            }
        },

        // add item + crop images
        {
            "Action": "Load",
            "Target": "Mods/{{ModId}}/Crops, Mods/{{ModId}}/Objects",
            "FromFile": "assets/{{TargetWithoutPath}}.png" // assets/Crops.png, assets/Objects.png
        }
    ]
}

Most item data assets work just like Data/Objects. See also specific info for custom fruit trees, custom tools, and melee weapons.

Error items

When an item is broken (e.g. due to deleting the mod which adds it), it's represented in-game as a default Error Item with a 🛇 sprite. This keeps the previous item data in case the item data is re-added.

Common data

Quality

Each item has a quality level which (depending on the item type) may affect its price, health boost, etc. The valid qualities are:

quality value constant
normal 0 Object.lowQuality
silver 1 Object.medQuality
gold 2 Object.highQuality
iridium 4 Object.bestQuality

Categories

Each item also has a category (represented by a negative integer). In code, you can get an item's category value from item.Category, and its translated name from item.getCategoryName(). 0 can be used as a blank value. Here are the valid categories:

value internal constant context tag English translation Color Properties
-2 Object.GemCategory category_gem Mineral #6E005A Affected by Gemologist profession
-4 Object.FishCategory category_fish Fish #00008B (DarkBlue) Affected by Fisher and Angler professions
-5 Object.EggCategory category_egg Animal Product #FF0064 Affected by Rancher profession, can be used in a slingshot
-6 Object.MilkCategory category_milk Animal Product #FF0064 Affected by Rancher profession
-7 Object.CookingCategory category_cooking Cooking #DC3C00
-8 Object.CraftingCategory category_crafting Crafting #943D28 Is Placeable
-9 Object.BigCraftableCategory category_big_craftable Is Placeable
-12 Object.mineralsCategory category_minerals Mineral #6E005A Affected by Gemologist profession
-14 Object.meatCategory category_meat Animal Product #FF0064
-15 Object.metalResources category_metal_resources Resource #406672
-16 Object.buildingResources category_building_resources Resource #406672
-17 Object.sellAtPierres category_sell_at_pierres
-18 Object.sellAtPierresAndMarnies category_sell_at_pierres_and_marnies Animal Product #FF0064 Affected by Rancher profession
-19 Object.fertilizerCategory category_fertilizer Fertilizer #708090 (SlateGray) Is Placeable, is always passable
-20 Object.junkCategory category_junk Trash #696969 (DimGray)
-21 Object.baitCategory category_bait Bait #8B0000 (DarkRed) Can be attached to a fishing rod
-22 Object.tackleCategory category_tackle Fishing Tackle #008B8B (DarkCyan) Can be attached to a fishing rod, cannot stack
-23 Object.sellAtFishShopCategory category_sell_at_fish_shop
-24 Object.furnitureCategory category_furniture Decor #9650BE
-25 Object.ingredientsCategory category_ingredients Cooking
-26 Object.artisanGoodsCategory category_artisan_goods Artisan Goods #009B6F Affected by Artisan profession
-27 Object.syrupCategory category_syrup Artisan Goods #009B6F Affected by Tapper profession
-28 Object.monsterLootCategory category_monster_loot Monster Loot #320A46
-29 Object.equipmentCategory category_equipment
-74 Object.SeedsCategory category_seeds Seed #A52A2A (Brown) Is Placeable, is always passable
-75 Object.VegetableCategory category_vegetable Vegetable #008000 (Green) Affected by Tiller profession, can be used in a slingshot
-79 Object.FruitsCategory category_fruits Fruit #FF1493 (DeepPink) Affected by Tiller profession (if not foraged), can be used in a slingshot
-80 Object.flowersCategory category_flowers Flower #DB36D3 Affected by Tiller profession
-81 Object.GreensCategory category_greens Forage #0A8232
-95 Object.hatCategory category_hat
-96 Object.ringCategory category_ring
-97 Object.bootsCategory category_boots
-98 Object.weaponCategory category_weapon
-99 Object.toolCategory category_tool
-100 Object.clothingCategory category_clothing
-101 Object.trinketCategory category_trinket
-102 Object.booksCategory #552F1B
-103 Object.skillBooksCategory #7A5d27
-999 Object.litterCategory category_litter
Console commands 
With the Console Code mod installed, you can run this command in the SMAPI console to see a list of objects by category:
cs return string.Join(`\n`, Game1.objectData.Keys.Select(key => new StardewValley.Object(key, 1)).GroupBy(item => item.Category, item => item.Name).OrderByDescending(p => p.Key).Select(p => $`{p.Key}: {string.Join(`, `, p.OrderBy(name => name))}`));

Context tags

A context tag is an arbitrary data label like category_gem or item_apple attached to items. These provide metadata about items (e.g. their color, quality, category, general groupings like alcohol or fish, etc), and may affect game logic (e.g. machine processing).

See Modding:Context tags for more info.

Specific item types

For docs about each item type (e.g. objects or weapons), see the item types table above.

For C# mods

Identify items

You can uniquely identify items by checking their item ID fields. For example:

bool isPufferfish = item.QualifiedItemId == "(O)128";

The ItemRegistry class also provides methods to work with items. For example:

// check if item would be matched by a qualified or unqualified item ID
bool isPufferfish = ItemRegistry.HasItemId(item, "128");

// qualify an item ID if needed
string pufferfishQualifiedId = ItemRegistry.QualifyItemId("128"); // returns "(O)128"

Note that flavored items like jellies and wine don't have their own ID. For example, Blueberry Wine and Wine are both (O)348. You can get the flavor item ID from the preservedParentSheetIndex field; for example, Blueberry Wine will have the item ID for blueberry. (Despite the name, it contains the item's ID rather than its ParentSheetIndex).

Create item instances

The ItemRegistry.Create method is the main way to construct items. For example:

Item pufferfish = ItemRegistry.Create("(O)128"); // can optionally specify count and quality

If the ID doesn't match a real item, the ItemRegistry will return an Error Item by default. You can override that by setting allowNull: true when calling the method.

You can also get a specific value type instead of Item if needed. This will throw a descriptive exception if the type isn't compatible (e.g. you try to convert furniture to boots).

Boots boots = ItemRegistry.Create<Boots>("(B)505"); // Rubber Boots

When creating an item manually instead, make sure to pass its ItemId (not QualifiedItemId) to the constructor. For example:

Item pufferfish = new Object("128", 1);

Work with item metadata

The ItemRegistry class provides several methods for working with item metadata. Some useful methods include:

method effect
ItemRegistry.Create Create an item instance.
ItemRegistry.Exists Get whether a qualified or unqualified item ID matches an existing item. For example:
bool pufferfishExists = ItemRegistry.Exists("(O)128");
ItemRegistry.IsQualifiedId Get whether the given item ID is qualified with the type prefix (like (O)128 instead of 128).
ItemRegistry.QualifyItemId Get the unique qualified item ID given an unqualified or qualified one. For example:
string qualifiedId = ItemRegistry.QualifyItemId("128"); // returns (O)128
ItemRegistry.GetMetadata Get high-level info about an item:
// get info about Rubber Boots
ItemMetadata metadata = ItemRegistry.GetMetadata("(B)505");

// get item ID info
$"The item has unqualified ID {metadata.LocalId}, qualified ID {metadata.QualifiedId}, and is defined by the {metadata.TypeIdentifier} item data definition.";

// does the item exist in the data files?
bool exists = metadata.Exists();

And get common parsed item data:

// get parsed info
ParsedItemData data = metadata.GetParsedData();
$"The internal name is {data.InternalName}, translated name {data.DisplayName}, description {data.Description}, etc.";

// draw an item sprite
Texture2D texture = data.GetTexture();
Rectangle sourceRect = data.GetSourceRect();
spriteBatch.Draw(texture, Vector2.Zero, sourceRect, Color.White);

And create an item:

Item item = metadata.CreateItem();

And get the type definition (note that this is very specialized, and you should usually use ItemRegistry instead to benefit from its caching and optimizations):

IItemDataDefinition typeDefinition = info.GetTypeDefinition();
ItemRegistry.ResolveMetadata Equivalent to ItemRegistry.GetMetadata, except that it'll return null if the item doesn't exist.
ItemRegistry.GetData Get the parsed data about an item, or null if the item doesn't exist. This is a shortcut for ItemRegistry.ResolveMetadata(id)?.GetParsedData(); see the previous method for info on the parsed data.
ItemRegistry.GetDataOrErrorItem Equivalent to ItemRegistry.GetData, except that it'll return info for an Error Item if the item doesn't exist (e.g. for drawing in inventory).
ItemRegistry.GetErrorItemName Get a translated Error Item label.

Define custom item types

You can implement IItemDataDefinition for your own item type, and call ItemRegistry.AddTypeDefinition to register it. This provides all the logic needed by the game to handle the item type: where to get item data, how to draw them, etc.

This is extremely specialized, and multiplayer compatibility is unknown. Most mods should add custom items within the existing types instead.

See also