tModLoader v2024.09
A mod to make and play Terraria mods
Tile Struct Reference

A data structure used for accessing information about tiles, walls, wires, and liquids at a single position in the world.Vanilla tile code and a mods tile code will be quite different, since tModLoader reworked how tiles function to improve performance. This means that copying vanilla code will leave you with many errors. Running the code through tModPorter will fix most of the issues, however.For your sanity, all of the changes are well documented to make it easier to port vanilla code. More...

Public Member Functions

TileColorCache BlockColorAndCoating ()
 Gets the paint and coating information from the tile at this position as a TileColorCache. More...
 
void Clear (TileDataType types)
 Clears the specified data at this position based on the given TileDataType. More...
 
void ClearBlockPaintAndCoating ()
 Clears any paint or coating on the tile at this position.
 
void ClearEverything ()
 Resets all of the data at this position.
To only remove the tile data, use ClearTile.
 
void ClearTile ()
 Resets the tile data at this position.
Sets HasTile and IsActuated to false and sets the BlockType to ID.BlockType.Solid. More...
 
void ClearWallPaintAndCoating ()
 Clears any paint or coating on the wall at this position.
 
object Clone ()
 
void CopyFrom (Tile from)
 Copies all data from the given position to this position. More...
 
void CopyPaintAndCoating (Tile other)
 Copies the paint and coating data from the specified tile to this tile.
Does not copy wall paint and coating data. More...
 
unsafe ref T Get< T > ()
 Used to get a reference to the ITileData at this position. More...
 
override int GetHashCode ()
 
void ResetToType (ushort type)
 Resets all of the data at this position except for the WallType, and sets TileType to type . More...
 
override string ToString ()
 
void UseBlockColors (TileColorCache cache)
 Sets the paint and coating of the tile at this position based on the given TileColorCache. More...
 
void UseWallColors (TileColorCache cache)
 Sets the paint and coating of the wall at this position based on the given TileColorCache. More...
 
TileColorCache WallColorAndCoating ()
 Gets the paint and coating information from the wall at this position as a TileColorCache. More...
 

Static Public Member Functions

static bool operator!= (Tile tile, ArgumentException justSoYouCanCompareWithNull)
 
static bool operator!= (Tile tile, Tile tile2)
 
static bool operator== (Tile tile, ArgumentException justSoYouCanCompareWithNull)
 
static bool operator== (Tile tile, Tile tile2)
 
static void SmoothSlope (int x, int y, bool applyToNeighbors=true, bool sync=false)
 Slopes a tile based on the tiles adjacent to it. More...
 

Properties

BlockType BlockType [get, set]
 The Slope and IsHalfBlock of this tile combined, which can be changed by hammering.
Legacy/vanilla equivalent is blockType.
 
bool BlueWire [get, set]
 Whether there is blue wire at this position.
Legacy/vanilla equivalent is wire2() or wire2(bool).
 
bool BottomSlope [get]
 Whether a tile's Slope has a solid bottom side (SlopeType.SlopeUpLeft or SlopeType.SlopeUpRight).
Legacy/vanilla equivalent is bottomSlope.
 
bool CheckingLiquid [get, set]
 Whether there is liquid at this position.
Legacy/vanilla equivalent is checkingLiquid() or checkingLiquid(bool).
 
bool GreenWire [get, set]
 Whether there is green wire at this position.
Legacy/vanilla equivalent is wire3() or wire3(bool).
 
bool HasActuator [get, set]
 Whether there is an actuator at this position.
Legacy/vanilla equivalent is actuator() or actuator(bool).
 
bool HasTile [get, set]
 Whether there is a tile at this position. Check this whenever you are accessing data from a tile to avoid getting data from an empty tile.
Legacy/vanilla equivalent is active() or active(bool). More...
 
bool HasUnactuatedTile [get]
 Whether there is a tile at this position that isn't actuated.
Legacy/vanilla equivalent is nactive. More...
 
bool IsActuated [get, set]
 Whether the tile at this position is actuated by an actuator.
Legacy/vanilla equivalent is inActive() or inActive(bool). More...
 
bool IsHalfBlock [get, set]
 Whether a tile is a half block shape, which can be changed by hammering.
Used by WorldGen.PoundTile(int, int) and BlockType.
Legacy/vanilla equivalent is halfBrick() or halfBrick(bool).
 
bool IsTileFullbright [get, set]
 Whether the tile at this position is fully illuminated. Used by ItemID.GlowPaint.
Legacy/vanilla equivalent is fullbrightBlock() or fullbrightBlock(bool).
 
bool IsTileInvisible [get, set]
 Whether the tile at this position is invisible. Used by ItemID.EchoCoating.
Legacy/vanilla equivalent is invisibleBlock() or invisibleBlock(bool).
 
bool IsWallFullbright [get, set]
 Whether the wall at this position is fully illuminated. Used by ItemID.GlowPaint.
