Wikia

Surfpup's tConfig Mod Wiki

TConfig Classes

Comments74
122pages on
this wiki
TConfig Classes
tConfig allows you to write code which is called on within various parts of the game. Here's a list of all of the methods that you can create for each class.

This is being updated for the new version of tConfig. Anything that is crossed out has not been implemented.

The following updated to tConfig v0.35.1

ModWorld NetworkingEdit

Defined in 'Global\World.cs':

  • void NetReceive(int msg, BinaryReader reader) - Called when a net message is received for this ModWorld class.
  • void NetSend(int msg, BinaryWriter writer) - Called when a net message needs to be sent
  • void PlayerConnected(int playerID) - Called on the server when a player connects
  • void SyncPlayers() - Called on the server when a player joins, and periodically afterwards
  • void NetReceiveIntercept(messageBuffer msgBuffer, int b, int start, int length, ref int num)
  • void NetSendIntercept(int num, ref int num2, ref int num3, int msgType, int remoteClient, int ignoreClient, string text, int number, float number2, float number3, float number4, int number5)

To send a message with NetSend, you would call NetMessage.SendData with 100 as the msgType, and the modIndex & your own message ID passed as parameters.

Another way to send a message, much more easily, is using the new NetMessage.SendModData() method. You can pass in basic data types and it will automatically write them into the networking stream appropriately. The method signature is:

void SendModData(int modIndex, int msgID, int remoteClient = -1, int ignoreClient = -1, params object[] parameters)


The Deathmatch PVP mod available here is a great example of using these networking capabilities.

Global ClassesEdit

ModWorld and ModPlayer classes are defined in 'Global\World.cs' and 'Global\Player.cs' respectively.

  • void Save(BinaryWriter writer) - Save data to the player or world.
  • void Load(BinaryReader reader, int version) - Load data associated with the player or world.
  • void Initialize(int modIndex) - Called when the world or player is loaded. It is HIGHLY recommended that you write this method for resetting variables. If you don't, then switching to a different world or player could result in unexpected behavior. The modIndex value is required for networking purposes.

ModWorldEdit

Defined in 'Global\World.cs'.

  • Interface Related
    • void PostDraw(SpriteBatch SP) - Called every tick, after the default drawing method
    • void PreDrawInterface(SpriteBatch SP) - called before interface is drawn
    • public void PreDrawTiles(SpriteBatch SP,bool solidOnly)
    • public void PostDrawTiles(SpriteBatch SP,bool solidOnly)
    • public void PreLightTiles(SpriteBatch SP)
    • public void PostLightTiles(SpriteBatch SP)
    • public bool PreDrawLifeHearts(SpriteBatch SP) - return true to draw player's life hearts regularly , false to skip
    • public bool PreDrawManaStars(SpriteBatch SP) - return true to draw player's mana stars regularly , false to skip
    • public bool PreDrawBubbleBar(SpriteBatch SP) - return true to draw player's bubbles bar regularly , false to skip
    • public bool PreDrawBuffsList(SpriteBatch SP) - return true to draw player's buff icons regularly , false to skip
    • public bool PreDrawTrashItem(SpriteBatch SP) - return true to draw trash slot regularly , false to skip
    • public bool PreDrawInventoryTitle(SpriteBatch SP) - return true to draw "inventory" on top of the inventory , false to skip
    • public bool PreDrawInventorySlots(SpriteBatch SP) - return true to draw the player's inventory , false to skip
    • public bool PreDrawHotbarLock(SpriteBatch SP) - return true to draw the lock on the left of the quickbar normally , false to skip
    • public bool PreDrawNPCHouseToggle(SpriteBatch SP) - return true to draw the house icon which switches to the NPC housing normally , false to skip
    • public bool PreDrawNPCHousingMenu(SpriteBatch SP) - return true to draw housable NPCs in list normally , false to skip
    • public bool PreDrawPlayerEquipment(SpriteBatch SP) - return true to draw player equipment item slots , false to skip
    • public bool PreDrawAvailableRecipes(SpriteBatch SP) - return true to draw recipes list normally, false to skip
    • public bool PreDrawInventoryCoins(SpriteBatch SP) - return true to draw the coin slots normally , false to skip
    • public bool PreDrawInventoryAmmo(SpriteBatch SP) - return true to draw the ammo slots normally , false to skip
    • public bool PreDrawNPCShop(SpriteBatch SP) - return true to draw an NPC's shop normally , false to skip
    • public bool PreDrawChestButtons(SpriteBatch SP) - return true to draw the quick buttons on the side of a chest in a chest menu normally , false to skip
    • public bool PreDrawChestSlots(SpriteBatch SP) - return true to draw chest slots of a chest normally , false to skip
    • public bool PreDrawInformationTexts(SpriteBatch SP) - return true to draw informative texts such as the ones of a clock or a GPS item normally , false to skip
    • public bool PreDrawEscapeButtons(SpriteBatch SP) - ...
    • public bool PreDrawHotbarInventory(SpriteBatch SP) - return true to draw the hotbar out of inventory normally , false to skip
    • public bool PreDrawDeathText(SpriteBatch SP) - return true to draw "You were Slain..." on screen normally , false to skip
    • public bool PreDrawLifeText(SpriteBatch SP) - return true to draw life text mouseover for health when putting mouse on hearts , false to skip
    • public bool PreDrawManaText(SpriteBatch SP) - return true to draw mana text mouseover for mana when putting mouse on stars , false to skip
    • public void PreDrawWalls(SpriteBatch SP) - drawn before walls
    • public void PostDrawWalls(SpriteBatch SP) -drawn after walls
    • public void PreDrawWater(SpriteBatch SP, bool background) - called before draw water
    • public void PostDrawWater(SpriteBatch SP,bool background) - called after draw water
    • public void PreDrawBackground(SpriteBatch SP) - called before drawing background (even sky)
    • public void PostDrawBackground(SpriteBatch SP) - called after drawing background (for whatever reason)
    • public void PreDrawTiles(SpriteBatch SP) - called before tiles are to be drawn
    • public void PostDrawTiles(SpriteBatch SP) - called after all tiles are drawn
    • public void PreDrawItemInSlot(SpriteBatch SP,Color SlotColor,Item I,Vector2 Pos,float ItemScale, ref bool LetDraw) - used to register ItemSlotRender layers
    • public void PostDrawItemInSlot(SpriteBatch SP,Color SlotColor,Item I,Vector2 Pos,float ItemScale,bool DidDraw) - used to register ItemSlotRender layers
  • bool PreHitWire(int x, int y) - called when HitWire() is called. Return true to execute normal hitwire function, false otherwise.
  • void OnSetup() - called right before the RegisterOnScreenInterfaces hook, used for adding listeners for a portion of tConfig's hooks [not recommend to beginner]
  • void UpdateWorld() - Called every tick at the end of default UpdateWorld, before custom tile update
  • void PreUpdate(GameTime gametime) - first thing called on the game's Update method , added as per request
  • void PostUpdate()  - called after GAME update, right before Draw
  • Vector2 TileCollision(Vector2 Result,Vector2 Position,Vector2 Velocity,int Width,int Height,bool fallThrough,bool fall2) - return Result to not override the original TileCollision method, otherwise return anything else
  • void CraftItem(Recipe R,Item I,bool NewStack) - called whenever an item is crafted and lets you run code on it on the moment of crafting (example purpose would be logging if you crafted it by yourself or not , or engrave your name into it)
  • int OverrideItemRemove() - return 0-199 for choosing the item to replace when the world contains too many items, return anything else if you removed items from the world manually and want to let tConfig find the first available free slot

