模组接口

来自Thorium Mod Wiki
跳到导航 跳到搜索

Mod Calls are special functions provided by tModLoader that mod creators can use to interact with the Thorium Mod in certain ways. They are accessible through Mod.Call and a given call name; for more details, see the tModLoader wiki. This page lists the mod call functions Thorium Mod currently adds, along with examples and what they are used for.

Important Information

  • A Thorium Mod Mod.Call will never raise an exception that propagates beyond the call. If an internal exception occurs, it will be logged (client/server.log) and the call will return null.
  • Mod.Calls that have primitive return types (bool, int etc.) can still return null as mentioned above, see the examples for handling such cases.
  • Mod.Calls that have no return value will return true if the operation/s was/were successful.
  • For best results, add sortAfter = ThoriumMod into your mod's build.txt so that the calls return their true value regardless of mod update order.
    • For example, Thorium Mod updates many of its Player values in the ModPlayer.PostUpdateEquips hook. Accessing these values in hooks that run prior to this will return a possibly "outdated" value. Accessing them inside the hook will only return a guaranteed "final" value if sortAfter = ThoriumMod is added. Accessing them in a later hook (such as ModPlayer.PostUpdate) will work regardless, but may limit you otherwise.
  • Calls that have a "register" nature (such as AddMartianItemID) usually go into Mod.PostSetupContent or an appropriate SetStaticDefaults hook.

Examples

To preface, most examples will be listed like this:

if (ModLoader.TryGetMod("ThoriumMod", out Mod thoriumMod))
{
    //Example here
}

These examples will show you how to handle the different ways a call returns values.

No return

The simplest calls are those that do not return anything of direct use, but they just change a stat.

thoriumMod.Call("BonusBardInspirationMax", player, 5); //Increase the inspiration limit by 5

"No return" calls actually do return a bool with value true to indicate if the operation was successful, use it when you think you need it.

Simple return

Calls that return a value need to be handled properly to prevent crashes.

object result = thoriumMod.Call("GetHealBonus", player);
if (result is int healBonus)
{
   //healBonus now contains the player's healing bonus
   //The general pattern is: if (<return value of the call> is <return type of the call> <variable name of your choice>)
}

ValueTuple return

Some more complex calls have to return more than one value, realized through ValueTuples.

object result = thoriumMod.Call("IsBardWeapon", item);
if (result is ValueTuple<bool, byte> tuple)
{
    //tuple.Item1 is bool, representing if the given item is a bard weapon or not
    //tuple.Item2 is byte, representing its specific weapon archetype
}

1.4 Porting Notes

As of version 1.7.0.0, the mod is now using the 1.4+ versions of Terraria. tModLoader made alot of changes to help facilitate mod compatibility natively, and as such, many calls got obsolete. Below you will find all the porting notes for the calls that were removed in the update.

  • Removed AddSpearItemID, IsSpearItemID. Porting notes:
ItemID.Sets.Spears[type]
  • Removed BonusBardDamage, BonusBardDamageMult, BonusBardDamageFlat, BonusBardCrit, BonusBardSpeed, GetBardDamageMods, GetBardCrit, GetBardSpeed. Porting notes:
if (thoriumMod.TryFind("BardDamage", out DamageClass damageClass))
{
    ref StatModifier damage = ref player.GetDamage(damageClass);
    ref float speed = ref player.GetAttackSpeed(damageClass);
    ref float critChance = ref player.GetCritChance(damageClass);
}
  • Removed BonusHealerDamage, BonusHealerDamageFlat, BonusHealerCrit, GetHealerDamageMods, GetRadiantBoost, GetHealerCrit. Porting notes: Replace "BardDamage" above with "HealerDamage".
  • Removed BonusHealerSpeed, GetHealerSpeed. Porting notes: Replace "BardDamage" above with "HealerTool".
  • Removed GetAllCrit. Porting notes:
player.GetCritChance(DamageClass.Generic)
  • Removed GetZoneAquaticDepths, GetZoneMarble, GetZoneGranite. Porting notes:
//biomeName can be any one of "DepthsBiome", "MarbleBiome", and "GraniteBiome"
if (thoriumMod.TryFind(biomeName, out ModBiome biome))
{
    bool inBiome = player.InModBiome(biome);
}
  • Removed previously undocumented SetRadiantBoost, SetRadiantCrit, SetHealBonus. No porting notes.
  • Removed support for previously undocumented Player calls also accepting the whoAmI of that player. Porting notes: Replace it with the Player instance if you have it available, otherwise Main.player[whoAmI].

GetDownedBossGetDownedBoss

Returns the downed status of a Thorium Mod boss.

