tModLoader v2024.09
A mod to make and play Terraria mods
GlobalTile Class Reference

This class allows you to modify the behavior of any tile in the game, both vanilla and modded.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically. More...

Inherits GlobalBlockType.

Public Member Functions

void AddToArray (ref int[] array, int type)
 A convenient method for adding an integer to the end of an array. This can be used with the arrays in TileID.Sets.RoomNeeds. More...
 
virtual int[] AdjTiles (int type)
 Allows you to determine which tiles the given tile type can be considered as when looking for crafting stations. More...
 
virtual void AnimateTile ()
 Allows animating tiles that were previously static. Loading a new texture for the tile is required first. Use Main.tileFrameCounter to count game frames and Main.tileFrame to change animation frames.
 
virtual bool AutoSelect (int i, int j, int type, Item item)
 Allows you to determine whether the given item can become selected when the cursor is hovering over a tile and the auto selection keybind is pressed. More...
 
virtual bool CanDrop (int i, int j, int type)
 Allows prevention of item drops from the tile dropping at the given coordinates. Return false to stop the game from dropping the tile's item(s). Returns true by default. Use Drop to spawn additional items.
 
virtual bool CanKillTile (int i, int j, int type, ref bool blockDamaged)
 Allows you to determine whether or not the tile at the given coordinates can be hit by anything. Returns true by default. blockDamaged currently has no use. More...
 
virtual bool CanReplace (int i, int j, int type, int tileTypeBeingPlaced)
 Allows you to stop a tile at the given coordinates from being replaced via the block swap feature. The tileTypeBeingPlaced parameter is the tile type that will replace the current tile. The type parameter is the tile type currently at the coordinates.
This method is called on the local client. This method is only called if the local player has sufficient pickaxe power to mine the existing tile.
Return false to block the tile from being replaced. Returns true by default.
Use this for dynamic logic. ID.TileID.Sets.DoesntGetReplacedWithTileReplacement, ID.TileID.Sets.DoesntPlaceWithTileReplacement, and ID.TileID.Sets.PreventsTileReplaceIfOnTopOfIt cover the most common use cases and should be used instead if possible. More...
 
virtual void ChangeWaterfallStyle (int type, ref int style)
 Allows you to change the style of waterfall that passes through or over any tile. More...
 
virtual void DrawEffects (int i, int j, int type, SpriteBatch spriteBatch, ref TileDrawInfo drawData)
 Allows you to make stuff happen whenever the tile at the given coordinates is drawn. For example, creating dust or changing the color the tile is drawn in. SpecialDraw will only be called if coordinates are added using Main.instance.TilesRenderer.AddSpecialLegacyPoint here. More...
 
virtual void Drop (int i, int j, int type)
 Allows you to spawn additional items when the tile at the given coordinates drops.
This hook is called once for multi-tiles. Trees or Cactus call this method for every individual tile.
For multi-tiles, the coordinates correspond to the tile that triggered this multi-tile to drop, so if checking Tile.TileFrameX and Tile.TileFrameY, be aware that the coordinates won't necessarily be the top left corner or origin of the multi-tile. Also be aware that some parts of the multi-tile might already be mined out when this method is called, so any math to determine tile style should be done on the tile at the coordinates passed in.
 
virtual void DropCritterChance (int i, int j, int type, ref int wormChance, ref int grassHopperChance, ref int jungleGrubChance)
 Allows you to modify the chance the tile at the given coordinates has of spawning a certain critter when the tile is killed. More...
 
virtual void FloorVisuals (int type, Player player)
 Allows you to make something happen when a player stands on the given type of tile. For example, you can make the player slide as if on ice. More...
 
virtual void HitWire (int i, int j, int type)
 Allows you to make something happen when a wire current passes through any tile. Both Wiring.SkipWire(int, int) and NetMessage.SendTileSquare(int, int, int, int, ID.TileChangeType) are usually required in the logic used in this method to correctly work.
Only called on the server and single player. All wiring happens on the world, not multiplayer clients. More...
 
virtual ? bool IsTileBiomeSightable (int i, int j, int type, ref Color sightColor)
 Allows you to customize whether this tile glows sightColor while the local player has the Biome Sight buff.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions and colors. Returns null by default.
This is only called on the local client. More...
 
virtual ? bool IsTileDangerous (int i, int j, int type, Player player)
 Allows you to determine whether this tile glows red when the given player has the Dangersense buff.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions. Returns null by default.
This is only called on the local client. More...
 
virtual ? bool IsTileSpelunkable (int i, int j, int type)
 Allows you to customize whether this tile can glow yellow while having the Spelunker buff, and is also detected by various pets.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions. Returns null by default. More...
 
virtual void KillTile (int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem)
 Allows you to determine what happens when the tile at the given coordinates is killed or hit with a pickaxe. If fail is true, the tile will not be mined; effectOnly makes it so that only dust is created; noItem stops items from dropping. More...
 
