Difference between revisions of "Modding:Modder Guide/Game Fundamentals"
Pathoschild (talk | contribs) m (Pathoschild moved page Modding:Stardew Valley fundamentals to Modding:Game fundamentals without leaving a redirect: simplify name) |
Pathoschild (talk | contribs) m (Pathoschild moved page Modding:Game fundamentals to Modding:Modder Guide/Game Fundamentals without leaving a redirect: integrate into modder guide) |
(No difference)
|
Revision as of 23:47, 1 June 2018
This page explains some of the Stardew Valley fundamentals that are useful for modders. See also Modding:Common tasks.
Data structures
Net fields
A 'net type' is any of several classes which Stardew Valley uses to sync data between players, named for the Net
prefix in their name. A net type can represent a simple value like NetBool, or complex values like NetFieldDictionary. The game will regularly collect all the net fields reachable from Game1.netWorldState and sync them with other players. That means that many mod changes will be synchronised automatically in multiplayer.
Net fields can implicitly convert to their underlying value type (like bool x = new NetBool(true)
), but their conversion rules can be counterintuitive and error-prone. For example, item?.category == null && item?.category != null
can both be true at once. Always avoid implicit casts to minimise bugs. Instead, access the underlying value using .Value (or .Pairs on a net dictionary):
NetString str = new NetString("bar"); if (str.Value == "bar") // true
The build config NuGet package should detect most implicit conversions and show an appropriate build warning.
Main classes
Game1
Game1 is the game's core logic. Most of the game state is tracked through this class. Here are some of the most useful fields:
field | purpose |
---|---|
Game1.player | The current player. |
Game1.currentLocation | The game location containing the current player. For a non-main player, may be null when transitioning between locations. |
Game1.locations | All locations in the game. For a non-main player, use SMAPI's GetActiveLocations method instead. |
Game1.timeOfDay Game1.dayOfMonth Game1.currentSeason Game1.year |
The current time, day, season, and year. See also SMAPI's date utility. |
Game1.itemsToShip | The items in the shipping bin. |
Game1.activeClickableMenu | The modal menu being displayed. Creating an IClickableMenu subclass and assigning an instance to this field will display it. |