2 using System.Collections.Generic;
15 public const int numVanilla = 3;
16 private static int nextTileEntity = numVanilla;
17 internal static readonly List<ModTileEntity> tileEntities =
new List<ModTileEntity>();
44 internal static int ReserveTileEntityID() {
47 int reserveID = nextTileEntity;
49 if (reserveID > Byte.MaxValue) {
50 throw new Exception(
"Too many tile entities have been added");
59 return type >= numVanilla && type < nextTileEntity ? tileEntities[type - numVanilla] : null;
62 internal static void Unload() {
63 nextTileEntity = numVanilla;
72 foreach (KeyValuePair<int, TileEntity> pair
in ByID) {
73 if (pair.Value.type >= numVanilla) {
84 _UpdateStart += UpdateStartInternal;
85 _UpdateEnd += UpdateEndInternal;
86 _NetPlaceEntity += NetPlaceEntity;
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) {
126 return ConstructFromBase(tileEntity);
134 newEntity.
mod = tileEntity.
mod;
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;
186 NetSend(writer, networkSend);
193 NetReceive(reader, networkSend);
200 return mod.Properties.Autoload;
236 public abstract bool ValidTile(
int i,
int j);
int Type
The numeric type used to identify this kind of tile entity.
string Name
The internal name of 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.
static bool AllowVanillaClients
Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit c...
int Find(int i, int j)
Returns the entity ID of this kind of tile entity at the given coordinates for you.
static void UpdateStartInternal()
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...
sealed override void WriteExtraData(BinaryWriter writer, bool networkSend)
Don't use this. It is included only for completion's sake.
static int CountInWorld()
Returns the number of modded tile entities that exist in the world currently being played...
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...
virtual void PostGlobalUpdate()
Code that should be run after all tile entities in the world update.
static ModTileEntity GetTileEntity(int type)
Gets the base ModTileEntity object with the given type.
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 void Load(TagCompound tag)
Allows you to load the custom data you have saved 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...
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 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...
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.
int Place(int i, int j)
A helper method that places this kind of tile entity in the given coordinates for you...
virtual TagCompound Save()
Allows you to save custom data for this tile entity.
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
virtual void OnNetPlace()
Code that should be run when this tile entity is placed by means of server-syncing. Called on Server only.
sealed override void ReadExtraData(BinaryReader reader, bool networkSend)
Don't use this. It is included only for completion's sake.
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.
static void Initialize()
You should never use this. It is only included here for completion's sake.
void Kill(int i, int j)
A helper method that removes this kind of tile entity from the given coordinates for you...
Mod mod
The mod that added this ModTileEntity.
static void UpdateEndInternal()