Mod The Mod class serves as the base class for all mods, containing essential information about your mod, customizable events, and more. All mods inherit from this class.
Allows mods to determine if they can be unloaded at the said moment.
Method Example
Copy // Mod.CanUnload(System.String@)
public virtual bool CanUnload ( ref string message)
Copy bool stillLoading = true ;
public override bool CanUnload ( ref string message)
{
if (stillLoading)
{
message = "The mod is still loading" ;
return false ;
}
return base. CanUnload ( ref message);
}
Unloads the mod.
Copy // Mod.UnloadMod()
public virtual void UnloadMod ()
Gets the bytes of an embedded file in the mod.
Returns the bytes of the embedded file, or null if the file doesn't exist.
Method Example
Copy // Mod.GetEmbeddedFileBytes(System.String)
public virtual byte [] GetEmbeddedFileBytes ( string path)
Copy byte [] myBundleBytes = GetEmbeddedFileBytes ( "mybundle.assets" );
AssetBundle bundle = AssetBundle . LoadFromMemory (myBundleBytes);
Gets the mod information.
Returns the mod information from the modinfo.json file.
Method Example
Copy // Mod.GetModInfo()
public JsonModInfo GetModInfo ()
Copy Debug . Log ( "Mod version: " + GetModInfo (). version );
Logs a message with the mod name as a prefix.
Method Example
Copy // Mod.Log(System.Object)
public void Log ( object message)
Copy Log ( "This is a message" ); // Outputs: "[ModName] This is a message".
The WorldEvent_WorldLoaded event triggers on world load complete.
Method Example
Copy // Mod.WorldEvent_WorldLoaded()
public virtual void WorldEvent_WorldLoaded ()
Copy public override void WorldEvent_WorldLoaded ()
{
Debug . Log ( "The world has loaded" );
}
The WorldEvent_WorldSaved event triggers on world save.
Method Example
Copy // Mod.WorldEvent_WorldSaved()
public virtual void WorldEvent_WorldSaved ()
Copy public override void WorldEvent_WorldSaved ()
{
Debug . Log ( "The world has been saved" );
}
The LocalPlayerEvent_Hurt event triggers when the local player takes damage.
Method Example
Copy // Mod.LocalPlayerEvent_Hurt(System.Single,UnityEngine.Vector3,UnityEngine.Vector3,EntityType)
public virtual void LocalPlayerEvent_Hurt(float damage, Vector3 hitPoint, Vector3 hitNormal, EntityType damageInflictorEntityType)
Copy public override void LocalPlayerEvent_Hurt(float damage, Vector3 hitPoint, Vector3 hitNormal, EntityType damageInflictorEntityType)
{
Debug . Log ( "Player hurt: " + damage + " damage taken" );
}
The LocalPlayerEvent_Death event triggers when the local player dies.
Method Example
Copy // Mod.LocalPlayerEvent_Death(UnityEngine.Vector3)
public virtual void LocalPlayerEvent_Death ( Vector3 deathPosition)
Copy public override void LocalPlayerEvent_Death ( Vector3 deathPosition)
{
Debug . Log ( "Player died at: " + deathPosition);
}
The LocalPlayerEvent_Respawn event triggers when the local player respawns.
Method Example
Copy // Mod.LocalPlayerEvent_Respawn()
public virtual void LocalPlayerEvent_Respawn ()
Copy public override void LocalPlayerEvent_Respawn ()
{
Debug . Log ( "Player respawned" );
}
The LocalPlayerEvent_ItemCrafted event triggers when the local player crafts an item.
Method Example
Copy // Mod.LocalPlayerEvent_ItemCrafted(Item_Base)
public virtual void LocalPlayerEvent_ItemCrafted ( Item_Base item)
Copy public override void LocalPlayerEvent_ItemCrafted ( Item_Base item)
{
Debug . Log ( "Item crafted: " + item . UniqueName );
}
The LocalPlayerEvent_PickupItem event triggers when the local player picks up a dropped item.
Method Example
Copy // Mod.LocalPlayerEvent_PickupItem(PickupItem)
public virtual void LocalPlayerEvent_PickupItem ( PickupItem item)
Copy public override void LocalPlayerEvent_PickupItem ( PickupItem item)
{
Debug . Log ( "Picked up item: " + item . itemInstance ? . UniqueName );
}
The LocalPlayerEvent_DropItem event triggers when the local player drops an item.
Method Example
Copy // Mod.LocalPlayerEvent_DropItem(ItemInstance,UnityEngine.Vector3,UnityEngine.Vector3,System.Boolean)
public virtual void LocalPlayerEvent_DropItem(ItemInstance item, Vector3 position, Vector3 direction, bool parentedToRaft)
Copy public override void LocalPlayerEvent_DropItem(ItemInstance item, Vector3 position, Vector3 direction, bool parentedToRaft)
{
Debug . Log ( "Dropped item: " + item . UniqueName + " at position: " + position);
}
The WorldEvent_OnPlayerConnected event triggers when a player connects to the world.
Method Example
Copy // Mod.WorldEvent_OnPlayerConnected(Steamworks.CSteamID,RGD_Settings_Character)
public virtual void WorldEvent_OnPlayerConnected ( CSteamID steamid , RGD_Settings_Character characterSettings)
Copy public override void WorldEvent_OnPlayerConnected ( CSteamID steamid , RGD_Settings_Character characterSettings)
{
Debug . Log ( "Player connected: " + steamid);
}
The WorldEvent_OnPlayerDisconnected event triggers when a player disconnects from the world.
Method Example
Copy // Mod.WorldEvent_OnPlayerDisconnected(Steamworks.CSteamID,DisconnectReason)
public virtual void WorldEvent_OnPlayerDisconnected ( CSteamID steamid , DisconnectReason disconnectReason)
Copy public override void WorldEvent_OnPlayerDisconnected ( CSteamID steamid , DisconnectReason disconnectReason)
{
Debug . Log ( "Player disconnected: " + steamid + " Reason: " + disconnectReason);
}
The WorldEvent_WorldUnloaded event triggers on world unload.
Method Example
Copy // Mod.WorldEvent_WorldUnloaded()
public virtual void WorldEvent_WorldUnloaded ()
Copy public override void WorldEvent_WorldUnloaded ()
{
Debug . Log ( "World unloaded" );
}
The ModEvent_OnModLoaded event triggers when a mod is loaded.
Method Example
Copy // Mod.ModEvent_OnModLoaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModLoaded ( Mod mod)
Copy public override void ModEvent_OnModLoaded ( Mod mod)
{
Debug . Log ( "Mod loaded: " + mod . name );
}
The ModEvent_OnModUnloaded event triggers when a mod is unloaded.
Method Example
Copy // Mod.ModEvent_OnModUnloaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModUnloaded ( Mod mod)
Copy public override void ModEvent_OnModUnloaded ( Mod mod)
{
Debug . Log ( "Mod unloaded: " + mod . name );
}