tModLoader v0.11.8.9
A mod to make and play Terraria mods
Terraria.ModLoader.ModTileEntity Class Referenceabstract

Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit cool behavior. TileEntity.Update is called in SP and on Server, not on Clients. More...

+ Inheritance diagram for Terraria.ModLoader.ModTileEntity:
+ Collaboration diagram for Terraria.ModLoader.ModTileEntity:

Public Member Functions

virtual bool Autoload (ref string name)
 Allows you to automatically load a tile entity instead of using Mod.AddTileEntity. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name. Use this method to either force or stop an autoload, or change the default display name. More...
 
int Find (int i, int j)
 Returns the entity ID of this kind of tile entity at the given coordinates for you. More...
 
virtual int Hook_AfterPlacement (int i, int j, int type, int style, int direction)
 This method does not get called by tModLoader, and is only included for you convenience so you do not have to cast the result of Mod.GetTileEntity. More...
 
void Kill (int i, int j)
 A helper method that removes this kind of tile entity from the given coordinates for you. More...
 
virtual void Load (TagCompound tag)
 Allows you to load the custom data you have saved for this tile entity. More...
 
virtual void NetReceive (BinaryReader reader, bool lightReceive)
 Receives the data sent in the NetSend hook. Called on MP Client when receiving tile data (!lightReceive) and when a MessageID.TileEntitySharing message is sent (lightReceive) More...
 
virtual void NetSend (BinaryWriter writer, bool lightSend)
 Allows you to send custom data for this tile entity between client and server. This is called on the server while sending tile data (!lightSend) and when a MessageID.TileEntitySharing message is sent (lightSend) More...
 
virtual void OnKill ()
 This method only gets called in the Kill method. If you plan to use that, you can put code here to make things happen when it is called. More...
 
virtual void OnNetPlace ()
 Code that should be run when this tile entity is placed by means of server-syncing. Called on Server only. More...
 
int Place (int i, int j)
 A helper method that places this kind of tile entity in the given coordinates for you. More...
 
virtual void PostGlobalUpdate ()
 Code that should be run after all tile entities in the world update. More...
 
virtual void PreGlobalUpdate ()
 Code that should be run before all tile entities in the world update. More...
 
sealed override void ReadExtraData (BinaryReader reader, bool networkSend)
 Don't use this. It is included only for completion's sake. More...
 
virtual TagCompound Save ()
 Allows you to save custom data for this tile entity. More...
 
abstract bool ValidTile (int i, int j)
 Whether or not this tile entity is allowed to survive at the given coordinates. You should check whether the tile is active, as well as the tile's type and frame. More...
 
sealed override void WriteExtraData (BinaryWriter writer, bool networkSend)
 Don't use this. It is included only for completion's sake. More...
 

Static Public Member Functions

static ModTileEntity ConstructFromBase (ModTileEntity tileEntity)
 Returns a new ModTileEntity with the same class, mod, name, and type as the parameter. It is very rare that you should have to use this. More...
 
static ModTileEntity ConstructFromType (int type)
 Returns a new ModTileEntity with the same class, mod, name, and type as the ModTileEntity with the given type. It is very rare that you should have to use this. More...
 
static int CountInWorld ()
 Returns the number of modded tile entities that exist in the world currently being played. More...
 
static ModTileEntity GetTileEntity (int type)
 Gets the base ModTileEntity object with the given type. More...
 
static void Initialize ()
 You should never use this. It is only included here for completion's sake. More...
 
static void NetPlaceEntity (int i, int j, int type)
 You should never use this. It is only included here for completion's sake. More...
 

Static Public Attributes

const int numVanilla = 3
 

Properties

Mod mod [get, set]
 The mod that added this ModTileEntity. More...
 
string Name [get, set]
 The internal name of this ModTileEntity. More...
 
int Type [get, set]
 The numeric type used to identify this kind of tile entity. More...
 

Static Private Member Functions

static void UpdateEndInternal ()
 
static void UpdateStartInternal ()
 

Static Private Attributes

static int nextTileEntity = numVanilla
 