Parameters

  • string as the alias for the boss. Options:
    • TheGrandThunderBird
    • QueenJellyfish
    • Viscount
    • GraniteEnergyStorm
    • BuriedChampion
    • StarScouter
    • BoreanStrider
    • FallenBeholder
    • Lich
    • ForgottenOne
    • ThePrimordials
    • PatchWerk
    • CorpseBloom
    • Illusionist

Return value

  • bool representing the downed status of the boss.

GetAquaticDepthsBoundsGetAquaticDepthsBounds

Returns the tile coordinate boundaries for the 深海 generated on world creation.

Parameters

  • None.

Return value

  • Rectangle consisting of the boundary's upper-left coordinates on the world map, along with its width and height. Note the Aquatic Depths are only generated after the "Micro Biomes" vanilla step, and calling GetAquaticDepthsBounds before will return Rectangle.Empty.

GetBloodChamberBoundsGetBloodChamberBounds

Returns the tile coordinate boundaries for the 鲜血密室 generated on world creation.

Parameters

  • None.

Return value

  • Rectangle consisting of the boundary's upper-left coordinates on the world map, along with its width and height. Note the Blood Chamber is only generated after the "Micro Biomes" vanilla step, and calling GetBloodChamberBounds before will return Rectangle.Empty.

GetBloodAltarPositionGetBloodAltarPosition

Returns the world coordinates for the 鲜血祭坛 generated on world creation, which the 恐怖指针 points to.

Parameters

  • None.

Return value

  • Vector2 of the Blood Altar's coordinates on the world. Note the Blood Altar is only generated after the "Micro Biomes" vanilla step, and calling GetBloodAltarPosition before will return -Vector2.One.

BirdFeederAddFruitsToBiomeBirdFeederAddFruitsToBiome

Registers a set of custom Item types (preferably Fruits) to the 喂鸟器水果池 of the given biome. You cannot add vanilla or Thorium Mod Items to this.

Parameters

  • Two variations
    • With Condition:
      • string representing the biome[1] to associate the fruits to.
      • Condition to only reward the fruits after the condition is fullfilled.
      • int[] array of Item types.
    • Without Condition:
      • string representing the biome[1].
      • int[] array of Item types.

Return value

  • bool which is true if the addition was successful; else, it is false.

BirdFeederAddPotionsToBiomeBirdFeederAddPotionsToBiome

Registers a set of custom Item types (preferably Potions) to the 喂鸟器药水池 of the given biome. You cannot add vanilla or Thorium Mod Items to this.

Parameters

  • string representing the biome[1].
  • int[] array of Item types.

Return value

  • bool which is true if the addition was successful; else, it is false.

AddFlailProjectileIDAddFlailProjectileID

Registers a custom Projectile (preferably a thrown 连枷 projectile) to the FlailProjectileIDCache, allowing it to function with the 铁连枷核心, 咒炎连枷核心, and 邪恶连枷核心. You cannot add a vanilla or Thorium Mod Item to this.

Parameters

  • int representing the Projectile type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

IsFlailProjectileIDIsFlailProjectileID

Checks if the inputted Projectile is registered to FlailProjectileIDCache.

Parameters

  • int representing the Projectile type to check.

Return value

  • bool which is true if it is registered; else, it is false.

AddMartianItemIDAddMartianItemID

Registers a custom Item (preferably a 武器 from the 火星暴乱 事件) to the MartianItemIDCache, allowing it to benefit from 电容盔甲's damage bonus to martian weapons. You cannot add a vanilla or Thorium Mod Item to this.

Parameters

  • int representing the Item type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

IsMartianItemIDIsMartianItemID

Checks if the inputted Item is registered to MartianItemIDCache.

Parameters

  • int representing the Item type to check.

Return value

  • bool which is true if it is registered; else, it is false.

AddPlayerDoTBuffIDAddPlayerDoTBuffID

Registers a custom "damage over time" Buff to the PlayerDoTBuff cache, allowing it to be cleared by effects such as 治愈 or 解脱. You cannot add a vanilla or Thorium Mod Buff to this.

Parameters

  • int representing the Buff type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

IsPlayerDoTBuffIDIsPlayerDoTBuffID

Checks if the inputted Buff is registered to the PlayerDoTBuff cache.

Parameters

  • int representing the Buff type to check.

Return value

  • bool which is true if it is registered; else, it is false.

AddPlayerStatusBuffIDAddPlayerStatusBuffID

Registers a custom "status" Buff to the PlayerStatusBuff cache, allowing it to be cleared by effects such as 美味又扎手 or 解脱. You cannot add a vanilla or Thorium Mod Buff to this.

Parameters

  • int representing the Buff type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

IsPlayerStatusBuffIDIsPlayerStatusBuffID

Checks if the inputted Buff is registered to the PlayerStatusBuff cache.

