Modding:Common tasks
← Index
Article Stub
This article is a stub and is missing information. You can help Stardew Valley Wiki by expanding it! |
This page explains how mod creators can perform common tasks in SMAPI mods. (Note: this page is for interacting with the game itself, for SMAPI-provided tasks see SMAPI reference)
Things to note
Many things in Stardew Valley are accessed through Game1. It is highly recommended to decompile the game source and look at how the game does things and then attempt to do it yourself. This is a general guide to point you to the right places in the code to look, it is not meant to give you the code. Modding:Creating a SMAPI mod //todo link to decompiling section
Items
Items are objects which represent things which can be put in an inventory. Tools, Crops, etc.
Create an Item
//todo
Remove an Item
//todo
Add an item to an inventory
//todo
Remove an item from an inventory
item.Stack--;
if (item.Stack == 0) {
inventory.Remove(item);
}
Locations
The GameLocation is a representation of any place in the game (e.g. Farm, Town) This it a good starting point for many things such as modifying tiles, etc.
Map Properties
You can edit many properties of the current map and the tiles in the map. This is already documented here Modding:Maps //todo link to Map Properties
Tiles
terrainFeatures contains information about the tiles. (e.g. dirt, grass)
objects contains information about objects on top of tiles. (e.g. crops, stones)
Valid Position
terrainFeatures.ContainsKey(Vector2)
objects.ContainsKey(Vector2)
HoeDirt
terrainFeatures[Vector2] is HoeDirt hd
Check if there crops on this dirt with hd.crops
Player
//todo describe section
Position
//todo
UI
//todo describe section
Banner Message
Add a new HUDMessage to show [insert image] banner.
Game1.addHUDMessage(new HUDMessage("MESSAGE", 3));
Optional parameters noIcon and timeLeft The 3 is because ...?
Menus
//todo describe section
Set the active Menu
Game1.activeClickableMenu = <Menu>
Simple Menu
Copy the menu you want from the game and make it your own
Harmony
//todo warning USE AT YOUR OWN RISK Ask @Cat on discord
Other
Add a small animation
location.temporarySprites.Add(new TemporaryAnimatedSprite(...))
See TemporaryAnimatedSprite for more details
Play a sound
location.playSound("SOUND");
(e.g. "junimoMeep1")
Open Source
When all else fails, when you've looked at the decompiled source too long and it makes no sense, take a look at some open source mod code! There's a lot out there, including (in no particular order):
- https://github.com/Pathoschild/StardewMods
- https://github.com/danvolchek/StardewMods
- https://github.com/Platonymous/Stardew-Valley-Mods/
- https://github.com/cheesysteak/stardew-steak
- https://github.com/Shalankwa/SDV_Mods
- https://github.com/CJBok/SDV-Mods
- https://github.com/cantorsdust/StardewMods
- https://github.com/Bouhm/stardew-valley-mods
- https://github.com/Zoryn4163/SMAPI-Mods
- https://github.com/spacechase0?tab=repositories
- https://github.com/hawkfalcon/Stardew-Mods