Changes

→‎Mod entry: seal by default.
Line 1: Line 1:  
{{../../header}}
 
{{../../header}}
'''See [[Modding:Modder Guide]] for an introduction to creating a SMAPI mod. This is a technical reference page which assumes you've already followed that guide.'''
+
 
 +
'''See [[Modding:Modder Guide/Get Started|Modding:Modder Guide]] for an introduction to creating a SMAPI mod. This is a technical reference page which assumes you've already followed that guide.'''
 +
 
 
__TOC__
 
__TOC__
 +
 
==Basic structure==
 
==Basic structure==
 
A SMAPI mod must have...
 
A SMAPI mod must have...
 
# a compiled DLL file which contains the code to run as part of the mod (see [[#Mod entry|''mod entry'' below]]);
 
# a compiled DLL file which contains the code to run as part of the mod (see [[#Mod entry|''mod entry'' below]]);
# a [[Modding:Modder Guide/APIs/Manifest|<tt>manifest.json</tt> file]] which describes the mod.
+
# a [[Modding:Modder Guide/APIs/Manifest|<samp>manifest.json</samp> file]] which describes the mod.
    
It may optionally have...
 
It may optionally have...
# any number of [[#Dependencies|compiled <tt>.dll</tt> and <tt>.pdb</tt> files referenced by the main mod DLL]];
+
# any number of [[#Dependencies|compiled <samp>.dll</samp> and <samp>.pdb</samp> files referenced by the main mod DLL]];
# an [[Modding:Modder Guide/APIs/Translation|<tt>i18n</tt> folder containing translations]];
+
# an [[Modding:Modder Guide/APIs/Translation|<samp>i18n</samp> folder containing translations]];
# any number of custom files used by the mod code (usually in an <tt>assets</tt> folder by convention).
+
# any number of custom files used by the mod code (usually in an <samp>assets</samp> folder by convention).
    
==Mod entry==
 
==Mod entry==
The main mod project must have a subclass of <tt>StardewModdingAPI.Mod</tt>. The class is often named <tt>ModEntry</tt> by convention, but you can use any valid C# name. The class must implement an <tt>Entry</tt> method, which SMAPI will call once the mod is loaded. The <tt>IModHelper helper</tt> argument provides access to nearly all [[Modding:Modder Guide/APIs|SMAPI APIs]], but you can access it via <tt>this.Helper</tt> in other methods.
+
The main mod project must have a subclass of <samp>StardewModdingAPI.Mod</samp>. The class is often named <samp>ModEntry</samp> by convention, but you can use any valid C# name. The class must implement an <samp>Entry</samp> method, which SMAPI will call once the mod is loaded. The <samp>helper</samp> argument provides access to nearly all [[Modding:Modder Guide/APIs|SMAPI APIs]] (available as <samp>this.Helper</samp> in other methods).
    
Here's the minimum possible implementation (which does nothing at all):
 
Here's the minimum possible implementation (which does nothing at all):
<source lang="c#">
+
<syntaxhighlight lang="c#">
 
using StardewModdingAPI;
 
using StardewModdingAPI;
    
/// <summary>The mod entry point.</summary>
 
/// <summary>The mod entry point.</summary>
public class ModEntry : Mod
+
internal sealed class ModEntry : Mod
 
{
 
{
 
     /// <summary>The mod entry point, called after the mod is first loaded.</summary>
 
     /// <summary>The mod entry point, called after the mod is first loaded.</summary>
Line 29: Line 32:  
     }
 
     }
 
}
 
}
</source>
+
</syntaxhighlight>
   −
This is a good place to [[Modding:Modder Guide/APIs/Config|read configuration]], [[Modding:Modder Guide/APIs/Events|register event handlers]], and [[Modding:Modder Guide/APIs/Content|load mod assets]]. However the method may be called very early in the process before the game is initialised, so you should use events like <tt>GameLaunched</tt>, <tt>SaveLoaded</tt>, or <tt>DayStarted</tt> if you need initialised game data.  
+
The <samp>Entry</samp> method is called very early in the launch process, so some things aren't initialised yet. You can use events like <samp>GameLaunched</samp>, <samp>SaveLoaded</samp>, or <samp>DayStarted</samp> to access all features. Here's a quick summary of using APIs in <samp>Entry</samp>:
 +
{| class="wikitable"
 +
|-
 +
! feature
 +
! status
 +
|-
 +
| most SMAPI APIs
 +
| ✓ available. That includes [[Modding:Modder Guide/APIs/Events|registering event handlers]], [[Modding:Modder Guide/APIs/Config|reading configuration]], [[Modding:Modder Guide/APIs/Content|loading assets]], and [[Modding:Modder Guide/APIs/Integrations#Mod registry|fetching mod info]].
 +
|-
 +
| <samp>helper.ModRegistry.GetApi</samp>
 +
| ✖ Not available, since some mods aren't initialised yet.
 +
|-
 +
| Game fields
 +
| ✖ Not reliably available, since mods are loaded early in the process. That includes core fields like <samp>Game1.objectInformation</samp>.
 +
|}
    
==Dependencies==
 
==Dependencies==
Line 40: Line 57:  
* Reference projects/DLLs and copy their DLLs into your mod folder. SMAPI will detect the reference and load the DLLs from your mod folder automatically. '''Don't do this for referencing a mod''' — that can cause confusing errors when multiple versions are available (see the first option instead).
 
* Reference projects/DLLs and copy their DLLs into your mod folder. SMAPI will detect the reference and load the DLLs from your mod folder automatically. '''Don't do this for referencing a mod''' — that can cause confusing errors when multiple versions are available (see the first option instead).
   −
{{modding guide footer
+
[[es:Modding:Guía del Modder/APIs/Mod structure]]
|prev = [[Modding:Modder Guide/APIs|SMAPI reference]]
+
[[zh:模组:制作指南/APIs/Mod structure]]
|next =
  −
}}
 
528

edits