ModPlayerEdit

  • Defined in 'Global\Player.cs'.
  • void UpdatePlayer(Player player) - Called every 'tick'
  • void CreatePlayer(Player player) - Called when a Player instance is created. This is where it sets the player's default starting items.
  • void PreUpdatePlayer(Player player) - Called every 'tick', before the effects from items and buffs are applied.
  • public bool PreQuickHeal(Player P) - Return true to call regular QuickHeal , false otherwise
  • public bool PreQuickMana(Player P) - Return true to call regular QuickMana , false otherwise
  • public bool PreQuickGrapple(Player P) - Return true to call regular QuickGrapple , false otherwise
  • public bool PreKill(Player P,double Damage,int hitDirection,bool pvp,string deathText) - Return true to let player die normally , false otherwise (can be used to make second-chance items , or some special death event related ones)
  • public void PostKill(Player P,double Damage,int hitDirection,bool pvp,string deathText) - Called after a player has died.
  • void BeforeHurt(Player P,ref bool LetHurt,ref bool PlaySound,ref bool GenGore,ref int TheDamage,ref int HitDirection,bool pvp,bool quiet,ref string DeathText,ref bool Crit,ref float CritMultiplier)
    • You can set LetHurt to false to stop Hurt from running the method after your code
    • You can set PlaySound to false to avoid player sound on being hurt
    • You can set GenGore to stop player from emitting blood on hit
    • tip : you can check the deathtext to try and understand what is the current damage source
  • public void AfterHurt(Player P,ref double ParsedDamage,int hitDirection,bool pvp,bool quiet,string deathtext,bool Crit,float CritMultiplier) - lets you control what the Hurt method outputs
  • public void ModifyPlayerDrawColors(Player P,bool OverrideFire,ref float r,ref float g,ref float b,ref float a) - This one allows you to change the color multipliers of a player. Note that all values start at 1f. overrideFire is false by default, if you set it to true your changes will occur even if the player is on fire (where usually it would just set everything back to 1 again). Examples include players poisoned have the red and blue scales lowered a bit.
  • public bool OverrideWingDraw(Player P,SpriteBatch SP) - return true to still draw normal wings, and false otherwise. Will be called before the original wing draw
  • public void DrawBeforeWings(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Armor)
  • public void DrawAfterWings(Player P,SpriteBatch SP,ref Color Armor)
  • public void DrawBeforeSkin(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Skin)
  • public void DrawAfterSkin(Player P,SpriteBatch SP,ref Color Skin)
  • public void DrawBeforeBody(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Skin,ref Color Undershirt,ref Color Shirt,ref Color Armor)
  • public void DrawAfterBody(Player P,SpriteBatch SP,ref Color Skin,ref Color Undershirt,ref Color Shirt,ref Color Armor)
  • public void DrawBeforeLegs(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Legs,ref Color Shoes,ref Color Grieves)
  • public void DrawAfterLegs(Player P,SpriteBatch SP,ref Color Legs,ref Color Shoes,ref Color Grieves)
  • public void DrawBeforeHead(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Skin,ref Color EyeWhite,ref Color Eye,ref Color Hair,ref Color Helm)
  • public void DrawAfterHead(Player P,SpriteBatch SP,ref Color Skin,ref Color EyeWhite,ref Color Eye,ref Color Hair,ref Color Helm)
  • public void DrawBeforeShooting(Player P,SpriteBatch SP,ref int shootOff,Vector2 ShootCenter)
  • public void DrawBeforeArms(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Skin,ref Color Undershirt,ref Color Shirt,ref Color Armor)
  • public void DrawAfterArms(Player P,SpriteBatch SP,ref Color Skin,ref Color Undershirt,ref Color Shirt,ref Color Armor)
  • public void DrawBeforeWeapon(Player P,SpriteBatch SP,ref bool LetDraw,ref Color Weapon)
  • public void DrawAfterWeapon(Player P,SpriteBatch SP,ref Color Weapon)
  • public void AdjTile(Player P) - used to let players modify the adjTiles array every frame (used from modplayer and can be called from items , too!)
  • public void PreQuickBuff(Player P) - as per the will from the modders around the forum
  • public bool HeldItemEffects(Player P) - Called on items the player has equipped, buffs, and the held item and the player itself , return false to negate held vanilla item effects such as candle lights or torch lights