virtual void MouseOver (int i, int j, int type)
 Allows you to make something happen when the mouse hovers over any tile. Useful for showing item icons or text on the mouse. More...
 
virtual void MouseOverFar (int i, int j, int type)
 Allows you to make something happen when the mouse hovers over any tile, even when the player is far away. Useful for showing what's written on signs, etc. More...
 
virtual void NearbyEffects (int i, int j, int type, bool closer)
 Allows you to make things happen when the tile is within a certain range of the player (around the same range water fountains and music boxes work). The closer parameter is whether or not the tile is within the range at which things like campfires and banners work. More...
 
virtual void PostSetupTileMerge ()
 Can be used to adjust tile merge related things that are not possible to do in ModBlockType.SetStaticDefaults due to timing.
 
virtual bool PreHitWire (int i, int j, int type)
 Whether or not the vanilla HitWire code and the HitWire hook is allowed to run. Useful for overriding vanilla behavior by returning false. Returns true by default. More...
 
virtual void RightClick (int i, int j, int type)
 Allows you to make something happen when any tile is right-clicked by the player. More...
 
virtual void SetSpriteEffects (int i, int j, int type, ref SpriteEffects spriteEffects)
 Allows you to determine whether or not a tile will draw itself flipped in the world. More...
 
sealed override void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual bool Slope (int i, int j, int type)
 Allows you to control how hammers slope any tile. Return true to allow the tile to slope normally. Returns true by default. Called on the local Client and Single Player. More...
 
virtual void SpecialDraw (int i, int j, int type, SpriteBatch spriteBatch)
 Special Draw. Only called if coordinates are added using Main.instance.TilesRenderer.AddSpecialLegacyPoint during DrawEffects. Useful for drawing things that would otherwise be impossible to draw due to draw order, such as items in item frames. More...
 
virtual bool TileFrame (int i, int j, int type, ref bool resetFrame, ref bool noBreak)
 Called for every tile that updates due to being placed or being next to a tile that is changed. Return false to stop the game from carrying out its default TileFrame operations. Returns true by default. More...
 
- Public Member Functions inherited from GlobalBlockType
virtual bool CanExplode (int i, int j, int type)
 Whether or not the tile/wall at the given coordinates can be killed by an explosion (ie. bombs). Returns true by default; return false to stop an explosion from destroying it. More...
 
virtual bool CanPlace (int i, int j, int type)
 Allows you to stop a tile/wall from being placed at the given coordinates. Return false to block the tile/wall from being placed. Returns true by default. More...
 
virtual bool CreateDust (int i, int j, int type, ref int dustType)
 Allows you to modify the default type of dust created when the tile/wall at the given coordinates is hit. Return false to stop the default dust (the dustType parameter) from being created. Returns true by default. More...
 
virtual bool KillSound (int i, int j, int type, bool fail)
 Allows you to customize which sound you want to play when the tile/wall at the given coordinates is hit. Return false to stop the game from playing its default sound for the tile/wall. Returns true by default. More...
 
virtual void ModifyLight (int i, int j, int type, ref float r, ref float g, ref float b)
 Allows you to determine how much light the block emits. If it is a tile, make sure you set Main.tileLighted[Type] to true in SetDefaults for this to work. If it is a wall, it can also let you light up the block in front of this wall. More...
 
virtual void NumDust (int i, int j, int type, bool fail, ref int num)
 Allows you to change how many dust particles are created when the tile/wall at the given coordinates is hit. More...
 
virtual void PlaceInWorld (int i, int j, int type, Item item)
 Allows you to do something when this tile/wall is placed. Called on the local Client and Single Player. More...
 
virtual void PostDraw (int i, int j, int type, SpriteBatch spriteBatch)
 Allows you to draw things in front of the tile/wall at the given coordinates. This can also be used to do things such as creating dust. Called on active tiles. See also ModSystem.PostDrawTiles. More...
 
virtual bool PreDraw (int i, int j, int type, SpriteBatch spriteBatch)
 Allows you to draw things behind the tile/wall at the given coordinates. Return false to stop the game from drawing the tile/wall normally. Returns true by default. More...
 
virtual void RandomUpdate (int i, int j, int type)
 Called for every tile/wall the world randomly decides to update in a given tick. Useful for things such as growing or spreading. More...
 
- Public Member Functions inherited from ModType< TEntity, TModType >
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
string PrettyPrintName ()
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Whether or not this type should be loaded when it's told to. Returning false disables Mod.AddContent from actually loading this type. More...
 
abstract void Load (Mod mod)
 Called when loading the type. More...
 
abstract void Unload ()
 Called during unloading when needed. More...
 
- Public Member Functions inherited from ModType< TEntity >
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
string PrettyPrintName ()
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 

