Tile Class Documentation - tModLoader/tModLoader GitHub Wiki
Note: This page is out of date and only relevant for 1.3 tModLoader. Modders using 1.4+ should rely on the documentation instead.
This page lists methods and fields pertaining to the Tile class. If you are working directly with Tile
s, you can consult this page for an understanding of various things. If you want to create a Tile in your mod, this is not relevant, see Basic Tile Guide for that. See also Main.tile[]. It is good to remember that Main.tile[]
can have null values in it, null values are empty/air tiles. Non-null values could also be empty/air tiles as well.
Index |
---|
Fields |
Methods |
Bitfield Data |
The Tile
class is structured to be very compact and efficient. You usually don't want to modify many of these fields directly. All values default to 0.
Field | Type | Description |
---|---|---|
type | ushort | Corresponds to the TileID of this tile. Since the dirt tile has the value of 0, you need to check other values to know if this tile has a tile or not. Tile.active() can be used to check if the Tile is air or not. |
wall | ushort | Corresponds to the WallID of this tile. A value of 0 means no wall. |
liquid | byte | Represents how much liquid is in the tile. Ranges from 0, no liquid, to 255, filled with liquid. |
sTileHeader | ushort | A bit field. Don't touch this directly, use the methods. Stores: Wires, Actuator, Slope, Color, and HalfBrick data. |
bTileHeader | byte | A bit field. Don't touch this directly, use the methods. Stores: LiquidType, WallColor, and Wire4 data. |
bTileHeader2 | byte | A bit field. Don't touch this directly, use the methods. Stores: FrameNumber, wallFrameX, and WallFrameNumber data. |
bTileHeader3 | byte | A bit field. Don't touch this directly, use the methods. Stores: SkipLiquid, CheckLiquid, and wallFrameY data. |
frameX frameY |
short | Corresponds to the coordinates of the 16x16 (usually) area in the spritesheet this Tile uses. For a Framed tile, this value is set automatically as the world loads or other tiles are placed or mined nearby. See Framed vs FrameImportant for more info. For FrameImportant tiles, this value will not change and will be saved and synced in Multiplayer. In either case, frameX and frameY correspond to the coordinates of the top left corner of the area in the spritesheet that this Tile should draw. 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 ModTileEntity s |
collisionType | int | Get only property. Unused. |
Constructor, all values default to 0.
Constructor that clones another Tile
Creates a clone of the Tile. Tile clone = (Tile)Main.tile[x,y].Clone()
Copies fields from another Tile.
Clears all fields.
Sets or checks if the Tile has a tile present or not.
Returns true is Tile is active but not actuated. Equivalent to tile.active() && !tile.inActive()
.
Sets or checks if the tile is actuated.
Sets or checks liquid type. 0 water, 1 lava, 2 honey.
Sets or checks liquid type.
Sets or checks presence of individual wires.
Sets or checks presence of actuator on tile.
Sets or checks tile color.
Sets or checks wall color.
Framed tiles usually have 3 choices (alternate images), this sets or checks that value.
Various wall framing related methods.
Various Liquid movement related methods.
Various slope related methods.
Prints debug info about a Tile.
Various methods.
In order to store its data efficiently, each Tile
uses several "header" fields as bitfields.
A bitfield is a variable used for a sequence of bits instead of an actual value. Accessing and modifying the bits is usually done through the bitwise operators: |
(bitwise-OR), &
(bitwise-AND), ^
(bitwise-XOR), ~
(bitwise-NOT), <<
(shift left logical) and >>
(shift right logical).
An example of uses for each operator is shown below:
Operator | Value 1 | Value 2 | Expression | Expression (binary) | Result | Result (binary) |
---|---|---|---|---|---|---|
| |
35 | 68 | 35 | 68 |
0010 0011 | 0100 0100 |
103 | 0110 0111 |
& |
39 | 68 | 39 & 68 |
0010 0111 & 0100 0100 |
4 | 0000 0100 |
^ |
47 | 68 | 47 ^ 68 |
0010 1111 ^ 0100 0100 |
107 | 0110 1011 |
~ |
68 | n/a | ~ 68 |
~ 0100 0100 |
187 | 1011 1011 |
<< |
35 | 2 | 35 << 2 |
0010 0011 << 0000 0010 |
210 | 1000 1100 |
>> |
35 | 2 | 35 >> 2 |
0010 0011 >> 0000 0010 |
8 | 0000 1000 |
Operator | Explanation |
---|---|
| |
If the bit in Value 1 or the bit in Value 2 is set, the bit in the result is also set. |
& |
The bit in the result is set only if the bit in Value 1 and Value 2 is set. |
^ |
The bit in the result is set only if the bit in Value 1 or Value 2 is set, but not both. |
~ |
Every 1 bit becomes a 0 bit and vice versa. |
<< |
Every bit in Value 1 is shifted to the left Value 2 times. Zeros are filled in from the right and any bits that overflow past the most significant bit (the first one) are removed. |
>> |
Every bit in Value 1 is shifted to the right Value 2 times. The most significant bit is filled in from the left and any bits that overflow past the least significant bit (the last one) are removed. |
The Tile
class has four bitfields: sTileHeader
, bTileHeader
, bTileHeader2
and bTileHeader3
. These bitfields should NOT be modified directly. Instead, use the various methods in Tile
.
For reference, here's what every bit in the bitfields represent and where they are normally accessed:
-SSS UHGB RTAC CCCC
-
: Unused.
SSS
: Where the slope type for this Tile
is stored. Accessed from tile.slope()
and tile.slope(byte)
. 0 is no slope, 1 is down-left slope, 2 is down-right slope, 3 is up-left slope and 4 is up-right slope.
U
: If this Tile
has an Actuator on it. Accessed from tile.actuator()
and tile.actuator(bool)
.
H
: If this Tile
is a half-brick. Accessed from tile.halfBrick()
and tile.halfBrick(bool)
.
G
: If this Tile
has a Green Wire on it. Accessed from tile.wire3()
and tile.wire3(bool)
.
B
: If this Tile
has a Blue Wire on it. Accessed from tile.wire2()
and tile.wire2(bool)
.
R
: If this Tile
has a Red Wire on it. Accessed from tile.wire()
and tile.wire(bool)
.
T
: If this Tile
is actuated. Accessed from tile.inActive()
and tile.inActive(bool)
.
A
: If this Tile
is active (not air). Accessed from tile.active()
and tile.active(bool)
.
C CCCC
: Where the paint color type for this Tile
is stored. Accessed from tile.color()
and tile.color(byte)
. Value ranges from 0 to 30.
YLLW WWWW
Y
: If this Tile
has a Yellow Wire on it. Accessed from tile.wire4()
and tile.wire4(bool)
.
LL
: Where the liquid type for this Tile
is stored. Accessed from tile.lava()
, tile.lava(bool)
, tile.honey()
and tile.honey(bool)
. 0 is water, 1 is lava and 2 is honey.
W WWWW
: Where the paint color type for this Tile
's wall is stored. Accessed from tile.wallColor()
and tile.wallColor(byte)
. Value ranges from 0 to 30.
WWNN XXXX
WW
: Related to wall framing. Accessed from tile.wallFrameNumber()
and tile.wallFrameNumber(byte)
. Values range from 0 to 3.
NN
: The alternate frame number for this Tile
. Accessed from tile.frameNumber()
and tile.frameNumber(byte)
. Values can range from 0 to 3, but vanilla only uses 0 to 2.
XXXX
: Where the frameX for this Tile
's wall in its spritesheet is stored. Accessed from tile.wallFrameX()
and tile.wallFrameX(byte)
. The values range from 0 to 15. tile.wallFrameX()
returns this value * 36 when called, and tile.wallFrameX(byte)
sets this value to the parameter / 36.
---S CYYY
---
: Unused.
S
: A flag used for liquid updating. Accessed from tile.skipLiquid()
and tile.skipLiquid(bool)
.
C
: A flag used for liquid updating. Accessed from tile.checkingLiquid()
and tile.checkingLiquid(bool)
.
YYY
: Where the frameY for this Tile
's wall in its spritesheet is stored. Accessed from tile.wallFrameY()
and tile.wallFrameY(byte)
. Values range from 0 to 7. These bits are handled in the same manner as the XXXX
bits in bTileHeader2
.