Useful method calls or variables:

  • int player.HasBuff(string buffname) - returns the buff index of the wished buff or -1 if not found

Notes:

  • These methods are called between every draw part , note that the order they are listed here is the chronological order in which they're called.
  • Color params are used to modify the colors of the drawn materials (essentially letting you draw colored armors *cough cough*)
  • on DrawBeforeShooting , note that it only applies to items of useStyle 5 , and will allow you to modify the position in which you hold them (for those requested machineguns / sniper rifles / shotguns / WHATEVER)
  • All of DrawBefore/DrawAfter can be called from the player himself , his equipped armor , and buffs.

tConfig Custom PropertiesEdit

Name Type

Description

baseGravity float Base gravity effect to apply to player
maxGravity float Maximum gravity effect to player (probably allows faster max falling speed, more fall damage)
baseSpeed float Base player speed with no buffs
baseSpeedAcceleration float Base player acceleration with no buffs
baseSlideFactor float
baseMaxSpeed float
MaximumMaxSpeed float

ModGenericEdit

  • Defined in Global\Generic.cs
  • void OnLoad() - Called after mods and content are loaded. Can be useful for loading texture packs.
  • void OnUnload() - useful for unloading content if you like to keep things super clean
  • void UpdateSpawn(Player P) - Global method for changing spawn rates and various things. You can access variables such as NPC.spawnRate and NPC.maxSpawns.
  • void ModifySpawnList(List<int> PossibleSpawns) - modify the said list to change what can be rolled for spawning
  • void ServerCommand(string text) - you can use it to add server commands by reading the text on them , the method is called before the actual regular text parsing and does not stop it
  • void checkXMas() - the regular method is skipped if such method is found
  • bool ItemMouseText(SpriteBatch SP,string cursorText,int rare,byte diff,string[] arr,bool[] arr2,bool[] arr3) - allows changing item tooltip texts entirely, return true to draw the normal text or false to skip it and draw your own stuff
  • bool OverrideMenuSelection(int previousFocus,int choicesAmt,Main main) - Return true to override menu choice handling , false to run this code along normal choices
  • void PostDrawMenu(Main main,SpriteBatch SP) - draw things over the menu and even make your own menu
  • void LoadCustomRecipes()
  • void OnRecipeRefresh()
  • Does not have initialize/save/load methods

InterfacesEdit

Interfaces are defined through a class called InterfaceObj. It can include item slots and text-based buttons. Call-back methods are defined using an interface called Interfaceable.

InterfaceableEdit

  • bool DropSlot(int slotNum) - Called when the interface is closed - return true if you want the item in the slot to be dropped, false otherwise
  • void ButtonClicked(int buttonNum) - Perform an action when the specified button is clicked on. This will be called if the button is defined to be clickable.
  • bool CanPlaceSlot(int slotNum, Item mouseItem) - return true if you want to let the player place / pick up an item in the specified slot. mouseItem is the item currently held by the mouse.
  • void PlaceSlot(int slotNum) - Perform some action after an item has been placed or taken from the specified slot
  • void PostDraw(SpriteBatch SP) - called after the interface is drawn
  • void PostDrawSlot(SpriteBatch SP, int slot) - called after the slot is drawn

Not part of the interface, but called reflectively (so it is optional):

  • void SlotRightClicked(int slot) - overrides the behavior of right clicking an item slot

Creating an InterfaceEdit

To actually build the interface itself, you must spawn an instance of the InterfaceObj class. For NPCs, you set Config.npcInterface to the InterfaceObj object. The InterfaceObj class consists of these methods:

  • Constructor: public InterfaceObj(Interfaceable item, int slotCount, int buttonCount) - The constructor takes the Interfaceable object that handles callbacks, and integers for allocating space.
  • void SetLocation(Vector2 vect) - Used for Tiles - set the location of the tile here, so it knows to close the interface when you move a certain distance away.
  • int AddText(string text, int x, int y, bool clickable,float scale=1f) - Add a text button to the screen at the specified location. If clickable is true, it will call the ButtonClicked() method in the interfaceable object.
  • int AddItemSlot(int x, int y) - Adds an item slot to the specified location.

