Interface IMod
- All Known Subinterfaces:
IGameInstance
Notice that, when a mod can be disabled (isDisableable()), the mod's
main method will still be initialized, but none of its initializing lifecycle
methods will be called. For this reason, you shouldn't statically initialize
any of your tiles, items or functionalities outside of the designated
initializing lifecycle methods.
For more information on how to create mods, check out the modding example and tutorial repository.
-
Method Summary
Modifier and TypeMethodDescriptiondefault String[]default StringReturns the location that content is stored in, starting in any of the root folder that are marked as source (meaning they will be at the root of the compiled mod jar).default StringgetId()default ModConfigGets an optionalModConfiginstance that you can use to save and load settings for your mod that the player will be able to change.Gets a class that can be initialized by the mods gui to open a special new gui where the mod can have its own information or settings.Returns the location that resources are stored in, starting in any of the root folders that are marked as source (meaning they will be at the root of the compiled mod jar).default intGets the priority of how to sort the mod in the list of mods, meaning this changes the order in which mods will be loaded.default voidinit(IGameInstance game, IApiHandler apiHandler, IEventHandler eventHandler) This method is called as the main initialization phase.default voidinitAssets(IGameInstance game, IAssetManager assetManager, IApiHandler apiHandler) This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind.default booleanisCompatibleWithModVersion(String version) Return something other than the default on this method if you want a client to be able to join a server (or vice versa) that has the same mod, but with a different version, installed.default booleanReturn true on this method if you want your mod to be able to be disabled from the mods menu or the mod settings file.default booleanReturn true on this method if you want the mod to be needed on the client when trying to join a server.default booleanReturn true on this method if you want the mod to be needed on the server when trying to join it.default voidpostInit(IGameInstance game, IApiHandler apiHandler, IEventHandler eventHandler) This method is called after the initialization.default voidpostInitAssets(IGameInstance game, IAssetManager assetManager, IApiHandler apiHandler) This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind.default voidpostPostInit(IGameInstance game, IApiHandler apiHandler, IEventHandler eventHandler) This method is called after post initialization.default voidpreInit(IGameInstance game, IApiHandler apiHandler, IEventHandler eventHandler) This method is called as pre initialization.default voidpreInitAssets(IGameInstance game, IAssetManager assetManager, IApiHandler apiHandler) This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind.default voidprePreInit(IGameInstance game, IApiHandler apiHandler, IEventHandler eventHandler) This method is called before pre initialization.default DataSetreceiveMessage(IMod sender, String messageIdentifier, DataSet message) This method is called when another loaded mod sends a message to this mod usingIModLoader.sendMessage(IMod, String, String, DataSet).
-
Method Details
-
getDisplayName
String getDisplayName()- Returns:
- The mod's display name. This is the name that will be displayed in the mods menu. It can contain spaces, capitalization and special characters.
-
getId
String getId()- Returns:
- The mod's unique id. It needs to be all lowercase, contain no spaces and be unique, meaning that no other mods that are currently installed are allowed to have the same id. Make sure that your mod id isn't too short or too simple, for this very reason.
-
getVersion
String getVersion()- Returns:
- The version of the mod. This doesn't follow any specific naming or versioning scheme, you can use any style you want. This will not be checked against anything or used in any way other than to display the version to the user as the provided string.
-
getResourceLocation
String getResourceLocation()Returns the location that resources are stored in, starting in any of the root folders that are marked as source (meaning they will be at the root of the compiled mod jar). The folder specified here needs to contain an assets.json file that contains information on all of the assets that need to be loaded and used during the game.For example, if your directory structure is
/assets/mymod/assets.json, then this method should returnassets/mymod, meaning there should be no leading or trailing slash.- Returns:
- The resource location
-
getContentLocation
Returns the location that content is stored in, starting in any of the root folder that are marked as source (meaning they will be at the root of the compiled mod jar). The folder specified here needs to contain a content.json file that contains ifnormation on all of the content (recipes, structures etc) that need to be loaded and used during the game.For example, if your directory structure is
/assets/content/mymod/content.json, then this method should returnassets/content/mymod, meaning there should be no leading or trailing slash.- Returns:
- The content location
-
getDescription
- Returns:
- A short description of the mod to be displayed to the user in the mods gui
-
getAuthors
- Returns:
- A list of names of the people that have worked on the mod. This list will be displayed, each entry seperated by a comma, to the user in the mods gui.
-
getSortingPriority
default int getSortingPriority()Gets the priority of how to sort the mod in the list of mods, meaning this changes the order in which mods will be loaded. The higher the priority, the sooner a mod will be loaded. For instance, if there are two installed mods likemod1with priority1000andmod2with priority2000, then the latter will be loaded first, meaning all of its initialization lifecycle methods will be called before mod1's.Note that Rock Bottom has a sorting priority of
Integer.MAX_VALUE.- Returns:
- The sorting priority
-
getModGuiClass
Gets a class that can be initialized by the mods gui to open a special new gui where the mod can have its own information or settings. This class needs to contain a constructor that takes a single Gui which acts as the parent. When this gui is initialized, it will then be passed the currently opened mods gui.- Returns:
- A gui class
-
getModConfig
Gets an optionalModConfiginstance that you can use to save and load settings for your mod that the player will be able to change. TheModConfigclass automatically picks a location for your settings to be, along with automatically loading them from disk before this mod'spreInit(IGameInstance, IApiHandler, IEventHandler)phase. If you want to change the settings in game, say, using thegetModGuiClass(), you will still have to callIJsonSettings.save()for them to be saved to file.Keep in mind that the config returned does actually have to be cached as a class variable for loading and saving to properly function.
- Returns:
- A config for the mod
-
isDisableable
default boolean isDisableable()Return true on this method if you want your mod to be able to be disabled from the mods menu or the mod settings file. Note that disabling a mod will still make its main class (the one that extends this interface) be initialized on startup, but have none of its intializiation lifecycle events be called. For that reason, you should never initialize anything statically in your mod's main class if you return true on this method, and instead always use the initialization lifecycle events.- Returns:
- If the mod should be disableable
-
isRequiredOnClient
default boolean isRequiredOnClient()Return true on this method if you want the mod to be needed on the client when trying to join a server. If this method returns false, then the mod is serverside only, meaning that players that do not have it installed on their clients can join the server without being kicked. Note that this can cause desynchronizations and crashes with mods that add tiles or items, and this setting should only be changed if a mod does not add anything that contributes to clientside behavior.- Returns:
- If the mod should be required on the client
-
isRequiredOnServer
default boolean isRequiredOnServer()Return true on this method if you want the mod to be needed on the server when trying to join it. If this method returns false, then a player that has this mod installed can join a server without the mod on it. If this mod adds tiles or items, then they will, naturally, not be available to the player on that server.- Returns:
- If the mod should be required on the server
-
isCompatibleWithModVersion
Return something other than the default on this method if you want a client to be able to join a server (or vice versa) that has the same mod, but with a different version, installed. The parameter passed to this method is the version that the client trying to join the server has installed.- Parameters:
version- The version that the client has- Returns:
- If the client version and the current version are compatible
-
receiveMessage
This method is called when another loaded mod sends a message to this mod usingIModLoader.sendMessage(IMod, String, String, DataSet). You can process any type of message in this method, and return any type of response back to the mod that originally sent the message. This way of communication can be used for several things, like registering custom content to different mods, notifying mods of certain requirements or items, and so on. Messages like this can be sent at any time. Note that sending a message to a mod that isn't installed will always yield an empty response with the message simply being discarded.- Parameters:
sender- The mod that sent the messagemessageIdentifier- A name for the message or type of message, can be nullmessage- The message data that the mod sent- Returns:
- Some reply data, or null if there should be none
-
prePreInit
This method is called before pre initialization. The base game does not initialize anything in this method.- Parameters:
game- The game instanceapiHandler- The api handler instanceeventHandler- The event handler instance
-
preInit
This method is called as pre initialization. The base game initializes the following things in this method: All threads the game uses, theSettings(orServerSettingson the dedicated server), theIAssetManagerand theIRenderer.- Parameters:
game- The game instanceapiHandler- The api handler instanceeventHandler- The event handler instance
-
init
This method is called as the main initialization phase. The base game initializes the following things in this method: TheGameContent, meaning allItem,Tile,BiomeandIEffectinstances along with allIWorldGeneratorclasses.- Parameters:
game- The game instanceapiHandler- The api handler instanceeventHandler- The event handler instance
-
postInit
This method is called after the initialization. The base game initializes the following things in this method: AllTileLayerobjects and their (final!) sorting, the loading of all of theIContentfiles from thegetContentLocation(), theIChatLog, theIGuiManager, theIInteractionManager, theIParticleManager, and lastly theIToaster.- Parameters:
game- The game instanceapiHandler- The api handler instanceeventHandler- The event handler instance
-
postPostInit
This method is called after post initialization. The base game initializes the following things in this method: The base game'sStatisticinstances and all of itsCommandinstances.- Parameters:
game- The game instanceapiHandler- The api handler instanceeventHandler- The event handler instance
-
preInitAssets
This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind. This method is called before the game'sIAssetManagerinitializes any assets, and especially before theITextureStitcherstitches the textures into one.- Parameters:
game- The game instanceassetManager- The asset manager instanceapiHandler- The api handler instance
-
initAssets
This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind. This method is called after the game'sIAssetManagerinitializes all of theIAssetinstances from thegetResourceLocation(), stitches the textures together using theITextureStitcherand also after the game loads its ownISpecialCursorobjects.- Parameters:
game- The game instanceassetManager- The asset manager instanceapiHandler- The api handler instance
-
postInitAssets
This method will not be called on the dedicated server, meaning this is the place to load and initialize assets and rendering-related operatios of any kind. This method is called after all of the assets have been initialized and finalized, especially all of the fallback assets have been initialized, but before theIAssetManagergets locked, meaning assets can still be added to it at this point.- Parameters:
game- The game instanceassetManager- The asset manager instanceapiHandler- The api handler instance
-