Views
Actions
Difference between revisions of "User:SciWhiz12/sandbox/structure"
(start testing the tree list) |
(complete the conversion) |
||
Line 42: | Line 42: | ||
The <code>mods.toml</code> file is formatted in [https://toml.io/en/ Tom's Obvious Minimal Language], or TOML for short. The example <code>mods.toml</code> file in the MDK provides comments explaining the contents of the file. It should be stored under the <code>META-INF</code> folder in your resources directory (<code>src/main/resources/META-INF/mods.toml</code>). | The <code>mods.toml</code> file is formatted in [https://toml.io/en/ Tom's Obvious Minimal Language], or TOML for short. The example <code>mods.toml</code> file in the MDK provides comments explaining the contents of the file. It should be stored under the <code>META-INF</code> folder in your resources directory (<code>src/main/resources/META-INF/mods.toml</code>). | ||
+ | |||
+ | <br> | ||
<div class="mw-collapsible mw-collapsed" style="border: solid 2px; padding: 2px 5px; margin-top: 3px"> | <div class="mw-collapsible mw-collapsed" style="border: solid 2px; padding: 2px 5px; margin-top: 3px"> | ||
Line 88: | Line 90: | ||
The <code>mods.toml</code> is split into three parts: the non-mod-specific properties, which are linked to the mod file; the mod properties, with a section for each mod; and dependency configurations, with a section for each mod's dependencies. | The <code>mods.toml</code> is split into three parts: the non-mod-specific properties, which are linked to the mod file; the mod properties, with a section for each mod; and dependency configurations, with a section for each mod's dependencies. | ||
+ | === Structure === | ||
{{Tree list}} | {{Tree list}} | ||
− | * | + | * ''root of the file'' |
** <code>modLoader</code>: '''(mandatory)''' The language loader for the mod. Used to specify an alternative language for the mod, such as Kotlin, if one exists. ''The Forge-provided Java loader is <code>javafml</code>.'' | ** <code>modLoader</code>: '''(mandatory)''' The language loader for the mod. Used to specify an alternative language for the mod, such as Kotlin, if one exists. ''The Forge-provided Java loader is <code>javafml</code>.'' | ||
** <code>loaderVersion</code>: '''(mandatory)''' The acceptable version range of the language loader, expressed as a [https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html Maven version spec]. ''For the Forge-provided Java loader, the version is the major version of the Forge version.'' | ** <code>loaderVersion</code>: '''(mandatory)''' The acceptable version range of the language loader, expressed as a [https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html Maven version spec]. ''For the Forge-provided Java loader, the version is the major version of the Forge version.'' | ||
Line 99: | Line 102: | ||
** <code><nowiki>[[mods]]</nowiki></code>: An entry defining a new mod. | ** <code><nowiki>[[mods]]</nowiki></code>: An entry defining a new mod. | ||
*** <code>modId</code>: '''(mandatory)''' The mod's identifier (modid). This must match the following regex: <code><nowiki>^[a-z][a-z0-9_-]{1,63}$</nowiki></code> (starts with a lowercase letter; other characters must be a lowercase letter, number, underscore or hyphen; must be 2-64 characters long). | *** <code>modId</code>: '''(mandatory)''' The mod's identifier (modid). This must match the following regex: <code><nowiki>^[a-z][a-z0-9_-]{1,63}$</nowiki></code> (starts with a lowercase letter; other characters must be a lowercase letter, number, underscore or hyphen; must be 2-64 characters long). | ||
− | *** <code>namespace</code>: (default: value of <code>modId</code>) : An overriding namespace for the resource pack. <span class="note_info"> Currently, there is no use for this property </span> | + | *** <code>namespace</code>: (default: value of <code>modId</code>) : An overriding namespace for the resource pack. <span class="note_info"> Currently, there is no use for this property. </span> |
+ | *** <code>version</code>: (default: <code>"1"</code>) The version of the mod jar, used when the mod is a dependency of another mod, expressed as numbers which may be seperated by dots (<code>.</code>), ideally conforming to [[Semantic_Versioning|Semantic Versioning]]. ''(The default value in the MDK for this is <code>${file.jarVersion}</code>, which is replaced at runtime with the <code>Implementation-Version</code> found in the jar's manifest file.)'' | ||
+ | *** <code>displayName</code>: (default: value of <code>modId</code>) The display name of the mod, for use in the Mods listing screen | ||
+ | *** <code>description</code>: (default: <code>"MISSING DESCRIPTION"</code>) The description of the mod, for use in the Mods listing screen. It's recommended to use a multiline string (surrounded by <code>'''</code>) | ||
+ | *** <code>logoFile</code>: (default: nothing) The path of the logo file image, for use in the Mods listing screen. The image must be in the root of the jar file, not in any subfolder thereof (e.g. the file is directly in <tt>src/main/resources</tt>) | ||
+ | *** <code>logoBlur</code>: (default: <code>true</code>) Whether to do some blurring on the mod's logo in the Mods listing screen. Has no effect if <code>logoFile</code> is not set. | ||
+ | *** <code>updateJSONURL</code>: (default: nothing) The update JSON URL, used by the [Update_Checker update checker]. <span class="note_alert"> This should never be a blank string, as that will cause an error. </span> | ||
+ | *** <code>modproperties</code>: (default: <code>{}</code>) A table of custom mod properties; this is not used for Forge, but is mainly for use by mods. | ||
+ | *** <code>credits</code>: (default: nothing) Credits and acknowledgements for the mod, for use in the Mods listing screen. | ||
+ | *** <code>authors</code> (default: nothing) Authors for the mod, for use in the Mods listing screen. | ||
+ | *** <code>displayURL</code>: (default: nothing) A URL, displayed on the Mods listing screen. | ||
+ | ** <code><nowiki>[[</nowiki>dependencies.''<modid>''<nowiki>]]</nowiki></code>: A dependency entry for the mod with the given ''<modid>''. | ||
+ | *** <code>modId</code>: '''(mandatory)''' The mod id of the dependency. | ||
+ | *** <code>mandatory</code>: '''(mandatory)''' Whether to stop the game from loading if this dependency is not present and met (the version does not match the specified version). | ||
+ | *** <code>versionRange</code>: (default: <code>""</code>) The acceptable version range of the dependency, expressed as a [https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html Maven version spec]. An empty string is an unbounded version range, which matches any version. | ||
+ | *** <code>ordering</code>: (default: <code>"NONE"</code>) Defines if the mod must load before or after this dependency. The valid values are <code>BEFORE</code> (this mod must load before), <code>AFTER</code> (this mod must load after), and <code>NONE</code> (does not care). | ||
+ | *** <code>side</code>: (default: <code>"BOTH"</code>) Defines if this dependency needs only to be met on a specfic [[Sides|physical side]]. The valid values are <code>CLIENT</code> (present on the client), <code>SERVER</code> (present on the dedicated server), and <code>BOTH</code> (present on both sides). | ||
{{Tree list/end}} | {{Tree list/end}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{Colored box|title=Important|content=When specifying dependency ordering between two or more mods, beware of cyclic order!: ex. if mod A must load before mod B, and mod B must load before mod A, the game will crash because of the circular cycle.}} | {{Colored box|title=Important|content=When specifying dependency ordering between two or more mods, beware of cyclic order!: ex. if mod A must load before mod B, and mod B must load before mod A, the game will crash because of the circular cycle.}} | ||
[[Category:Getting Started]] | [[Category:Getting Started]] |
Latest revision as of 16:55, 15 December 2020
The structure of your mod is important in keeping your mod organized, for both your benefit and the benefit of anyone who wishses to make a feature for your mod. A disorganized mod structure may cause headaches when someone is trying to update it to a higher version, especially if they cannot modify the package structure, due to i.e. licensing.
Tip
Packaging
Pick a unique package name for your mod. If you own a URL associated with your project, you can use it as your top level package. For example if you own "example.com", you may use com.example
as your top level package.
The next level package is usually your mod's ID: if your mod ID is examplemod
, your mod's package will be com.example.examplemod
.
Important
me.exampledude.examplemod
).Using Subpackages
Rather than clutter up a single class and package with everything, it is recommended you break your mod into subpackages.
A common strategy is to make a subpackage for grouping classes that have a common purpose. For example, your blocks classes can be under blocks
, your entities classes can be under entities
, your helper utilities can be under helpers
, etc.
It is recommended to add a client
subpackage under your main package, to isolate your client-only code from the rest, such as your GUIs and renderers.
By keeping your code in clean subpackages, you can grow your mod much more organically.
Class Naming Schemes
A common class naming scheme allows easier deciphering of the purpose of the class, and makes it easier for someone developing for your mod to find specific classes.
The usual style is to use suffixes for your classes, for example:
- An
Item
calledPowerRing
would be in theitems
package, with a class name ofPowerRingItem
. - A
Block
calledNotDirt
would be in ablocks
package, with a class name ofNotDirtBlock
. - A
TileEntity
for a block calledSuperChewer
would be in atile
ortileentity
package, with a class name ofSuperChewerTile
.
The Mod File
The main mod class - the class that is annotated with @Mod
- is usually put into the main package of your mod, and not placed into a subpackage. This allows an easier time to access this, as your main mod class is the entrypoint of your mod.
The @Mod
annotation indicates to the mod loader that this class is the entry point of your mod. Each @Mod
annotation and their value should be paired with a mod id entry in your mods.toml
file.
The mods.toml
file
The mods.toml
file is read by the mod loader to determine what mods are packaged into your JAR file, and what information to display to the user in the Mods listing screen (accessible by pressing the "Mods" button on the main menu of the game).
The mods.toml
file is formatted in Tom's Obvious Minimal Language, or TOML for short. The example mods.toml
file in the MDK provides comments explaining the contents of the file. It should be stored under the META-INF
folder in your resources directory (src/main/resources/META-INF/mods.toml
).
mods.toml
filemodLoader="javafml" # Forge for 1.16.3 is version 34 loaderVersion="[34,)" license="All rights reserved" issueTrackerURL="github.com/MinecraftForge/MinecraftForge/issues" showAsResourcePack=false [[mods]] modId="examplemod" version="1.0.0.0" displayName="Example Mod" updateJSONURL="minecraftforge.net/versions.json" displayURL="minecraftforge.net" logoFile="logo.png" credits="I'd like to thank my mother and father." authors="Author" description=''' Lets you craft dirt into diamonds. This is a traditional mod that has existed for eons. It is ancient. The holy Notch created it. Jeb rainbowfied it. Dinnerbone made it upside down. Etc. ''' [[dependencies.examplemod]] modId="forge" mandatory=true versionRange="[34,)" ordering="NONE" side="BOTH" [[dependencies.examplemod]] modId="minecraft" mandatory=true versionRange="[1.16.3]" ordering="NONE" side="BOTH"
The default Gradle configuration replaces ${file.jarVersion}
with the project version, but only within mods.toml
, so you should use those instead of directly writing them out. Here is a table of attributes that may be given to a mod, where mandatory
means there is no default and the absence of the property causes an error.
The mods.toml
is split into three parts: the non-mod-specific properties, which are linked to the mod file; the mod properties, with a section for each mod; and dependency configurations, with a section for each mod's dependencies.
Structure
- root of the file
modLoader
: (mandatory) The language loader for the mod. Used to specify an alternative language for the mod, such as Kotlin, if one exists. The Forge-provided Java loader isjavafml
.loaderVersion
: (mandatory) The acceptable version range of the language loader, expressed as a Maven version spec. For the Forge-provided Java loader, the version is the major version of the Forge version.license
: (mandatory) The license for the mod(s) in this JAR. This string may be any valid string, but it is suggested to set the value to be the name of your license, and/or a link to that license.showAsResourcePack
: (default:false
) Whether to display this mod's resources as a separate option in the resource pack menu. If disabled, the mod's resources will be rolled into the "Mod resources" pack.properties
: (default:{}
) A table of custom substitution properties. This is used byStringSubstitutor
to replace values, using${file.*}
.issueTrackerURL
(default: nothing) A URL for an issues tracker. This should never be a blank string, as that will cause an error.[[mods]]
: An entry defining a new mod.modId
: (mandatory) The mod's identifier (modid). This must match the following regex:^[a-z][a-z0-9_-]{1,63}$
(starts with a lowercase letter; other characters must be a lowercase letter, number, underscore or hyphen; must be 2-64 characters long).namespace
: (default: value ofmodId
) : An overriding namespace for the resource pack. Currently, there is no use for this property.version
: (default:"1"
) The version of the mod jar, used when the mod is a dependency of another mod, expressed as numbers which may be seperated by dots (.
), ideally conforming to Semantic Versioning. (The default value in the MDK for this is${file.jarVersion}
, which is replaced at runtime with theImplementation-Version
found in the jar's manifest file.)displayName
: (default: value ofmodId
) The display name of the mod, for use in the Mods listing screendescription
: (default:"MISSING DESCRIPTION"
) The description of the mod, for use in the Mods listing screen. It's recommended to use a multiline string (surrounded by)
logoFile
: (default: nothing) The path of the logo file image, for use in the Mods listing screen. The image must be in the root of the jar file, not in any subfolder thereof (e.g. the file is directly in src/main/resources)logoBlur
: (default:true
) Whether to do some blurring on the mod's logo in the Mods listing screen. Has no effect iflogoFile
is not set.updateJSONURL
: (default: nothing) The update JSON URL, used by the [Update_Checker update checker]. This should never be a blank string, as that will cause an error.modproperties
: (default:{}
) A table of custom mod properties; this is not used for Forge, but is mainly for use by mods.credits
: (default: nothing) Credits and acknowledgements for the mod, for use in the Mods listing screen.authors
(default: nothing) Authors for the mod, for use in the Mods listing screen.displayURL
: (default: nothing) A URL, displayed on the Mods listing screen.
[[dependencies.<modid>]]
: A dependency entry for the mod with the given <modid>.modId
: (mandatory) The mod id of the dependency.mandatory
: (mandatory) Whether to stop the game from loading if this dependency is not present and met (the version does not match the specified version).versionRange
: (default:""
) The acceptable version range of the dependency, expressed as a Maven version spec. An empty string is an unbounded version range, which matches any version.ordering
: (default:"NONE"
) Defines if the mod must load before or after this dependency. The valid values areBEFORE
(this mod must load before),AFTER
(this mod must load after), andNONE
(does not care).side
: (default:"BOTH"
) Defines if this dependency needs only to be met on a specfic physical side. The valid values areCLIENT
(present on the client),SERVER
(present on the dedicated server), andBOTH
(present on both sides).
Important