Detailed Description

Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit cool behavior. TileEntity.Update is called in SP and on Server, not on Clients.

See also
Terraria.DataStructures.TileEntity

Definition at line 13 of file ModTileEntity.cs.

Member Function Documentation

◆ Autoload()

virtual bool Terraria.ModLoader.ModTileEntity.Autoload ( ref string  name)
virtual

Allows you to automatically load a tile entity instead of using Mod.AddTileEntity. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name. Use this method to either force or stop an autoload, or change the default display name.

Definition at line 199 of file ModTileEntity.cs.

199 {
200 return mod.Properties.Autoload;
201 }
ModProperties Properties
Definition: Mod.cs:52
Mod mod
The mod that added this ModTileEntity.
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...

References Terraria.ModLoader.ModProperties.Autoload, Terraria.ModLoader.ModTileEntity.mod, and Terraria.ModLoader.Mod.Properties.

Referenced by Terraria.ModLoader.Mod.AutoloadTileEntity().

+ Here is the caller graph for this function:

◆ ConstructFromBase()

static ModTileEntity Terraria.ModLoader.ModTileEntity.ConstructFromBase ( ModTileEntity  tileEntity)
static

Returns a new ModTileEntity with the same class, mod, name, and type as the parameter. It is very rare that you should have to use this.

Definition at line 132 of file ModTileEntity.cs.

132 {
133 ModTileEntity newEntity = (ModTileEntity)Activator.CreateInstance(tileEntity.GetType());
134 newEntity.mod = tileEntity.mod;
135 newEntity.Name = tileEntity.Name;
136 newEntity.Type = tileEntity.Type;
137 return newEntity;
138 }

References Terraria.ModLoader.ModTileEntity.mod, Terraria.ModLoader.ModTileEntity.Name, and Terraria.ModLoader.ModTileEntity.Type.

Referenced by Terraria.ModLoader.ModTileEntity.ConstructFromType(), and Terraria.ModLoader.ModTileEntity.Place().

+ Here is the caller graph for this function:

◆ ConstructFromType()

static ModTileEntity Terraria.ModLoader.ModTileEntity.ConstructFromType ( int  type)
static

Returns a new ModTileEntity with the same class, mod, name, and type as the ModTileEntity with the given type. It is very rare that you should have to use this.

Definition at line 121 of file ModTileEntity.cs.

121 {
122 ModTileEntity tileEntity = GetTileEntity(type);
123 if (tileEntity == null) {
124 return null;
125 }
126 return ConstructFromBase(tileEntity);
127 }
static ModTileEntity ConstructFromBase(ModTileEntity tileEntity)
Returns a new ModTileEntity with the same class, mod, name, and type as the parameter....
static ModTileEntity GetTileEntity(int type)
Gets the base ModTileEntity object with the given type.

References Terraria.ModLoader.ModTileEntity.ConstructFromBase(), and Terraria.ModLoader.ModTileEntity.GetTileEntity().

+ Here is the call graph for this function:

◆ CountInWorld()

static int Terraria.ModLoader.ModTileEntity.CountInWorld ( )
static

Returns the number of modded tile entities that exist in the world currently being played.

Definition at line 70 of file ModTileEntity.cs.

70 {
71 int count = 0;
72 foreach (KeyValuePair<int, TileEntity> pair in ByID) {
73 if (pair.Value.type >= numVanilla) {
74 count++;
75 }
76 }
77 return count;
78 }

References Terraria.ModLoader.ModTileEntity.numVanilla.

◆ Find()

int Terraria.ModLoader.ModTileEntity.Find ( int  i,
int  j 
)

Returns the entity ID of this kind of tile entity at the given coordinates for you.

Definition at line 171 of file ModTileEntity.cs.

171 {
172 Point16 pos = new Point16(i, j);
173 if (ByPosition.ContainsKey(pos)) {
174 TileEntity tileEntity = ByPosition[pos];
175 if (tileEntity.type == Type) {
176 return tileEntity.ID;
177 }
178 }
179 return -1;
180 }
int Type
The numeric type used to identify this kind of tile entity.

