Modding:Items

From Stardew Valley Wiki
Revision as of 01:24, 28 January 2022 by Pathoschild (talk | contribs) (→‎Categories: replace outdated export with a console command to export it anytime)
Jump to navigation Jump to search

Index

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

Introduction

Overview

Items are divided into several types:

item type data asset texture name summary
Object Data/ObjectInformation Maps/springobjects The default type for items in inventories or placed in the world.
Object (big craftable) Data/BigCraftablesInformation TileSheets/Craftables Craftable items which can be placed in the world and are two tiles tall (instead of one like objects).
Boots Data/Boots item sprite: Maps/springobjects
shoe color: Characters/Farmer/shoeColors
Equippable boots.
Clothing Data/ClothingInformation Characters/Farmer/pants
Characters/Farmer/shirts
Equippable pants and shirts.
Furniture Data/Furniture TileSheets/furniture Decorative furniture items, including chairs which the player can sit on.
Hat Data/Hats Characters/Farmer/hats Equippable hat items.
Tool TileSheets/Tools Tools that can be used by the player.
MeleeWeapon Data/Weapons TileSheets/weapons Weapons that can be used by the player to damage monsters.

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

  • 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. The ParentSheetIndex 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 item is Weapon weapon && weapon.ParentSheetIndex == 4.

See the sections below for details on each item type.

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(). Here are the valid categories:

value internal constant English translation
-2 Object.GemCategory Mineral
-4 Object.FishCategory Fish
-5 Object.EggCategory Animal Product
-6 Object.MilkCategory Animal Product
-7 Object.CookingCategory Cooking
-8 Object.CraftingCategory Crafting
-9 Object.BigCraftableCategory
-12 Object.mineralsCategory Mineral
-14 Object.meatCategory Animal Product
-15 Object.metalResources Resource
-16 Object.buildingResources Resource
-17 Object.sellAtPierres
-18 Object.sellAtPierresAndMarnies Animal Product
-19 Object.fertilizerCategory Fertilizer
-20 Object.junkCategory Trash
-21 Object.baitCategory Bait
-22 Object.tackleCategory Fishing Tackle
-23 sellAtFishShopCategory
-24 Object.furnitureCategory Decor
-25 Object.ingredientsCategory Cooking
-26 Object.artisanGoodsCategory Artisan Goods
-27 Object.syrupCategory Artisan Goods
-28 Object.monsterLootCategory Monster Loot
-29 Object.equipmentCategory
-74 Object.SeedsCategory Seed
-75 Object.VegetableCategory Vegetable
-79 Object.FruitsCategory Fruit
-80 Object.flowersCategory Flower
-81 Object.GreensCategory Forage
-95 Object.hatCategory
-96 Object.ringCategory
-98 Object.weaponCategory
-99 Object.toolCategory
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.objectInformation.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))}`));

Define a custom item

Every item must be assigned a unique ParentSheetIndex within its type, and that index must fit within the item type's spritesheet.

Adding custom items to the data assets and spritesheets directly is not recommended, since it's very easy to conflict with other mods or cause game errors. Instead you should create a content pack for Json Assets, which coordinates dynamic item ID assignment so multiple custom item mods can work together.

Objects

Objects are the default type for items in inventories or placed in the world.

They have their data in Data/ObjectInformation, their icon sprites in Maps/springobjects, and their code in StardewValley.Object. See a table of sprites and their corresponding indexes.

Data format

The object data in Data/ObjectInformation consists of an integer→string dictionary with entries like this:

  "18": "Daffodil/30/0/Basic -81/Daffodil/A traditional spring flower that makes a nice gift."

For each entry in the data asset, the key is the item's ParentSheetIndex and the value is a slash-delimited string with the fields listed below. Fields 0–5 are used by rings and most other objects; fields 6–11 are only used for food buffs. The objects with keys 516–534 (Ring.ringLowerIndexRange through Ring.ringUpperIndexRange) and 801 (wedding ring) are hardcoded as rings.

index field effect
all objects
0 name The internal item name (and display name in English).
1 price The gold price of the item when sold by the player.
2 edibility A numeric value that determines how much health (edibility × 2.5) and energy (edibility × 1.125) is restored. An item with an edibility of -300 can't be eaten.

This is ignored for rings.

3 type and category
  • For a ring: the value Ring. Rings have a hardcoded category of -96 (Object.ringCategory).
  • For other objects: the item's type (string) and category (negative integer), separated by a space like Fish -4.
4 display name The translated item name.
5 description The translated item description.
food & drink only
6 miscellaneous
  • For a food or drink item, set this to food or drink respectively. This enables the remaining fields, and changes which animation/sound is played when the player consumes the item. Any other value is ignored.
  • For a geode item (535, 536, 537, or 749) is broken, a space-delimited list of object IDs. There's a roughly 50% chance that the geode item will drop one of these items (the other drops are hardcoded).
7 buffs The bonuses to apply to the player's attribute when the item is consumed. This consists of a space-delimited list of these numbers:
index buff
0 farming
1 fishing
2 mining
3 unused
4 luck
5 foraging
6 unused
7 max energy
8 magnetism
9 speed
10 defense
11 attack
8 buff duration How long the buffs provided by the previous field last. This is converted into in-game minutes using the formula (duration × 0.7) / 60. The buff duration number shown in-game will always be one second less than the calculated value.

Notes

  • Items that have a number in the "Crafting" field show buggy information in-game (e.g., Bean Hotpot prior to version 1.4). Items that have a number in the "Attack" field display the Attack icon and a number, but no description. It's unclear how these buffs work (if at all).
  • Named buffs (like Oil of Garlic, Life Elixir, or Tipsy) are implemented in code and can't be set in the food buff fields.
  • The spritesheet and data have items that can't normally be found in the player inventory (like twigs and lumber), and some sprites have no corresponding item data. There are also multiple entries for weeds and stone corresponding to different sprites, but the player can only normally obtain one stone item (index 390) and no weeds items.