← README
This page helps mod authors integrate with Data Layers from their mods. See the main README for other info.
Data Layers has a mod-provided API you can use to integrate with your mods.
To access the API:
- Copy
IDataLayersApi.csinto your mod code. - In SMAPI's
GameLoop.GameLaunchedevent, get the API:var dataLayers = this.Helper.ModRegistry.GetApi<IDataLayersApi>("Pathoschild.DataLayers"); if (dataLayers is null) return; // Data Layers not installed
- Call methods on the API (see below).
After accessing the API, you can add custom data layers from the GameLaunched event:
dataLayers.RegisterLayer(id, GetName, GetTileGroups, UpdateTiles);This method takes these arguments (see below for a working example):
| argument | usage | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
id |
An ID for the layer, unique among the layers added by your mod. This doesn't need to be globally unique, since Data Layers will prepend your mod ID automatically. |
||||||||||
name |
A translated display name for your data layer, which will be shown to players in-game. |
||||||||||
getTileGroups |
A method which registers the possible tile groups when the layer is loaded. The method is called with one
|
||||||||||
updateTiles |
A method which gets the tile groups for the visible tiles while the layer is visible. This is called repeatedly while the layer is open. The method is called with four arguments:
This should return a lookup of tile positions within each group; that is, an |
||||||||||
updatesPerSecond |
(Optional) The default number of updates needed per second, or This sets the default value for the layer's configuration, so it's ignored for players who already have configuration saved for it. |
||||||||||
updateWhenViewChanges |
(Optional) Whether to update the layer by default when the player's tile view changes, regardless of the
This sets the default value for the layer's configuration, so it's ignored for players who already have configuration saved for it. |
Color arguments in the API can be specified in any of these formats:
- A semantic color name which can configured by the player:
yes(e.g. covered/ready/enabled);no(e.g. not covered/ready/enabled);- or
highlight(e.g. the range for a held object).
- A color string recognized by the game code.
Using a semantic color name is recommended where possible, so that players' color schemes are applied automatically (e.g. to support colorblind players).
For example, let's create a 'checkerboard' data layer:

To do that:
- Add an
i18n/default.jsontranslation file to store your layer's display text:{ "layer.name": "Checkerboard", "layer.even": "Even", "layer.odd": "Odd" } - Set up the
Pathoschild.Stardew.ModTranslationClassBuilderNuGet package. - Create a class for your layer logic:
/// <summary>A data layer which shows a checkerboard tile pattern.</summary> internal static class CheckerboardLayer { /// <inheritdoc cref="GetTileGroupsDelegate" /> public static void GetTileGroups(AddTileGroupDelegate addGroup) { addGroup(id: "even", name: I18n.Layer_Even, overlayColor: "yes"); addGroup(id: "odd", name: I18n.Layer_Odd, overlayColor: "no"); } /// <inheritdoc cref="UpdateTilesDelegate" /> public static ILookup<string, Vector2> UpdateTiles(GameLocation location, Rectangle visibleArea, IReadOnlySet<Vector2> visibleTiles, Vector2 cursorTile) { return visibleTiles.ToLookup(GetTileGroup); } /// <summary>Get the tile group ID for a tile position.</summary> /// <param name="tile">The tile position.</param> private static string GetTileGroup(Vector2 tile) { return (tile.X + tile.Y) % 2 == 0 ? "even" : "odd"; } }
- Access the API and register your layer:
dataLayers.RegisterLayer("checkerboard", I18n.Layer_Name, CheckerboardLayer.GetTileGroups, CheckerboardLayer.UpdateTiles);
That's it! If you launch the game and open the Data Layers UI, your new layer should appear in the list.
- README for other info
- Ask for help