References Terraria.ModLoader.ModTileEntity.Type.

◆ GetTileEntity()

static ModTileEntity Terraria.ModLoader.ModTileEntity.GetTileEntity ( int  type)
static

Gets the base ModTileEntity object with the given type.

Definition at line 58 of file ModTileEntity.cs.

58 {
59 return type >= numVanilla && type < nextTileEntity ? tileEntities[type - numVanilla] : null;
60 }

References Terraria.ModLoader.ModTileEntity.nextTileEntity, and Terraria.ModLoader.ModTileEntity.numVanilla.

Referenced by Terraria.ModLoader.ModTileEntity.ConstructFromType(), and Terraria.ModLoader.ModTileEntity.NetPlaceEntity().

+ Here is the caller graph for this function:

◆ Hook_AfterPlacement()

virtual int Terraria.ModLoader.ModTileEntity.Hook_AfterPlacement ( int  i,
int  j,
int  type,
int  style,
int  direction 
)
virtual

This method does not get called by tModLoader, and is only included for you convenience so you do not have to cast the result of Mod.GetTileEntity.

Definition at line 241 of file ModTileEntity.cs.

241 {
242 return -1;
243 }

◆ Initialize()

static void Terraria.ModLoader.ModTileEntity.Initialize ( )
static

You should never use this. It is only included here for completion's sake.

Definition at line 83 of file ModTileEntity.cs.

83 {
84 _UpdateStart += UpdateStartInternal;
85 _UpdateEnd += UpdateEndInternal;
86 _NetPlaceEntity += NetPlaceEntity;
87 }
static void NetPlaceEntity(int i, int j, int type)
You should never use this. It is only included here for completion's sake.

References Terraria.ModLoader.ModTileEntity.NetPlaceEntity(), Terraria.ModLoader.ModTileEntity.UpdateEndInternal(), and Terraria.ModLoader.ModTileEntity.UpdateStartInternal().

+ Here is the call graph for this function:

◆ Kill()

void Terraria.ModLoader.ModTileEntity.Kill ( int  i,
int  j 
)

A helper method that removes this kind of tile entity from the given coordinates for you.

Definition at line 156 of file ModTileEntity.cs.

156 {
157 Point16 pos = new Point16(i, j);
158 if (ByPosition.ContainsKey(pos)) {
159 TileEntity tileEntity = ByPosition[pos];
160 if (tileEntity.type == Type) {
161 ((ModTileEntity)tileEntity).OnKill();
162 ByID.Remove(tileEntity.ID);
163 ByPosition.Remove(pos);
164 }
165 }
166 }

References Terraria.ModLoader.ModTileEntity.OnKill(), and Terraria.ModLoader.ModTileEntity.Type.

+ Here is the call graph for this function:

◆ Load()

virtual void Terraria.ModLoader.ModTileEntity.Load ( TagCompound  tag)
virtual

Allows you to load the custom data you have saved for this tile entity.

Definition at line 214 of file ModTileEntity.cs.

214 {
215 }

◆ NetPlaceEntity()

static void Terraria.ModLoader.ModTileEntity.NetPlaceEntity ( int  i,
int  j,
int  type 
)
static

You should never use this. It is only included here for completion's sake.

Definition at line 104 of file ModTileEntity.cs.

104 {
105 ModTileEntity tileEntity = GetTileEntity(type);
106 if (tileEntity == null) {
107 return;
108 }
109 if (!tileEntity.ValidTile(i, j)) {
110 return;
111 }
112 int id = tileEntity.Place(i, j);
113 ModTileEntity newEntity = (ModTileEntity)ByID[id];
114 newEntity.OnNetPlace();
115 NetMessage.SendData(86, -1, -1, null, id, i, j, 0f, 0, 0, 0);
116 }

References Terraria.ModLoader.ModTileEntity.GetTileEntity(), Terraria.ModLoader.ModTileEntity.OnNetPlace(), Terraria.ModLoader.ModTileEntity.Place(), and Terraria.ModLoader.ModTileEntity.ValidTile().