Example (in the Examples mod):

Config.npcInterface = new InterfaceObj(new EnchantInterface(), 3, 3); //Pass along this code instance, and the # of item slots you want to use
Config.npcInterface.AddItemSlot(150,250);
Config.npcInterface.AddItemSlot(230,250);
Config.npcInterface.AddItemSlot(190,300);
Config.npcInterface.AddText("Enchant:", 130, 230, false, 0.9f);
Config.npcInterface.AddText("Rune:", 225, 230, false, 0.9f);
Config.npcInterface.AddText("Result:", 140, 310, false,0.9f);

ItemEdit

For everything:

  • void Initialize()
  • void Save(BinaryWriter writer) - Saves data, for either the world or the player. Also used to transfer data in multiplayer.
  • void Load(BinaryReader reader, int version) - Loads data for the world or the player. Also used to transfer data in multiplayer.
  • void PlayerGrab(Player player, int playerID, int itemIndex) - Called when the item collides with the player. This is where health or mana crystals give the player health/mana, and normal items go into the player's inventory. Defining this method will override the default behavior for normal items. The itemIndex is the index into the Main.item[] array.
  • public bool OverrideItemGrab(Player P,int PlayerID,int ItemIndex) - return false to call normal grabbing , otherwise true
  • public bool OverrideItemVacuum(Player P,int PlayerID,int ItemIndex) - return true to let the item be vacuumed even if you don't have enough space in inventory (should be used with ItemGrab or overrideItemGrab)
  • public bool UpdateItem(int itemindex,ref bool LetUpdate,ref int MovementType,ref int LavaImmunity)
    • you can change LetUpdate to false in order to make the item not update naturally
    • you can assign the item movementType 0 (default) to make it act normally , 1 for floating movement type like soul items , anything else to make neither of those run
    • you can assign lavaImmunity to a value smaller then 0 to make the item always perish in lava , or a value higher then 0 to never perish in lava (0 is default case where only rare items don't perish in lava)
  • public void PreDrawItem(SpriteBatch SP,Item I,Color DrawAlpha,ref float Scale) - can be used to make item draw in special ways , such as extremely big small / changing size per frame (again , can be used to make a soul without a pretendType)
  • public bool PreShoot(Player P,Vector2 ShootPos,Vector2 ShootVelocity,int projType,int Damage,float knockback,int owner) - mystical magical method to make all your life easier , return true to let custom item shoot normally , false otherwise
  • public bool InvRightClicked(Player P, int playerID, int slot)
  • MouseTip[] UpdateTooltip() - Return a string array of new lines of text to add to the tooltip
  • void PostPrefix(int prefixID) - Called right after an item has its prefix set
  • bool OverridePrefix(int prefixID) - Specifying this method will override prefix behavior entirely
  • CustomProjectile SpawnProjectile(Projectile p) - Return a CustomProjectile class, whose methods will be registered to the projectile
  • void RegisterProjectile(Projectile p) - Allows you to manually register delegates to the projectile if you wish to do so
  • void ModifyPrefixList(WeightedRandom<int> validPrefixes) - allowing you to control the list of which prefixes can be given to your item

For usable items (consumables, weapons):

  • void UseItem(Player player, int playerID) - Important Note: UseItem is not called if a projectile is fired by ini paramaters.
  • bool CanUse(Player player, int playerID) - Return True if the item can be used, false otherwise. This opens up more possibilities, and is needed for things like boomerangs that have a limit to the amount that can be thrown.

For weapons

  • void UseItemEffect(Player player, Rectangle rectangle)
    • Used to create a visual effect, such as fire particles on a flame sword
  • bool UseAmmo(Player P,bool CurrentState,Item Counter) - return true if you want it to use ammo, false otherwise. You could easily make a weapon not use ammo 33% of the time or not use ammo under certain conditions.
    • It is now called on both the ammo that is being used for shooting, and the item that shoots it.
    • The ammo method gets called first , then the shooting item's method.
    • P is the shooting player
    • CurrentState is the current status of using ammo (return it to leave unchanged)
    • If the method is called from an item that shoots ammo, Counter is the ammo item
    • if the method is called from an ammo item, Counter is the shooting item
  • void AffixName(ref string itemname,bool AfterPrefixing) - Allows you to modify the name of the item for display purposes, called twice per name getting, once before prefixing of the item and once after the prefixing of the item

For Equipable ites:

  • void Effects(Player player) - Used to add passive effects that are active while the item is equipped
  • bool CanEquip(Player P, int slot) - return true to allow the player to equip an item , false otherwise
  • void OnEquip(Player P, int slot) - runs on the moment you equip the item
  • void OnUnequip(Player P, int slot) - runs on the moment you unequip the item

For Accessories:

  • bool AccCheck(Player P,slot i) - allows to override the '1 accessory of same kind' rule , return true to allow equipping the accessory in the slot i(3,4,5,6,7) , or false otherwise

For Armor:

  • void SetBonus(Player player) - Define effects that are only active while all armor pieces from a set are equipped
  • void PlayerFrame(Player player) - Define visual effects for set bonuses
  • void VanityEffects(Player P) - same as Effects, only runs on the items in your vanityslot

For weapons, armor/accessories, buffs, and ModPlayer:

  • void DamageNPC(Player myPlayer,NPC npc, ref int damage, ref float knockback)
    • Called when an NPC is hit with the weapon. You can add buff effects here, or alter the damage and knockback. You can also use it to spawn items.
  • void DealtNPC(Player myPlayer, NPC npc, double damage)
    • Called after you damage an enemy, it lets you see how much damage was dealt and perform some action.
  • void DealtPlayer(Player myPlayer, double damage, NPC npc) - Called after the player takes damage from an NPC
  • DamagePVP(Player myPlayer, ref int damage, Player enemyPlayer) - PvP method that allows you to intercept the damage taken and modify it in some way.
  • DealtPVP(Player myPlayer, int damage, Player enemyPlayer) - PvP method that allows you to react to the total damage dealt to the enemy player.
  • void OnSpawn(Player player, int id) - called when the player respawns.
  • void FrameEffect(Player player) - Similar to the PlayerFrame() method, but it gets called for all items, buffs, etc and doesn't care about set bonuses.
  • void PreDraw(Player P, SpriteBatch SP,ref bool LetDraw) - Called before DrawPlayer; set LetDraw to true to let it continue with DrawPlayer(), false otherwise.
  • void PostDraw(Player player, SpriteBatch spriteBatch) - called after DrawPlayer
  • void RocketFrame(Player P,ref bool LetRocket,ref bool EmitDust)
    • LetRocket (default true) can be set to false to remove all the handling of rocket boots velocity changes and dust stuff
    • EmitDust (default true) can be set to false to make the player not emit dust when using rocket boots of any kind
  • public void DirectionalMovement(Player P,ref bool LetRun,ref bool EmitDust,ref bool PlaySound)
    • LetRun (default true) can be set to false to remove all the handling of horizontal movement
    • EmitDust (default true) can be set to false to remove any dust emitted by things such as hermes boots when moving fast
    • PlaySound (default true) can be set to false to remove any stepping sound when running fast
  • public void CheckJump(Player P,ref bool LetJump,ref bool EmitDust,ref bool PlaySound)
    • LetJump (default true) can be set to false to remove all the handling of the jump key control
    • EmitDust (default true) can be set to false to remove any dust emitted by cloud in a bottle like effects
    • PlaySound (default true) can be set to false to remove any jump related sound
  • bool CanHitboxDamageNPC(Player P,Rectangle Hitbox,NPC N) - called on npcs that are in the player's weapon hitbox, return true to hit the npc , false otherwise (can be used in the creation of melee weapons that hit through walls, for example)
  • bool CanHitboxDamagePlayer(Player P,Rectangle Hitbox,Player P2) - called on players that are in the player's weapon hitbox in pvp, return true to hit the enemy player, false otherwise (can be used in the creation of melee weapons that hit through walls, for example)

Useful method calls or variables:

  • Item Config.itemDefs.byName["Item Name"] - get the custom Item object by name
  • bool HasItem(int netID,int stack =-1) - returns true if the player has the item , if stack is not -1 it will check if the player has at least the stack amount specified of the item. E.g. somePlayer.HasItem(8,3) would return true if the player has at least 3 torches
  • bool HasItem(string name,int stack =-1) - same as bool HasItem(int netID,int stack =-1), but using name

Notes:

  • The 'MouseTip' class used for adding tooltips to prefixes and in the UpdateTooltip() method. If 'colored' is true, it will appear green, and if colored AND red is true, it will appear red. Here's the simple class in its entirety:
   public class MouseTip
   {
       public string text;
       public bool colored;
       public bool red;
       public MouseTip(string text, bool colored = true, bool red = false)
       {
           this.text = text;
           this.colored = colored;
           this.red = red;
       }
   }

tConfig Custom Properties Edit

Name Type Description
displayName string Set the item's displayname, which can be different from the .ini file name
pretendType int The ID value for an item you want it to act like. Affects items when they're on the ground or on the screen.
prefixType int The ID value for an item - Gives your item prefix capabilities of the specified item.
useSound string The name of a custom sound effect.
drawHair int Set it to 1 to make it draw hair on top of the head texture. Set to 2 to make hair be drawn underneath.
drawHairAlt bool Set to True to draw the alternate hair for the player's hairstyle

createTileName

string The name of a custom tile that the item will place when used.

hasHands

boolean For body armor, set to True if your sprite includes hands.

hasArms

boolean For body armor, set to True if your sprite includes arms.
texture string Make one ini use another's texture, the texture must be of the same group
[Recipe] can also use [Recipe2],[Recipe3] and so on to make multiple recipe
Amount int The amount of items craft once
needWater bool Set to True will require standing near water when crafting
needLava bool Set to True will require standing near lava when crafting
Items string Material required, e.g. "1 Torch,2 Steel Chain" means need one torch and 2 steel chain
Tiles string Require standing near a specific tile when crafting, e.g. "Anvil" will force player to craft the recipe near a Anvil

PrefixEdit

In Global code file (Prefix.cs):

  • List<Prefix> DefinePrefixes()

Useful method calls or variables:

  • Prefix SetWeight(double weight) - set the weight of a prefix, return the prefix itself

Notes:

  • If a prefix isn't loaded, the item will get the "Mysterious" prefix, and should regain the original prefix if the prefix's mod is reloaded

tConfig Custom Properties Edit

Name Type Description
[Stats]
name string Name is required, this is what gets added to the item name
suffix bool Set suffix to True to make the name appear after the item name
weight double Chance to get the prefix
[Requirements]
melee bool Requirement of the prefix, set to true to apply to melee weapon
ranged bool Requirement of the prefix, set to true to apply to ranged weapon

magic

bool Requirement of the prefix, set to true to apply to magic weapon

accessory

bool Requirement of the prefix, set to true to apply to accessory
[Item]

manaCost

float multiplier to mana cost, e.g. 0.7 is decrease mana cast by 30%
damage float multiplier to weapon damage, e.g. 1.5 is increase damage by 50%
scale float multiplier to weapon scale
knockback float multiplier to weapon knockback
shootSpeed float multiplier to gun velocity
speed float multiplier to weapon speed
defense int increase item defense
crit int add to weapon critical chance, e.g. 2 is adding 2% critical chance to the item
[Player]
defense int increase player defense
crit int increase player total critical chance
mana int increase player max mana
damage float increase player damage, e.g. 5.5 is adding 5.5 damage to all weapon
moveSpeed float increase player move speed
meleeSpeed float increase player melee speed

NPCEdit

  • void Initialize()
  • void FindFrame(int currentFrame) - Handle custom animations here
  • void AI() - Handle AI
  • bool PreAI() - Called before AI(); return false if you don't want it to run the normal AI routine
  • void PostAI() - called after AI()
  • bool SpawnNPC(int x, int y, int playerID) - return true if you want the NPC to spawn.
  • void SetupShop(Chest chest) - Handle shop items for your Town NPC
  • string Chat() - Return the line of text you want the NPC to say
  • bool TownSpawn() - return true if you want the NPC to spawn as a Town NPC
  • void NPCLoot() - Handle death events and drop items
  • string SetName() - Required method to set the name of your Town NPC.
  • void DealtNPC(double damage, Player player) - Called after the NPC takes damage from a player or a player's projectile
  • void DamagePlayer(Player player, ref int damage)
  • void HitEffect(int hitDirection, double damage) - Used primarily for visual (dust) effects and gore when the NPC is hit or killed.
  • NPC Interface methods:
    • string ChatFuncName() - Return the text you click on to call the ChatFunc().
    • void ChatFunc() - Perform some action when the text is clicked on. You can define an interface here, or maybe turn the NPC into Skeletron.
    • bool CanPlaceSlot(int slot, Item mouseItem) - return true if you want to let the player place / pick up an item in the specified slot. mouseItem is the item currently held by the mouse.
    • void PlaceSlot(int slot) - Perform some action after an item has been placed or taken from the specified slot
    • bool DropSlot(int slot) - Called when the interface is closed - return true if you want the item in the slot to be dropped, false otherwise.
  • bool PreDraw(SpriteBatch spriteBatch) - Called before the default drawing code; return true to execute the regular drawing code, otherwise return false.
  • void PostDraw(SpriteBatch spriteBatch) - Called after the default drawing code
  • public string DominantChat() - return non-empty string to override Chat method , added for things like temporary event texts etc.
  • public string ShopOverFuncName() - return non-empty string to change the name of the left option on chat
  • public string KindChatFuncName() - return a non-empty string to change name of the right option button on chat
  • public bool ShopOverFun() - return true to override setup shop , otherwise false
  • public bool KindChatFunc() - return true to let normal chat func be called
  • public void UpdateShop(Chest chest, int itemInShop) - ??

In Global code file (NPC.cs):

  • public void UpdateNPC() - called before each NPC update

Useful method calls or variables:

  • Config.mainInstance.DrawNPCReal(int npcindex,bool behindtiles) - call the drawing code for an individual NPC
  • NPC Config.npcDefs.byName["NPC Name"] - get the custom NPC object by name
  • int npc.HasBuff(string buffname) - returns the buff index of the wished buff or -1 if not found
  • bool NPC.AnyNPCs(string name) - returns true if any npc of the name exists in the world , false if otherwise

tConfig Custom Properties Edit

Name Type Description
animationType int The ID value of the NPC whose animation code you would like to use
frameCount int The number of frames in your image.
soundHitName string The name of a custom sound effect.
soundKilledName string The name of a custom sound effect.
baseGravity float Affect's NPC's movement on the Y axis
maxGravity float Affect's NPC's movement on the Y axis
dontRelocate bool NPC won't automatically search for a house - you will need to manually select one for it
dontDrawFace bool NPC's face won't show up in NPC list and you won't see its death message
dontDisplayLifeText bool Set to true to disable npc display info when you aim your mouse at it
texture string Make one ini use another's texture, the texture must be of the same group

BuffEdit

There are separate methods for buffs on NPCs and buffs on the Player.

  • Called every 'tick':
    • public void Effects(Player P,int buffIndex,int buffType,int buffTime)
    • public void NPCEffects(NPC N,int buffIndex,int buffType,int buffTime)
  • Called when the buff starts:
    • public void EffectsStart(Player P,int buffIndex,int buffType,int buffTime)
    • public void NPCEffectsStart(NPC N,int buffIndex,int buffType,int buffTime)
  • Called when the buff ends:
    • public void EffectsEnd(Player P,int buffIndex,int buffType,int buffTime)
    • public void NPCEffectsEnd(NPC N,int buffIndex,int buffType,int buffTime)
  • Used for saving/loading data:
    • void Save(BinaryWriter writer)
    • void Load(BinaryReader reader, int version)
  • Other:
    • void DamageNPC(Player myPlayer,NPC npc, ref int damage, ref float knockback)
      • Called when an NPC is hit with the weapon.
    • void DamagePlayer(Player player, ref int damage, NPC npc) - Use to modify damage the player receives when hit by an NPC
    • void DealtPlayer(Player player, double damage, NPC npc) - Called after the player takes damage from an NPC
    • void DamagePVP(Player myPlayer, ref int damage, Player enemyPlayer)
    • void DealtPVP(Player myPlayer, int damage, Player enemyPlayer)

ProjectileEdit

  • void Initialize()
  • void AI()
  • bool PreAI() - called before AI(); return true to execute AI(), false otherwise
  • void PostAI() - called after AI()
  • void DamageNPC(NPC npc, ref int damage, ref float knockback)
  • void DealtNPC(NPC npc, double damage, Player player)
  • void DamagePlayer(ref int damage, Player player) -​ You can use this to apply a code over a player that's hit by a projectile
  • void DealtPlayer(double damage,Player player) -​ ​You can use this to apply a code over a player that's hit by a projectile
  • void Kill() - Here, decide what to do with the projectile is destroyed. You could create an explosion, for instance.
  • bool tileCollide(Vector2 CollideVel) - allows executing code when the projectile hits a tile (only for tile collide projectiles), return true to run normal collision code and false otherwise
  • void DamagePVP(ref int damage, Player enemyPlayer)
  • void DealtPVP(double damage, Player enemyPlayer)
  • bool PreDraw(SpriteBatch spriteBatch) - Called before the default drawing code; return true to execute the regular drawing code, otherwise return false
  • void PostDraw(SpriteBatch spriteBatch) - Called after the default drawing code

Useful method calls or variables:

  • Projectile Config.projDefs.byName["Projectile Name"] - get the custom Projectile object by name
  • Color Projectile.GetColor(Color current) - return color of the same brightness as current
  • static void Projectile.ExplodeTile(int x,int y,int projtype,bool ExplodeWalls=false) - you can use this in your projectiles to explode tiles like the vanilla explosives do

tConfig Custom Properties Edit

Name Type Description
displayName string Set the projectile's displayname, which can be different from the .ini file name
aiPretendType int The Type to mimic. This would be the projectile.Type value
killPretendType int
pretendType int
pretendName string Maps to pretendType, for default projectiles only
hurtsTiles bool Set to false to make projectile not cut tiles like grass / vines when passing them, true otherwise.
color float,float,float,float Set the color, e.g. "255,0,0,64" means red=255, green=0, blue=0, alpha=64

TileEdit

  • void Initialize(int x, int y) - Called when the tile is placed, or when the world is loaded
  • void UseTile(Player player, int x, int y) - Called when the player clicks on the tile
  • void PlaceTile(int x, int y) - Called when a tile is placed
  • void KillTile(int x, int y, Player player) - Called when a tile is destroyed.
  • void PreKillTile(ref int x, ref int y, ref bool LetContinue, ref bool fail, ref bool effectOnly, ref bool noItem, Player P) - called on your tile before it executes any logic, you can change its X, Y and so on, allowing high level manipulation of its death. [not recommend]
  • bool StopKillTile(int x, int y) - stop a tile from dying after it dropped its particle effects, called after stop checks from effectOnly and noItem. Return true to stop KillTile there
  • bool CanDestroyTile(int x, int y) - Return true if the tile can be destroyed, false otherwise. Useful for a chest, if you want it to be indestructible while it contains items.
  • bool CanDestroyAround(int x, int y, string Dir) - called right after CanDestroyTile, it is called 4 times in total, with Dir being "Top" , "Bottom" , "Left" , or "Right", when you try to break tiles which surround your tile. Return false to stop them from being destroyed or true if the tile can be destroyed.
  • public void PostKillTile(int x, int y, string StoppedAt, Player P) - the string arguement tells you where the KillTile method ended when it dies, since there are so many stops StopAt possible results:
    • "Success" - if the entire method ran
    • "StopKill" -if StopKillTile returned true
    • "Unempty Chest" - if you destroy a vanilla chest which has things in it
    • "Fail" - if KillTile's 'fail' parameter was true and it got there
    • "EffectOnly" - if KillTile's 'effectOnly' parameter was true and it got there
    • "CanDestroyAround" - one of the CanDestroyAround methods returned false
    • "CanDestroyTile" - CanDestroyTile returned false
    • "Immune Top" - if you try destroying a tile that is under an undestructible vanilla tile
    • "PreKillTile" - if PreKillTile changed LetContinue to false
  • void Save(BinaryWriter writer) - Called when the world is saved
  • void Load(BinaryReader reader, int version) - Called when the world is loaded
  • static void SaveGlobal(BinaryWriter writer) - Like Save(), but for static variables
  • static void LoadGlobal(BinaryReader reader, int version) - Like Load(), but for static variables
  • void hitWire(int x, int y) - called when a tile is activated by a wire
  • void UpdateFrame()
  • void Update() - called every tick; As it won't take the coordinate as arguments, you should save the coordinates in Initialize() if they are needed
  • bool CheckTile(int x, int y) - Overrides the normal CheckTile method. Check the consistency of the tile types and tile frames. Return true if the check passes; false otherwise. ** Currently (tConfig 23.1) works backwards- False passes, true fails and destroys tile.
  • bool CheckPlaceTile(int x, int y) - Overrides the normal CheckPlaceTile method. Check the ground, ceiling, surrounding area, etc. to see if the tile can be placed. Return true if the check passes; false otherwise.
  • bool CanExplode(int x, int y, int projectileType) - Return true if the tile can be destroyed by an explosion, false otherwise. This only affects explosions from vanilla explosive projectiles, such as Bomb, Dynamite, Sticky Bomb, etc.
  • public void MouseOverTile(int x,int y,Player P) - can be used to make tile give an item icon on the player's mouse. (such as custom beds showing they're clickable)

