Links
Comment on page

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
// Mod.CanUnload(System.String@)
public virtual bool CanUnload(ref string message)
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.

// 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
// Mod.GetEmbeddedFileBytes(System.String)
public virtual byte[] GetEmbeddedFileBytes(string path)
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
// Mod.GetModInfo()
public JsonModInfo GetModInfo()
Debug.Log("Mod version: "+GetModInfo().version);

Logs a message with the mod name as a prefix.

Method
Example
// Mod.Log(System.Object)
public void Log(object message)
Log("This is a message"); // Outputs: "[ModName] This is a message".

The WorldEvent_WorldLoaded event triggers on world load complete.

Method
Example
// Mod.WorldEvent_WorldLoaded()
public virtual void WorldEvent_WorldLoaded()
public override void WorldEvent_WorldLoaded()
{
Debug.Log("The world has loaded");
}

The WorldEvent_WorldSaved event triggers on world save.

Method
Example
// Mod.WorldEvent_WorldSaved()
public virtual void WorldEvent_WorldSaved()
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
// Mod.LocalPlayerEvent_Hurt(System.Single,UnityEngine.Vector3,UnityEngine.Vector3,EntityType)
public virtual void LocalPlayerEvent_Hurt(float damage, Vector3 hitPoint, Vector3 hitNormal, EntityType damageInflictorEntityType)
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
// Mod.LocalPlayerEvent_Death(UnityEngine.Vector3)
public virtual void LocalPlayerEvent_Death(Vector3 deathPosition)
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
// Mod.LocalPlayerEvent_Respawn()
public virtual void LocalPlayerEvent_Respawn()
public override void LocalPlayerEvent_Respawn()
{
Debug.Log("Player respawned");
}

The LocalPlayerEvent_ItemCrafted event triggers when the local player crafts an item.

Method
Example
// Mod.LocalPlayerEvent_ItemCrafted(Item_Base)
public virtual void LocalPlayerEvent_ItemCrafted(Item_Base item)
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
// Mod.LocalPlayerEvent_PickupItem(PickupItem)
public virtual void LocalPlayerEvent_PickupItem(PickupItem item)
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
// Mod.LocalPlayerEvent_DropItem(ItemInstance,UnityEngine.Vector3,UnityEngine.Vector3,System.Boolean)
public virtual void LocalPlayerEvent_DropItem(ItemInstance item, Vector3 position, Vector3 direction, bool parentedToRaft)
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
// Mod.WorldEvent_OnPlayerConnected(Steamworks.CSteamID,RGD_Settings_Character)
public virtual void WorldEvent_OnPlayerConnected(CSteamID steamid, RGD_Settings_Character characterSettings)
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
// Mod.WorldEvent_OnPlayerDisconnected(Steamworks.CSteamID,DisconnectReason)
public virtual void WorldEvent_OnPlayerDisconnected(CSteamID steamid, DisconnectReason disconnectReason)
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
// Mod.WorldEvent_WorldUnloaded()
public virtual void WorldEvent_WorldUnloaded()
public override void WorldEvent_WorldUnloaded()
{
Debug.Log("World unloaded");
}

The ModEvent_OnModLoaded event triggers when a mod is loaded.

Method
Example
// Mod.ModEvent_OnModLoaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModLoaded(Mod mod)
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
// Mod.ModEvent_OnModUnloaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModUnloaded(Mod mod)
public override void ModEvent_OnModUnloaded(Mod mod)
{
Debug.Log("Mod unloaded: " + mod.name);
}