Legacy/vanilla equivalent is fullbrightWall() or fullbrightWall(bool).
 
bool IsWallInvisible [get, set]
 Whether the wall at this position is invisible. Used by ItemID.EchoCoating.
Legacy/vanilla equivalent is invisibleWall() or invisibleWall(bool).
 
bool LeftSlope [get]
 Whether a tile's Slope has a solid left side (SlopeType.SlopeDownRight or SlopeType.SlopeUpRight).
Legacy/vanilla equivalent is leftSlope.
 
ref byte LiquidAmount [get]
 The amount of liquid at this position.
Ranges from 0, no liquid, to 255, filled with liquid.
Legacy/vanilla equivalent is liquid.
 
int LiquidType [get, set]
 The LiquidID of the liquid at this position.
Make sure to check that LiquidAmount is greater than 0.
Legacy/vanilla equivalent is liquidType() or liquidType(int).
 
bool RedWire [get, set]
 Whether there is red wire at this position.
Legacy/vanilla equivalent is wire() or wire(bool).
 
bool RightSlope [get]
 Whether a tile's Slope has a solid right side (SlopeType.SlopeDownLeft or SlopeType.SlopeUpLeft).
Legacy/vanilla equivalent is rightSlope.
 
bool SkipLiquid [get, set]
 Whether the liquid at this position should skip updating for 1 tick.
Legacy/vanilla equivalent is skipLiquid() or skipLiquid(bool).
 
SlopeType Slope [get, set]
 The slope shape of the tile, which can be changed by hammering.
Used by WorldGen.SlopeTile(int, int, int, bool) and BlockType.
Legacy/vanilla equivalent is slope() or slope(byte).
 
byte TileColor [get, set]
 The PaintID the tile at this position is painted with. Is PaintID.None if not painted.
Legacy/vanilla equivalent is color() or color(byte).
 
int TileFrameNumber [get, set]
 The random style number the tile at this position has, which is random number between 0 and 2 (inclusive).
This is used in non-Main.tileFrameImportant tiles (aka "Terrain" tiles) to provide visual variation and is not synced in multiplayer nor will it be preserved when saving and loading the world.
Legacy/vanilla equivalent is frameNumber() or frameNumber(byte).
 
ref short TileFrameX [get]
 The X coordinate of the top left corner of the area in the spritesheet for the TileType to be used to draw the tile at this position.For a Framed tile, this value is set automatically according to the framing logic as the world loads or other tiles are placed or mined nearby. See Framed vs FrameImportantfor more info. For Main.tileFrameImportant tiles, this value will not change due to tile framing and will be saved and synced in Multiplayer. In either case, TileFrameX and TileFrameY correspond to the coordinates of the top left corner of the area in the spritesheet corresponding to the TileType that should be drawn at this position. Custom drawing logic can adjust these values.Some tiles such as Christmas Tree and Weapon Rack use the higher bits of these fields to do tile-specific behaviors. Modders should not attempt to do similar approaches, but should use ModLoader.ModTileEntitys.Legacy/vanilla equivalent is frameX.
 
ref short TileFrameY [get]
 The Y coordinate of the top left corner of the area in the spritesheet for the TileType to be used to draw the tile at this position.For a Framed tile, this value is set automatically according to the framing logic as the world loads or other tiles are placed or mined nearby. See Framed vs FrameImportantfor more info. For Main.tileFrameImportant tiles, this value will not change due to tile framing and will be saved and synced in Multiplayer. In either case, TileFrameX and TileFrameY correspond to the coordinates of the top left corner of the area in the spritesheet corresponding to the TileType that should be drawn at this position. Custom drawing logic can adjust these values.Some tiles such as Christmas Tree and Weapon Rack use the higher bits of these fields to do tile-specific behaviors. Modders should not attempt to do similar approaches, but should use ModLoader.ModTileEntitys.Legacy/vanilla equivalent is frameY.
 
ref ushort TileType [get]
 The TileID of the tile at this position.
This value is only valid if HasTile is true.
Legacy/vanilla equivalent is type.
 
bool TopSlope [get]
 Whether a tile's Slope has a solid top side (SlopeType.SlopeDownLeft or SlopeType.SlopeDownRight).
Legacy/vanilla equivalent is topSlope.
 
byte WallColor [get, set]
 The PaintID the wall at this position is painted with. Is PaintID.None if not painted.
Legacy/vanilla equivalent is wallColor() or wallColor(byte).
 
int WallFrameNumber [get, set]
 The random style number the wall at this position has, which is a random number between 0 and 2 (inclusive).
This is used to provide visual variation and is not synced in multiplayer nor will it be preserved when saving and loading the world.
Legacy/vanilla equivalent is wallFrameNumber() or wallFrameNumber(byte).
 