Protected Member Functions

sealed override void Register ()
 If you make a new ModType, seal this override. More...
 
- Protected Member Functions inherited from ModType< TEntity, TModType >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 
- Protected Member Functions inherited from ModType< TEntity >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 

Additional Inherited Members

- Properties inherited from ModType< TEntity, TModType >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 
- Properties inherited from IModType
string FullName [get]
 => $"{Mod.Name}/{Name}" More...
 
Mod Mod [get]
 The mod this belongs to. More...
 
string Name [get]
 The internal name of this instance. More...
 
- Properties inherited from ModType< TEntity >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 

Detailed Description

This class allows you to modify the behavior of any tile in the game, both vanilla and modded.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically.

Member Function Documentation

◆ AddToArray()

void GlobalTile.AddToArray ( ref int[]  array,
int  type 
)

A convenient method for adding an integer to the end of an array. This can be used with the arrays in TileID.Sets.RoomNeeds.

Parameters
array
type

◆ AdjTiles()

virtual int[] GlobalTile.AdjTiles ( int  type)
virtual

Allows you to determine which tiles the given tile type can be considered as when looking for crafting stations.

Parameters
type
Returns

◆ AutoSelect()

virtual bool GlobalTile.AutoSelect ( int  i,
int  j,
int  type,
Item  item 
)
virtual

Allows you to determine whether the given item can become selected when the cursor is hovering over a tile and the auto selection keybind is pressed.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type
item
Returns

◆ CanKillTile()

virtual bool GlobalTile.CanKillTile ( int  i,
int  j,
int  type,
ref bool  blockDamaged 
)
virtual

Allows you to determine whether or not the tile at the given coordinates can be hit by anything. Returns true by default. blockDamaged currently has no use.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
blockDamaged
Returns

◆ CanReplace()

virtual bool GlobalTile.CanReplace ( int  i,
int  j,
int  type,
int  tileTypeBeingPlaced 
)
virtual

Allows you to stop a tile at the given coordinates from being replaced via the block swap feature. The tileTypeBeingPlaced parameter is the tile type that will replace the current tile. The type parameter is the tile type currently at the coordinates.
This method is called on the local client. This method is only called if the local player has sufficient pickaxe power to mine the existing tile.
Return false to block the tile from being replaced. Returns true by default.
Use this for dynamic logic. ID.TileID.Sets.DoesntGetReplacedWithTileReplacement, ID.TileID.Sets.DoesntPlaceWithTileReplacement, and ID.TileID.Sets.PreventsTileReplaceIfOnTopOfIt cover the most common use cases and should be used instead if possible.

Parameters
i
j
type
tileTypeBeingPlaced
Returns

◆ ChangeWaterfallStyle()

virtual void GlobalTile.ChangeWaterfallStyle ( int  type,
ref int  style 
)
virtual

Allows you to change the style of waterfall that passes through or over any tile.

Parameters
type
style

◆ DrawEffects()

virtual void GlobalTile.DrawEffects ( int  i,
int  j,
int  type,
SpriteBatch  spriteBatch,
ref TileDrawInfo  drawData 
)
virtual

Allows you to make stuff happen whenever the tile at the given coordinates is drawn. For example, creating dust or changing the color the tile is drawn in. SpecialDraw will only be called if coordinates are added using Main.instance.TilesRenderer.AddSpecialLegacyPoint here.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe Tile type of the tile being drawn
spriteBatchThe SpriteBatch that should be used for all draw calls
drawDataVarious information about the tile that is being drawn, such as color, framing, glow textures, etc.

◆ DropCritterChance()

virtual void GlobalTile.DropCritterChance ( int  i,
int  j,
int  type,
ref int  wormChance,
ref int  grassHopperChance,
ref int  jungleGrubChance 
)
virtual

Allows you to modify the chance the tile at the given coordinates has of spawning a certain critter when the tile is killed.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
wormChanceChance for a worm to spawn. Value corresponds to a chance of 1 in X. Vanilla values include: Grass-400, Plants-200, Various Piles-6
grassHopperChanceChance for a grass hopper to spawn. Value corresponds to a chance of 1 in X. Vanilla values include: Grass-100, Plants-50
jungleGrubChanceChance for a jungle grub to spawn. Value corresponds to a chance of 1 in X. Vanilla values include: JungleVines-250, JunglePlants2-40, PlantDetritus-10

◆ FloorVisuals()

virtual void GlobalTile.FloorVisuals ( int  type,
Player  player 
)
virtual

Allows you to make something happen when a player stands on the given type of tile. For example, you can make the player slide as if on ice.

Parameters
type
player

◆ HitWire()

virtual void GlobalTile.HitWire ( int  i,
int  j,
int  type 
)
virtual

