Changes

Jump to navigation Jump to search
→‎Mod entry: seal by default.
Line 8: Line 8:  
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>helper</tt> argument provides access to nearly all [[Modding:Modder Guide/APIs|SMAPI APIs]] (available as <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):
Line 23: Line 23:     
/// <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 34: Line 34:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
The <tt>Entry</tt> method is called very early in the launch process, so some things aren't initialised yet. You can use events like <tt>GameLaunched</tt>, <tt>SaveLoaded</tt>, or <tt>DayStarted</tt> to access all features. Here's a quick summary of using APIs in <tt>Entry</tt>:
+
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"
 
{| class="wikitable"
 
|-
 
|-
Line 43: Line 43:  
| ✓ 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]].
 
| ✓ 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]].
 
|-
 
|-
| <tt>helper.ModRegistry.GetApi</tt>
+
| <samp>helper.ModRegistry.GetApi</samp>
 
| ✖ Not available, since some mods aren't initialised yet.
 
| ✖ Not available, since some mods aren't initialised yet.
 
|-
 
|-
 
| Game fields
 
| Game fields
| ✖ Not reliably available, since mods are loaded early in the process. That includes core fields like <tt>Game1.objectInformation</tt>.
+
| ✖ Not reliably available, since mods are loaded early in the process. That includes core fields like <samp>Game1.objectInformation</samp>.
 
|}
 
|}
   Line 56: Line 56:  
* [https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/shared-projects Create a shared project] and reference it from your mod project. The shared project's code will be compiled as part of your mod project (so it'll be one DLL containing both projects in the mod folder).
 
* [https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/shared-projects Create a shared project] and reference it from your mod project. The shared project's code will be compiled as part of your mod project (so it'll be one DLL containing both projects in the mod folder).
 
* 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).
 +
 +
[[es:Modding:Guía del Modder/APIs/Mod structure]]
 +
[[zh:模组:制作指南/APIs/Mod structure]]
528

edits

Navigation menu