2using System.Collections.Generic;
4using Terraria.DataStructures;
17 internal static readonly List<ModTileEntity> tileEntities =
new List<ModTileEntity>();
44 internal static int ReserveTileEntityID() {
49 if (reserveID > Byte.MaxValue) {
50 throw new Exception(
"Too many tile entities have been added");
62 internal static void Unload() {
72 foreach (KeyValuePair<int, TileEntity> pair
in ByID) {
106 if (tileEntity ==
null) {
112 int id = tileEntity.
Place(i, j);
115 NetMessage.SendData(86, -1, -1,
null,
id, i, j, 0f, 0, 0, 0);
123 if (tileEntity ==
null) {
134 newEntity.mod = tileEntity.
mod;
135 newEntity.Name = tileEntity.
Name;
136 newEntity.Type = tileEntity.
Type;
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;
156 public void Kill(
int i,
int j) {
157 Point16 pos =
new Point16(i, j);
158 if (ByPosition.ContainsKey(pos)) {
160 if (tileEntity.type ==
Type) {
162 ByID.Remove(tileEntity.ID);
163 ByPosition.Remove(pos);
171 public int Find(
int i,
int j) {
172 Point16 pos =
new Point16(i, j);
173 if (ByPosition.ContainsKey(pos)) {
175 if (tileEntity.type ==
Type) {
176 return tileEntity.ID;
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
static bool AllowVanillaClients
Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit c...
int Type
The numeric type used to identify this kind of tile entity.
sealed override void ReadExtraData(BinaryReader reader, bool networkSend)
Don't use this. It is included only for completion's sake.
static ModTileEntity ConstructFromBase(ModTileEntity tileEntity)
Returns a new ModTileEntity with the same class, mod, name, and type as the parameter....
virtual void PreGlobalUpdate()
Code that should be run before all tile entities in the world update.
abstract bool ValidTile(int i, int j)
Whether or not this tile entity is allowed to survive at the given coordinates. You should check whet...
static ModTileEntity GetTileEntity(int type)
Gets the base ModTileEntity object with the given type.
virtual void Load(TagCompound tag)
Allows you to load the custom data you have saved for this tile entity.
virtual void PostGlobalUpdate()
Code that should be run after all tile entities in the world update.
static int nextTileEntity
sealed override void WriteExtraData(BinaryWriter writer, bool networkSend)
Don't use this. It is included only for completion's sake.
virtual TagCompound Save()
Allows you to save custom data for this tile entity.
static ModTileEntity ConstructFromType(int type)
Returns a new ModTileEntity with the same class, mod, name, and type as the ModTileEntity with the gi...
static void UpdateStartInternal()
virtual void OnNetPlace()
Code that should be run when this tile entity is placed by means of server-syncing....
static void Initialize()
You should never use this. It is only included here for completion's sake.
virtual void OnKill()
This method only gets called in the Kill method. If you plan to use that, you can put code here to ma...
string Name
The internal name of this ModTileEntity.
static void UpdateEndInternal()
static int CountInWorld()
Returns the number of modded tile entities that exist in the world currently being played.
int Find(int i, int j)
Returns the entity ID of this kind of tile entity at the given coordinates for you.
Mod mod
The mod that added this ModTileEntity.
static void NetPlaceEntity(int i, int j, int type)
You should never use this. It is only included here for completion's sake.
virtual bool Autoload(ref string name)
Allows you to automatically load a tile entity instead of using Mod.AddTileEntity....
void Kill(int i, int j)
A helper method that removes this kind of tile entity from the given coordinates for you.
virtual void NetReceive(BinaryReader reader, bool lightReceive)
Receives the data sent in the NetSend hook. Called on MP Client when receiving tile data (!...
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 ...
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...
int Place(int i, int j)
A helper method that places this kind of tile entity in the given coordinates for you.
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...