In Global code file (Tile.cs):

  • void ModifyWorld() - Called after world generation, you can modify the world any way you want - put items in chests, modify tiles to add new ores, etc.

Useful method calls or variables:

  • int Config.tileDefs.ID["Tile Name"] - get the custom Tile's type id by name

tConfig Custom Properties Edit

Name Type Description
PretendType int The Type to mimic. Set it to the id of an existing Tile to get similar behavior.
DropName string The name of the item to drop when the tile is destroyed.
furniture string Set to 'chair', 'table', 'torch', or 'door', to meet NPC housing requirements
pick/axe/hammer float Specifies the resistance to pickaxes/axes/hammers. It is a multiplier, so the lower it is, the longer it takes to break the tile.
minPick/minAxe/minHammer int Specifies the minimum value required by the pickaxe/axe/hammer to break the tile
Width int Specify the width of the tile. It is 1 by default.
Height int Specify the height of the tile. It is 1 by default.
mechToggle string The name of a tile to 'toggle' to when this tile is activated by wiring.
special bool If the tile is 1x1, use this to enable custom code being called
hitSound int Specify the ID number for the sound to play when the tile is hit with a tool
hitSoundName string Specify the name of the custom sound effect to play when the tile is hit with a tool
hitSoundList int Specify the ID for the sound list to use
directional bool Set to True to create 'multi-directional' tiles; it will change the sprite frame based on the direction the player is facing when placing the tile. The frames must be going horizontally; see vanilla sprites for the bed and door for example.
doorType string Set this to "open" or "closed" - If your door is opened, the sprite must have two frames of a 2x3 door. If the door is closed, it must have one frame of a 1x3 door.
doorToggle string Set this to the name of the other tile to 'toggle' to when opening or closing. For example, the "Open Stone Door.ini" would have doorToggle=Closed Stone Door. You can also ignore this attribute if you want to have more control by doing it through code.
placeFrame int Specify the frame number to use when placing a tile. This value is zero by default.
placeOn string Specify how the tile can be placed. Current options are: solid, solidTop, wall, ceiling, side, air. You can use any combinations of these for a tile to have multiple possibilities, and separate them by a space. For instance, to make a tile be placeable on top of solid tiles and solidTop tiles (e.g. tables), then you set "placeOn=solid solidTop". Default behavior is "solid wall ceiling side" for Solid tiles Non-Solid tiles by default have just "solid" as their placeable attribute.
light float,float,float Specify custom lighting for the tile. See here for more details.
treasure bool Set to True to make tile shine when using the spelunking potion
dustType int the dust type you want, for your tile to emit that dust when struck.
texture string Make one ini use another's texture, the texture must be of the same group
[Drops] define only new drops for an NPC without modifying its stats
e.g. 5-10 Torch=100
which means 100% dropping 5 to 10 Torch

RecipeEdit

  • Recipe.AddSimpleRecipe(object output, object... args)

example uses:

Item output = new Item(); output.SetDefaults("Gold Chest"); 
output.stack = 3; 
Recipe.AddSimpleRecipe(output,"3 Chest","10 Gold Bar","@Work Bench") 
Recipe.AddSimpleRecipe("2 Mega Spelunker Potion","5 Spelunker Potion","@Bottle","@Water")
Recipe.AddSimpleRecipe("Lava Bottle","Bottle","@Lava")

output can be:

  • an instance of Item
  • a string in format:
    • "{item name}" - outputs one {item name}
    • "{amount} {item name}" - outputs {amount} of {item name}

arguments can be:

  • instances of Item - recipe materials
  • strings in format:
    • "{item name}" - requires one {item name} as material
    • "{amount} {item name}" - requires {amount} of {item name} as material
    • "@{tile name}" - tile required nearby
    • "@Water" - water required nearby
    • "@Lava" lava required nearby
  • ints - tile IDs required nearby

Around Wikia's network

Random Wiki