Parameters

  • int representing the Buff type to check.

Return value

  • bool which is true if it is registered; else, it is false.

AddGemStoneTileIDAddGemStoneTileID

Registers a custom Tile to the GemStoneTiles cache, allowing it to be affected by effects such as 吸血鬼镐 or 晶体盔甲 set bonus. You cannot add a vanilla or Thorium Mod Tile to this.

Parameters

  • int representing the Tile type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

IsGemStoneTileIDIsGemStoneTileID

Checks if the inputted Tile is registered to the GemStoneTiles cache.

Parameters

  • int representing the Tile type to check.

Return value

  • bool which is true if it is registered; else, it is false.

Add[NAME]RepellentNPCIDAdd[NAME]RepellentNPCID

Registers a custom NPC to the [NAME]RepellentNPCs cache, allowing it to ignore the player when he has the respective 敌怪趋避剂 buff active. You cannot add a vanilla or Thorium Mod NPC to this.

[NAME] is a placeholder for the following: Bat, Insect, Fish, Skeleton, Zombie, meaning that the call will be i.e. AddSkeletonRepellentNPCID.

Parameters

  • int representing the NPC type to be registered to the cache.

Return value

  • bool which is true if the addition was successful; else, it is false.

Is[NAME]RepellentNPCIDIs[NAME]RepellentNPCID

Checks if the inputted NPC is registered to the [NAME]RepellentNPCs cache.

[NAME] is a placeholder for the following: Bat, Insect, Fish, Skeleton, Zombie, meaning that the call will be i.e. IsSkeletonRepellentNPCID.

Parameters

  • int representing the NPC type to check.

Return value

  • bool which is true if it is registered; else, it is false.

IsBardItemIsBardItem

Checks if the inputted Item is a 吟游诗人 item (i.e. weapon, accessory, armor, or otherwise related).

Aliases

  • IsSymphonicItem

Parameters

  • Item representing the Item to check.

Return value

  • bool which is true if it is a bard item; else, it is false.

IsBardWeaponIsBardWeapon

Checks if the inputted Item is a 吟游诗人 weapon. Expects the given item to have item.damage > 0, otherwise it won't count as a weapon.

Aliases

  • IsSymphonicWeapon

Parameters

  • Item representing the Item to check.

Return value

  • ValueTuple with the values:
    • Item1: bool which is true if it is of the BardItem type and has a damage value greater than 0; else, it is false.
    • Item2: byte representing the instrument type the BardItem belongs to [2].

IsBardProjectileIsBardProjectile

Checks if the inputted Projectile belongs to a 吟游诗人 weapon.

Aliases

  • IsSymphonicProjectile

Parameters

  • Projectile representing the Projectile to check.

Return value

  • ValueTuple with the values:
    • Item1: bool which is true if it is of the BardProjectile type; else, it is false.
    • Item2: byte representing the instrument type the BardProjectile belongs to [2].

BonusBardEmpowermentRangeBonusBardEmpowermentRange

Adds to the player's 咒音增幅范围 by a provided amount.

Parameters

  • Player that will have its empowerment range increased.
  • int value to increase the player's empowerment range by.

Return value

  • None.

BonusBardEmpowermentDurationBonusBardEmpowermentDuration

Adds to the player's 咒音增幅持续时间 by a provided amount.

Parameters

  • Player that will have its empowerment duration increased.
  • short value to increase the player's empowerment duration by (in ticks).

Return value

  • None.

BonusBardInspirationMaxBonusBardInspirationMax

Adds to the player's 最大灵感值 by a provided amount.

Parameters

  • Player that will have its maximum inspiration increased.
  • int value to increase the player's maximum inspiration by.[3]

Return value

  • None.

GetBardInspirationGetBardInspiration

Returns the player's 当前灵感值.

Parameters

  • Player to check current inspiration.

Return value

  • int representing the player's current inspiration.

GetBardInspirationMaxGetBardInspirationMax

Returns the player's 最大灵感值.

Parameters

  • Player to check maximum inspiration.

Return value

  • int representing the player's maximum inspiration.

BonusHealerHealBonusBonusHealerHealBonus

Adds to the player's 治疗加成 by a provided amount.

Parameters

  • Player that will have its bonus healing increased.
  • int value to increase the player's bonus healing amount by.

Return value

  • None.

GetHealerHealBonusGetHealerHealBonus

Returns the player's 治疗加成.

Aliases

  • GetHealBonus

Parameters

  • Player to check bonus healing.

Return value

  • int representing the player's bonus healing.

BonusLifeRecoveryBonusLifeRecovery

Adds to the player's 生命恢复 by a provided amount (i.e. +=).

