Terraria ModLoader  0.10.1.5
A framework for Terraria mods
Terraria.ModLoader.ModTileEntity Class Referenceabstract

Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit cool behavior. TileEntitry.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...
 

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. TileEntitry.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

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.

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

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

+ Here is the caller graph for this function:

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.

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

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  }
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 GetTileEntity(int type)
Gets the base ModTileEntity object with the given type.
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.
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  }
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.
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  }
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  }
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&#39;s sake.
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.

References Terraria.ModLoader.ModTileEntity.OnKill().

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  }
int Type
The numeric type used to identify this kind of tile entity.

+ Here is the call graph for this function:

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  }
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.

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

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  }
static ModTileEntity GetTileEntity(int type)
Gets the base ModTileEntity object with the given type.

+ Here is the call graph for this function:

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  }
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  }
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.

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

266  {
267  }

+ Here is the caller graph for this function:

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.

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

248  {
249  }

+ Here is the caller graph for this function:

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.

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

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  }
int Type
The numeric type used to identify this kind of tile entity.
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.

+ Here is the caller graph for this function:

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.

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

260  {
261  }

+ Here is the caller graph for this function:

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.

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

254  {
255  }

+ Here is the caller graph for this function:

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 (!lightRecei...
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  }
static void Terraria.ModLoader.ModTileEntity.UpdateEndInternal ( )
staticprivate

Definition at line 95 of file ModTileEntity.cs.

References Terraria.ModLoader.ModTileEntity.PostGlobalUpdate().

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

+ Here is the call graph for this function:

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

Definition at line 89 of file ModTileEntity.cs.

References Terraria.ModLoader.ModTileEntity.PreGlobalUpdate().

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

+ Here is the call graph for this function:

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:

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 ...

Member Data Documentation

int Terraria.ModLoader.ModTileEntity.nextTileEntity = numVanilla
staticprivate

Definition at line 16 of file ModTileEntity.cs.

const int Terraria.ModLoader.ModTileEntity.numVanilla = 3

Definition at line 15 of file ModTileEntity.cs.

Property Documentation

Mod Terraria.ModLoader.ModTileEntity.mod
getset
string Terraria.ModLoader.ModTileEntity.Name
getset

The internal name of this ModTileEntity.

Definition at line 31 of file ModTileEntity.cs.

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

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.

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