Allows you to make something happen when a wire current passes through any tile. Both Wiring.SkipWire(int, int) and NetMessage.SendTileSquare(int, int, int, int, ID.TileChangeType) are usually required in the logic used in this method to correctly work.
Only called on the server and single player. All wiring happens on the world, not multiplayer clients.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type

◆ IsTileBiomeSightable()

virtual ? bool GlobalTile.IsTileBiomeSightable ( int  i,
int  j,
int  type,
ref Color  sightColor 
)
virtual

Allows you to customize whether this tile glows sightColor while the local player has the Biome Sight buff.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions and colors. Returns null by default.
This is only called on the local client.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
sightColorThe color this tile should glow with, which defaults to Color.White.

◆ IsTileDangerous()

virtual ? bool GlobalTile.IsTileDangerous ( int  i,
int  j,
int  type,
Player  player 
)
virtual

Allows you to determine whether this tile glows red when the given player has the Dangersense buff.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions. Returns null by default.
This is only called on the local client.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
playerMain.LocalPlayer

◆ IsTileSpelunkable()

virtual ? bool GlobalTile.IsTileSpelunkable ( int  i,
int  j,
int  type 
)
virtual

Allows you to customize whether this tile can glow yellow while having the Spelunker buff, and is also detected by various pets.
Return true to force this behavior, or false to prevent it, overriding vanilla conditions. Returns null by default.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type

◆ KillTile()

virtual void GlobalTile.KillTile ( int  i,
int  j,
int  type,
ref bool  fail,
ref bool  effectOnly,
ref bool  noItem 
)
virtual

Allows you to determine what happens when the tile at the given coordinates is killed or hit with a pickaxe. If fail is true, the tile will not be mined; effectOnly makes it so that only dust is created; noItem stops items from dropping.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
failIf true, the tile won't be mined
effectOnlyIf true, only the dust visuals will happen
noItemIf true, the corresponding item won't drop

◆ MouseOver()

virtual void GlobalTile.MouseOver ( int  i,
int  j,
int  type 
)
virtual

Allows you to make something happen when the mouse hovers over any tile. Useful for showing item icons or text on the mouse.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type

◆ MouseOverFar()

virtual void GlobalTile.MouseOverFar ( int  i,
int  j,
int  type 
)
virtual

Allows you to make something happen when the mouse hovers over any tile, even when the player is far away. Useful for showing what's written on signs, etc.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type

◆ NearbyEffects()

virtual void GlobalTile.NearbyEffects ( int  i,
int  j,
int  type,
bool  closer 
)
virtual

Allows you to make things happen when the tile is within a certain range of the player (around the same range water fountains and music boxes work). The closer parameter is whether or not the tile is within the range at which things like campfires and banners work.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
closer

◆ PreHitWire()

virtual bool GlobalTile.PreHitWire ( int  i,
int  j,
int  type 
)
virtual

Whether or not the vanilla HitWire code and the HitWire hook is allowed to run. Useful for overriding vanilla behavior by returning false. Returns true by default.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type
Returns

◆ Register()

sealed override void GlobalTile.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements ModType< TEntity >.

◆ RightClick()

virtual void GlobalTile.RightClick ( int  i,
int  j,
int  type 
)
virtual

Allows you to make something happen when any tile is right-clicked by the player.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type

◆ SetSpriteEffects()

virtual void GlobalTile.SetSpriteEffects ( int  i,
int  j,
int  type,
ref SpriteEffects  spriteEffects 
)
virtual

Allows you to determine whether or not a tile will draw itself flipped in the world.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe tile type
spriteEffects

◆ SetupContent()

sealed override void GlobalTile.SetupContent ( )
virtual

If you make a new ModType, seal this override, and call SetStaticDefaults in it.

Reimplemented from ModType< TEntity >.

◆ Slope()

virtual bool GlobalTile.Slope ( int  i,
int  j,
int  type 
)
virtual

Allows you to control how hammers slope any tile. Return true to allow the tile to slope normally. Returns true by default. Called on the local Client and Single Player.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type
Returns

◆ SpecialDraw()

virtual void GlobalTile.SpecialDraw ( int  i,
int  j,
int  type,
SpriteBatch  spriteBatch 
)
virtual

Special Draw. Only called if coordinates are added using Main.instance.TilesRenderer.AddSpecialLegacyPoint during DrawEffects. Useful for drawing things that would otherwise be impossible to draw due to draw order, such as items in item frames.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
typeThe Tile type of the tile being drawn
spriteBatchThe SpriteBatch that should be used for all draw calls

◆ TileFrame()

virtual bool GlobalTile.TileFrame ( int  i,
int  j,
int  type,
ref bool  resetFrame,
ref bool  noBreak 
)
virtual

Called for every tile that updates due to being placed or being next to a tile that is changed. Return false to stop the game from carrying out its default TileFrame operations. Returns true by default.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.
type
resetFrame
noBreak
Returns