Referenced by Terraria.ModLoader.ModTileEntity.Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NetReceive()

virtual void Terraria.ModLoader.ModTileEntity.NetReceive ( BinaryReader  reader,
bool  lightReceive 
)
virtual

Receives the data sent in the NetSend hook. Called on MP Client when receiving tile data (!lightReceive) and when a MessageID.TileEntitySharing message is sent (lightReceive)

Parameters
readerThe reader.
lightReceiveIf true, read only data that can change. Otherwise, read the full information.

Definition at line 230 of file ModTileEntity.cs.

230 {
231 }

Referenced by Terraria.ModLoader.ModTileEntity.ReadExtraData().

+ Here is the caller graph for this function:

◆ NetSend()

virtual void Terraria.ModLoader.ModTileEntity.NetSend ( BinaryWriter  writer,
bool  lightSend 
)
virtual

Allows you to send custom data for this tile entity between client and server. This is called on the server while sending tile data (!lightSend) and when a MessageID.TileEntitySharing message is sent (lightSend)

Parameters
writerThe writer.
lightSendIf true, send only data that can change. Otherwise, send the full information.

Definition at line 222 of file ModTileEntity.cs.

222 {
223 }

Referenced by Terraria.ModLoader.ModTileEntity.WriteExtraData().

+ Here is the caller graph for this function:

◆ OnKill()

virtual void Terraria.ModLoader.ModTileEntity.OnKill ( )
virtual

This method only gets called in the Kill method. If you plan to use that, you can put code here to make things happen when it is called.

Definition at line 266 of file ModTileEntity.cs.

266 {
267 }

Referenced by Terraria.ModLoader.ModTileEntity.Kill().

+ Here is the caller graph for this function:

◆ OnNetPlace()

virtual void Terraria.ModLoader.ModTileEntity.OnNetPlace ( )
virtual

Code that should be run when this tile entity is placed by means of server-syncing. Called on Server only.

Definition at line 248 of file ModTileEntity.cs.

248 {
249 }

Referenced by Terraria.ModLoader.ModTileEntity.NetPlaceEntity().

+ Here is the caller graph for this function:

◆ Place()

int Terraria.ModLoader.ModTileEntity.Place ( int  i,
int  j 
)

A helper method that places this kind of tile entity in the given coordinates for you.

Definition at line 143 of file ModTileEntity.cs.

143 {
144 ModTileEntity newEntity = ConstructFromBase(this);
145 newEntity.Position = new Point16(i, j);
146 newEntity.ID = AssignNewID();
147 newEntity.type = (byte)Type;
148 ByID[newEntity.ID] = newEntity;
149 ByPosition[newEntity.Position] = newEntity;
150 return newEntity.ID;
151 }

References Terraria.ModLoader.ModTileEntity.ConstructFromBase(), and Terraria.ModLoader.ModTileEntity.Type.

Referenced by Terraria.ModLoader.ModTileEntity.NetPlaceEntity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PostGlobalUpdate()

virtual void Terraria.ModLoader.ModTileEntity.PostGlobalUpdate ( )
virtual

Code that should be run after all tile entities in the world update.

Definition at line 260 of file ModTileEntity.cs.

260 {
261 }

Referenced by Terraria.ModLoader.ModTileEntity.UpdateEndInternal().

+ Here is the caller graph for this function:

◆ PreGlobalUpdate()

virtual void Terraria.ModLoader.ModTileEntity.PreGlobalUpdate ( )
virtual

Code that should be run before all tile entities in the world update.

Definition at line 254 of file ModTileEntity.cs.

254 {
255 }

Referenced by Terraria.ModLoader.ModTileEntity.UpdateStartInternal().

+ Here is the caller graph for this function:

◆ ReadExtraData()

sealed override void Terraria.ModLoader.ModTileEntity.ReadExtraData ( BinaryReader  reader,
bool  networkSend 
)

Don't use this. It is included only for completion's sake.

Definition at line 192 of file ModTileEntity.cs.