int WallFrameX [get, set]
 The X coordinate of the top left corner of the area in the spritesheet for the WallType to be used to draw the wall at this position.Legacy/vanilla equivalent is wallFrameX() or wallFrameX(int).
 
int WallFrameY [get, set]
 The Y coordinate of the top left corner of the area in the spritesheet for the WallType to be used to draw the wall at this position.Legacy/vanilla equivalent is wallFrameY() or wallFrameY(int).
 
ref ushort WallType [get]
 The WallID of the wall at this position.
A value of 0 indicates no wall.
Legacy/vanilla equivalent is wall.
 
bool YellowWire [get, set]
 Whether there is yellow wire at this position.
Legacy/vanilla equivalent is wire4() or wire4(bool).
 

Detailed Description

A data structure used for accessing information about tiles, walls, wires, and liquids at a single position in the world.

Vanilla tile code and a mods tile code will be quite different, since tModLoader reworked how tiles function to improve performance. This means that copying vanilla code will leave you with many errors. Running the code through tModPorter will fix most of the issues, however.

For your sanity, all of the changes are well documented to make it easier to port vanilla code.

Member Function Documentation

◆ BlockColorAndCoating()

TileColorCache Tile.BlockColorAndCoating ( )

Gets the paint and coating information from the tile at this position as a TileColorCache.

Returns
A TileColorCache representing the paint and coatings on the tile at this position.

◆ Clear()

void Tile.Clear ( TileDataType  types)

Clears the specified data at this position based on the given TileDataType.

Parameters
typesThe TileDataType to clear.

◆ ClearTile()

void Tile.ClearTile ( )

Resets the tile data at this position.
Sets HasTile and IsActuated to false and sets the BlockType to ID.BlockType.Solid.

Does not reset data related to walls, wires, or anything else. For that, use ClearEverything.

◆ CopyFrom()

void Tile.CopyFrom ( Tile  from)

Copies all data from the given position to this position.

Parameters
fromThe position to copy the data from.

◆ CopyPaintAndCoating()

void Tile.CopyPaintAndCoating ( Tile  other)

Copies the paint and coating data from the specified tile to this tile.
Does not copy wall paint and coating data.

Parameters
otherThe Tile to copy the data from.

◆ Get< T >()

unsafe ref T Tile.Get< T > ( )

Used to get a reference to the ITileData at this position.

Template Parameters
TThe ITileData to get.
Returns
The ITileData of type T at this position.
Type Constraints
T :unmanaged 
T :ITileData 
T :ref 
T :TileData<T> 
T :ptr 
T :TileId 

◆ ResetToType()

void Tile.ResetToType ( ushort  type)

Resets all of the data at this position except for the WallType, and sets TileType to type .

Parameters
typeThe ID.TileID to set this tile to.

◆ SmoothSlope()

static void Tile.SmoothSlope ( int  x,
int  y,
bool  applyToNeighbors = true,
bool  sync = false 
)
static

Slopes a tile based on the tiles adjacent to it.

Parameters
xThe X coordinate of the tile.
yThe Y coordinate of the tile.
applyToNeighborsWhether the adjacent tiles should be automatically smoothed.
syncWhether the changes should automatically be synced to multiplayer.

◆ UseBlockColors()

void Tile.UseBlockColors ( TileColorCache  cache)

Sets the paint and coating of the tile at this position based on the given TileColorCache.

Parameters
cacheThe TileColorCache to apply.

◆ UseWallColors()

void Tile.UseWallColors ( TileColorCache  cache)

Sets the paint and coating of the wall at this position based on the given TileColorCache.

Parameters
cacheThe TileColorCache to apply.

◆ WallColorAndCoating()

TileColorCache Tile.WallColorAndCoating ( )

Gets the paint and coating information from the wall at this position as a TileColorCache.

Returns
A TileColorCache representing the paint and coatings on the wall at this position.

Property Documentation

◆ HasTile

bool Tile.HasTile
getset

Whether there is a tile at this position. Check this whenever you are accessing data from a tile to avoid getting data from an empty tile.
Legacy/vanilla equivalent is active() or active(bool).

Actuated tiles are not solid, so use HasUnactuatedTile instead of HasTile for collision checks.
This only corresponds to whether a tile exists, however, a wall can exist without a tile. To check if a wall exists, use tile.WallType != WallID.None.

◆ HasUnactuatedTile

bool Tile.HasUnactuatedTile
get

Whether there is a tile at this position that isn't actuated.
Legacy/vanilla equivalent is nactive.

Actuated tiles are not solid, so use HasUnactuatedTile instead of HasTile for collision checks.
When checking if a tile exists, use HasTile instead of HasUnactuatedTile.

◆ IsActuated

bool Tile.IsActuated
getset

Whether the tile at this position is actuated by an actuator.
Legacy/vanilla equivalent is inActive() or inActive(bool).

Actuated tiles are not solid.