Parameters

  • Player that will have its life recovery increased.
  • int value to increase the player's life recovery by.

Return value

  • None.

BonusLifeRecoveryIntervalReductionBonusLifeRecoveryIntervalReduction

Adds to the player's amount of ticks subtracted from LifeRecoveryIntervalDefault [4] to reduce the 生命恢复 interval by a provided amount (i.e. +=) [5].

Parameters

  • Player that will have its life recovery timer reduced.
  • int value to reduce the player's life recovery timer by.

Return value

  • None.

GetLifeRecoveryGetLifeRecovery

Returns the player's 生命恢复.

Parameters

  • Player to check life recovery.

Return value

  • int representing the player's life recovery.

GetLifeRecoveryIntervalGetLifeRecoveryInterval

Returns the player's 生命恢复 interval in ticks.

Parameters

  • Player to check life recovery interval.

Return value

  • int representing the player's life recovery interval in ticks.

BonusDartDamageBonusDartDamage

Adds to the player's 飞镖伤害 multiplier by a provided amount (i.e. +=).

Parameters

  • Player that will have its dart damage increased.
  • float value to increase the player's dart damage multiplier by.

Return value

  • None.

BonusMartianDamageBonusMartianDamage

Adds to the player's 火星伤害 multiplier by a provided amount (i.e. +=).

Parameters

  • Player that will have its martian damage increased.
  • float value to increase the player's martian damage multiplier by.

Return value

  • None.

History

  • 1.7.1.4: Added 2 new Mod Calls:
    • BirdFeederAddFruitsToBiome.
    • BirdFeederAddPotionsToBiome.
  • 1.7.1.0: Added 12 new Mod Calls:
    • AddGemStoneTileID.
    • IsGemStoneTileID.
    • AddBatRepellentNPCID.
    • IsBatRepellentNPCID.
    • AddInsectRepellentNPCID.
    • IsInsectRepellentNPCID.
    • AddFishRepellentNPCID.
    • IsFishRepellentNPCID.
    • AddSkeletonRepellentNPCID.
    • IsSkeletonRepellentNPCID.
    • AddZombieRepellentNPCID.
    • IsZombieRepellentNPCID.
  • 1.7.0.1: Added 1 new Mod Call: GetDownedBoss.
  • 1.7.0.0: Updated Mod.Call functions:
    • Removed AddSpearItemID, IsSpearItemID.
    • Removed BonusBardDamage, BonusBardDamageMult, BonusBardDamageFlat, BonusBardCrit, BonusBardSpeed, GetBardDamageMods, GetBardCrit, GetBardSpeed.
    • Removed BonusHealerDamage, BonusHealerDamageFlat, BonusHealerCrit, GetHealerDamageMods, GetRadiantBoost, GetHealerCrit.
    • Removed BonusHealerSpeed, GetHealerSpeed.
    • Removed GetAllCrit.
    • Removed GetZoneAquaticDepths, GetZoneMarble, GetZoneGranite.
    • Removed previously undocumented SetRadiantBoost, SetRadiantCrit, SetHealBonus.
    • Removed support for previously undocumented Player calls also accepting the whoAmI of that player.
  • 1.6.5.4: Added 4 new Mod Calls:
    • AddPlayerDoTBuffID.
    • IsPlayerDoTBuffID.
    • AddPlayerStatusBuffID.
    • IsPlayerStatusBuffID.
  • 1.6.5.3: Added 1 new Mod Call: IsBardItem.
    • All Symphonic calls now also alias as Bard (which becomes the primary name).
  • 1.6.5.0: Added 18 new Mod Calls:
    • IsSpearItemID, IsMartianItemID, IsFlailProjectileID.
    • GetAquaticDepthsBounds, GetBloodChamberBounds, GetBloodAltarPosition.
    • GetZoneAquaticDepths, GetZoneGranite, GetZoneMarble.
    • BonusLifeRecovery, BonusLifeRecoveryIntervalReduction, GetLifeRecovery, GetLifeRecoveryInterval.
    • GetAllCrit, GetBardInspiration, GetBardInspirationMax, BonusDartDamage, BonusMartianDamage.

参考

  1. 1.0 1.1 1.2 BirdFeederBiome values are as follows: "Forest", "Snow", "Evil", "Ocean", "Jungle", "Underworld", "Hallow".
  2. 2.0 2.1 BardInstrumentType values are as follows: 0 = Other (盔甲, 饰品, etc.); 1 = Wind; 2 = Brass; 3 = String; 4 = Percussion; 5 = Electronic.
  3. The resulting value is clamped between 10 and 60.
  4. 60, in ticks.
  5. Example: providing 20 to the call will reduce the interval by 20 ticks, effectively increasing the life recovery speed by 33% from the default (60).