192 {
193 NetReceive(reader, networkSend);
194 }
virtual void NetReceive(BinaryReader reader, bool lightReceive)
Receives the data sent in the NetSend hook. Called on MP Client when receiving tile data (!...

References Terraria.ModLoader.ModTileEntity.NetReceive().

+ Here is the call graph for this function:

◆ Save()

virtual TagCompound Terraria.ModLoader.ModTileEntity.Save ( )
virtual

Allows you to save custom data for this tile entity.

Returns

Definition at line 207 of file ModTileEntity.cs.

207 {
208 return null;
209 }

◆ UpdateEndInternal()

static void Terraria.ModLoader.ModTileEntity.UpdateEndInternal ( )
staticprivate

Definition at line 95 of file ModTileEntity.cs.

95 {
96 foreach (ModTileEntity tileEntity in tileEntities) {
97 tileEntity.PostGlobalUpdate();
98 }
99 }

References Terraria.ModLoader.ModTileEntity.PostGlobalUpdate().

Referenced by Terraria.ModLoader.ModTileEntity.Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateStartInternal()

static void Terraria.ModLoader.ModTileEntity.UpdateStartInternal ( )
staticprivate

Definition at line 89 of file ModTileEntity.cs.

89 {
90 foreach (ModTileEntity tileEntity in tileEntities) {
91 tileEntity.PreGlobalUpdate();
92 }
93 }

References Terraria.ModLoader.ModTileEntity.PreGlobalUpdate().

Referenced by Terraria.ModLoader.ModTileEntity.Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValidTile()

abstract bool Terraria.ModLoader.ModTileEntity.ValidTile ( int  i,
int  j 
)
pure virtual

Whether or not this tile entity is allowed to survive at the given coordinates. You should check whether the tile is active, as well as the tile's type and frame.

Referenced by Terraria.ModLoader.ModTileEntity.NetPlaceEntity().

+ Here is the caller graph for this function:

◆ WriteExtraData()

sealed override void Terraria.ModLoader.ModTileEntity.WriteExtraData ( BinaryWriter  writer,
bool  networkSend 
)

Don't use this. It is included only for completion's sake.

Definition at line 185 of file ModTileEntity.cs.

185 {
186 NetSend(writer, networkSend);
187 }
virtual void NetSend(BinaryWriter writer, bool lightSend)
Allows you to send custom data for this tile entity between client and server. This is called on the ...

References Terraria.ModLoader.ModTileEntity.NetSend().

+ Here is the call graph for this function:

Member Data Documentation

◆ nextTileEntity

int Terraria.ModLoader.ModTileEntity.nextTileEntity = numVanilla
staticprivate

Definition at line 16 of file ModTileEntity.cs.

Referenced by Terraria.ModLoader.ModTileEntity.GetTileEntity().

◆ numVanilla

const int Terraria.ModLoader.ModTileEntity.numVanilla = 3
static

Property Documentation

◆ mod

Mod Terraria.ModLoader.ModTileEntity.mod
getset

The mod that added this ModTileEntity.

Definition at line 23 of file ModTileEntity.cs.

23 {
24 get;
25 internal set;
26 }

Referenced by Terraria.ModLoader.ModTileEntity.Autoload(), and Terraria.ModLoader.ModTileEntity.ConstructFromBase().

◆ Name

string Terraria.ModLoader.ModTileEntity.Name
getset

The internal name of this ModTileEntity.

Definition at line 31 of file ModTileEntity.cs.

31 {
32 get;
33 internal set;
34 }

Referenced by Terraria.ModLoader.Mod.AutoloadTileEntity(), and Terraria.ModLoader.ModTileEntity.ConstructFromBase().

◆ Type

int Terraria.ModLoader.ModTileEntity.Type
getset

The numeric type used to identify this kind of tile entity.

Definition at line 39 of file ModTileEntity.cs.

39 {
40 get;
41 internal set;
42 }

Referenced by Terraria.ModLoader.ModTileEntity.ConstructFromBase(), Terraria.ModLoader.ModTileEntity.Find(), Terraria.ModLoader.ModTileEntity.Kill(), and Terraria.ModLoader.ModTileEntity.Place().