Terraria ModLoader  0.11.7.8
A mod to make and play Terraria mods
ModTile.cs
Go to the documentation of this file.
1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
3 using System;
4 using System.Collections.Generic;
5 using Terraria.Localization;
6 
7 namespace Terraria.ModLoader
8 {
12  public class ModTile
13  {
17  public Mod mod {
18  get;
19  internal set;
20  }
21 
25  public string Name {
26  get;
27  internal set;
28  }
29 
33  public ushort Type {
34  get;
35  internal set;
36  }
37 
38  internal string texture;
42  public virtual string HighlightTexture => texture + "_Highlight";
46  public int soundType = 0;
50  public int soundStyle = 1;
54  public int dustType = 0;
58  public int drop = 0;
62  public int animationFrameHeight = 0;
66  public float mineResist = 1f;
70  public int minPick = 0;
74  public bool disableSmartCursor = false;
78  public bool disableSmartInteract = false;
82  public int[] adjTiles = new int[0];
86  public int closeDoorID = -1;
90  public int openDoorID = -1;
94  public string chest = "";
98  public int chestDrop = 0;
102  public string dresser = "";
106  public int dresserDrop = 0;
110  public bool bed = false;
114  public bool torch = false;
118  public bool sapling = false;
119 
123  public void AddToArray(ref int[] array) {
124  Array.Resize(ref array, array.Length + 1);
125  array[array.Length - 1] = Type;
126  }
127 
131  public void AddMapEntry(Color color, LocalizedText name = null) {
132  if (!MapLoader.initialized) {
133  MapEntry entry = new MapEntry(color, name);
134  if (!MapLoader.tileEntries.Keys.Contains(Type)) {
135  MapLoader.tileEntries[Type] = new List<MapEntry>();
136  }
137  MapLoader.tileEntries[Type].Add(entry);
138  }
139  }
140 
146  public ModTranslation CreateMapEntryName(string key = null) {
147  if (string.IsNullOrEmpty(key)) {
148  key = Name;
149  }
150  return mod.GetOrCreateTranslation(string.Format("Mods.{0}.MapObject.{1}", mod.Name, key));
151  }
152 
156  public void AddMapEntry(Color color, ModTranslation name) {
157  if (!MapLoader.initialized) {
158  MapEntry entry = new MapEntry(color, name);
159  if (!MapLoader.tileEntries.Keys.Contains(Type)) {
160  MapLoader.tileEntries[Type] = new List<MapEntry>();
161  }
162  MapLoader.tileEntries[Type].Add(entry);
163  }
164  }
165 
169  public void AddMapEntry(Color color, LocalizedText name, Func<string, int, int, string> nameFunc) {
170  if (!MapLoader.initialized) {
171  MapEntry entry = new MapEntry(color, name, nameFunc);
172  if (!MapLoader.tileEntries.Keys.Contains(Type)) {
173  MapLoader.tileEntries[Type] = new List<MapEntry>();
174  }
175  MapLoader.tileEntries[Type].Add(entry);
176  }
177  }
178 
182  public void AddMapEntry(Color color, ModTranslation name, Func<string, int, int, string> nameFunc) {
183  if (!MapLoader.initialized) {
184  MapEntry entry = new MapEntry(color, name, nameFunc);
185  if (!MapLoader.tileEntries.Keys.Contains(Type)) {
186  MapLoader.tileEntries[Type] = new List<MapEntry>();
187  }
188  MapLoader.tileEntries[Type].Add(entry);
189  }
190  }
191 
196  public void SetModTree(ModTree tree) {
197  TileLoader.trees[Type] = tree;
198  }
199 
204  public void SetModPalmTree(ModPalmTree palmTree) {
205  TileLoader.palmTrees[Type] = palmTree;
206  }
207 
212  public void SetModCactus(ModCactus cactus) {
213  TileLoader.cacti[Type] = cactus;
214  }
215 
222  public virtual bool Autoload(ref string name, ref string texture) {
223  return mod.Properties.Autoload;
224  }
225 
229  public virtual void SetDefaults() {
230  }
231 
235  public virtual void PostSetDefaults() {
236  }
237 
242  public virtual bool HasSmartInteract() {
243  return false;
244  }
245 
251  public virtual bool KillSound(int i, int j) {
252  return true;
253  }
254 
260  public virtual void NumDust(int i, int j, bool fail, ref int num) {
261  }
262 
268  public virtual bool CreateDust(int i, int j, ref int type) {
269  type = dustType;
270  return true;
271  }
272 
278  public virtual void DropCritterChance(int i, int j, ref int wormChance, ref int grassHopperChance, ref int jungleGrubChance) {
279  }
280 
286  public virtual bool Drop(int i, int j) {
287  return true;
288  }
289 
295  public virtual bool CanKillTile(int i, int j, ref bool blockDamaged) {
296  return true;
297  }
298 
304  public virtual void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) {
305  }
306 
312  public virtual void KillMultiTile(int i, int j, int frameX, int frameY) {
313  }
314 
320  public virtual bool CanExplode(int i, int j) {
321  return true;
322  }
323 
329  public virtual void NearbyEffects(int i, int j, bool closer) {
330  }
331 
337  public virtual void ModifyLight(int i, int j, ref float r, ref float g, ref float b) {
338  }
339 
345  public virtual bool Dangersense(int i, int j, Player player) {
346  return false;
347  }
348 
354  public virtual void SetSpriteEffects(int i, int j, ref SpriteEffects spriteEffects) {
355  }
356 
362  public virtual void SetDrawPositions(int i, int j, ref int width, ref int offsetY, ref int height) {
363  }
364 
378  public virtual void AnimateTile(ref int frame, ref int frameCounter) {
379  }
380 
390  public virtual void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) {
391  }
392 
398  public virtual bool PreDraw(int i, int j, SpriteBatch spriteBatch) {
399  return true;
400  }
401 
408  public virtual void DrawEffects(int i, int j, SpriteBatch spriteBatch, ref Color drawColor, ref int nextSpecialDrawIndex) {
409  }
410 
416  public virtual void PostDraw(int i, int j, SpriteBatch spriteBatch) {
417  }
418 
424  public virtual void SpecialDraw(int i, int j, SpriteBatch spriteBatch) {
425  }
426 
432  public virtual ushort GetMapOption(int i, int j) {
433  return 0;
434  }
435 
441  public virtual void RandomUpdate(int i, int j) {
442  }
443 
449  public virtual bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) {
450  return true;
451  }
452 
458  public virtual bool CanPlace(int i, int j) {
459  return true;
460  }
461 
467  [Obsolete("ModTile.RightClick will return a bool value later. This version is deprecated since v0.11.5, please use ModTile.NewRightClick instead and return true if a tile interaction has occurred.")]
468  public virtual void RightClick(int i, int j) {
469  }
470 
477  public virtual bool NewRightClick(int i, int j) {
478  return false;
479  }
480 
486  public virtual void MouseOver(int i, int j) {
487  }
488 
494  public virtual void MouseOverFar(int i, int j) {
495  }
496 
502  public virtual bool AutoSelect(int i, int j, Item item) {
503  return false;
504  }
505 
511  public virtual void HitWire(int i, int j) {
512  }
513 
519  public virtual bool Slope(int i, int j) {
520  return true;
521  }
522 
527  public virtual void FloorVisuals(Player player) {
528  }
529 
533  public virtual bool HasWalkDust() {
534  return false;
535  }
536 
543  public virtual void WalkDust(ref int dustType, ref bool makeDust, ref Color color) {
544  }
545 
550  public virtual void ChangeWaterfallStyle(ref int style) {
551  }
552 
558  public virtual int SaplingGrowthType(ref int style) {
559  return -1;
560  }
561 
568  public virtual void PlaceInWorld(int i, int j, Item item) {
569  }
570 
577  public virtual bool IsLockedChest(int i, int j) => false;
578 
591  public virtual bool UnlockChest(int i, int j, ref short frameXAdjustment, ref int dustType, ref bool manual) => false;
592  }
593 }
virtual void ChangeWaterfallStyle(ref int style)
Allows you to change the style of waterfall that passes through or over this type of tile...
Definition: ModTile.cs:550
virtual void MouseOver(int i, int j)
Allows you to make something happen when the mouse hovers over this tile. Useful for showing item ico...
Definition: ModTile.cs:486
virtual bool CanPlace(int i, int j)
Allows you to stop this tile from being placed at the given coordinates. Return false to block the ti...
Definition: ModTile.cs:458
This class represents a type of tile that can be added by a mod. Only one instance of this class will...
Definition: ModTile.cs:12
virtual void NearbyEffects(int i, int j, bool closer)
Allows you to make things happen when this tile is within a certain range of the player (around the s...
Definition: ModTile.cs:329
virtual void WalkDust(ref int dustType, ref bool makeDust, ref Color color)
Allows you to modify the dust created when the player walks on this tile. The makeDust parameter is w...
Definition: ModTile.cs:543
virtual bool PreDraw(int i, int j, SpriteBatch spriteBatch)
Allows you to draw things behind the tile at the given coordinates. Return false to stop the game fro...
Definition: ModTile.cs:398
virtual void RandomUpdate(int i, int j)
Called whenever the world randomly decides to update this tile in a given tick. Useful for things suc...
Definition: ModTile.cs:441
virtual bool HasWalkDust()
Whether or not this tile creates dust when the player walks on it. Returns false by default...
Definition: ModTile.cs:533
virtual bool NewRightClick(int i, int j)
Allows you to make something happen when this tile is right-clicked by the player. Return true to indicate that a tile interaction has occurred, preventing other right click actions like minion targetting from happening. Returns false by default.
Definition: ModTile.cs:477
virtual bool CanExplode(int i, int j)
Whether or not the tile at the given coordinates can be killed by an explosion (ie. bombs). Returns true by default; return false to stop an explosion from destroying it.
Definition: ModTile.cs:320
virtual void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
Allows you to determine how much light this block emits. Make sure you set Main.tileLighted[Type] to ...
Definition: ModTile.cs:337
virtual void DropCritterChance(int i, int j, ref int wormChance, ref int grassHopperChance, ref int jungleGrubChance)
Allows you to modify the chance the tile at the given coordinates has of spawning a certain critter w...
Definition: ModTile.cs:278
virtual void PostDraw(int i, int j, SpriteBatch spriteBatch)
Allows you to draw things in front of the tile at the given coordinates. This can also be used to do ...
Definition: ModTile.cs:416
virtual bool CreateDust(int i, int j, ref int type)
Allows you to modify the default type of dust created when the tile at the given coordinates is hit...
Definition: ModTile.cs:268
virtual void DrawEffects(int i, int j, SpriteBatch spriteBatch, ref Color drawColor, ref int nextSpecialDrawIndex)
Allows you to make stuff happen whenever the tile at the given coordinates is drawn. For example, creating dust or changing the color the tile is drawn in.
Definition: ModTile.cs:408
ModTranslation CreateMapEntryName(string key=null)
Creates a ModTranslation object that you can use in AddMapEntry.
Definition: ModTile.cs:146
void AddToArray(ref int[] array)
A convenient method for adding this tile&#39;s Type to the given array. This can be used with the arrays ...
Definition: ModTile.cs:123
This serves as the central class from which tile-related functions are supported and carried out...
Definition: TileLoader.cs:14
virtual bool AutoSelect(int i, int j, Item item)
Allows you to determine whether the given item can become selected when the cursor is hovering over t...
Definition: ModTile.cs:502
virtual void HitWire(int i, int j)
Allows you to make something happen when a wire current passes through this tile. ...
Definition: ModTile.cs:511
virtual void SetDrawPositions(int i, int j, ref int width, ref int offsetY, ref int height)
Allows you to customize the position in which this tile is drawn. Width refers to the width of one fr...
Definition: ModTile.cs:362
virtual bool Dangersense(int i, int j, Player player)
Allows you to determine whether this block glows red when the given player has the Dangersense buff...
Definition: ModTile.cs:345
virtual void FloorVisuals(Player player)
Allows you to make something happen when a player stands on this type of tile. For example...
Definition: ModTile.cs:527
void AddMapEntry(Color color, ModTranslation name)
Adds an entry to the minimap for this tile with the given color and display name. This should be call...
Definition: ModTile.cs:156
virtual void SpecialDraw(int i, int j, SpriteBatch spriteBatch)
Special Draw. Only called if coordinates are placed in Main.specX/Y during DrawEffects. Useful for drawing things that would otherwise be impossible to draw due to draw order, such as items in item frames.
Definition: ModTile.cs:424
virtual bool CanKillTile(int i, int j, ref bool blockDamaged)
Allows you to determine whether or not the tile at the given coordinates can be hit by anything...
Definition: ModTile.cs:295
This class represents a type of modded cactus. The cactus will share a tile ID with the vanilla cacti...
virtual void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
Allows you to determine what happens when the tile at the given coordinates is killed or hit with a p...
Definition: ModTile.cs:304
virtual void RightClick(int i, int j)
Allows you to make something happen when this tile is right-clicked by the player.
Definition: ModTile.cs:468
virtual void AnimateTile(ref int frame, ref int frameCounter)
Allows you to animate your tile. Use frameCounter to keep track of how long the current frame has bee...
Definition: ModTile.cs:378
void SetModCactus(ModCactus cactus)
Allows this tile to grow the given modded cactus.
Definition: ModTile.cs:212
virtual bool Slope(int i, int j)
Allows you to control how hammers slope this tile. Return true to allow it to slope normally...
Definition: ModTile.cs:519
virtual void PostSetDefaults()
Allows you to override some default properties of this tile, such as Main.tileNoSunLight and Main...
Definition: ModTile.cs:235
virtual void MouseOverFar(int i, int j)
Allows you to make something happen when the mouse hovers over this tile, even when the player is far...
Definition: ModTile.cs:494
virtual bool Drop(int i, int j)
Allows you to customize which items the tile at the given coordinates drops. Remember that the x...
Definition: ModTile.cs:286
virtual void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset)
Animates an individual tile. i and j are the coordinates of the Tile in question. frameXOffset and fr...
Definition: ModTile.cs:390
void AddMapEntry(Color color, ModTranslation name, Func< string, int, int, string > nameFunc)
Adds an entry to the minimap for this tile with the given color, default display name, and display name function. The parameters for the function are the default display name, x-coordinate, and y-coordinate. This should be called in SetDefaults.
Definition: ModTile.cs:182
virtual void PlaceInWorld(int i, int j, Item item)
Allows you to do something when this tile is placed. Called on the local Client and Single Player...
Definition: ModTile.cs:568
void SetModPalmTree(ModPalmTree palmTree)
Allows this tile to grow the given modded palm tree.
Definition: ModTile.cs:204
void AddMapEntry(Color color, LocalizedText name=null)
Adds an entry to the minimap for this tile with the given color and display name. This should be call...
Definition: ModTile.cs:131
virtual void NumDust(int i, int j, bool fail, ref int num)
Allows you to change how many dust particles are created when the tile at the given coordinates is hi...
Definition: ModTile.cs:260
void AddMapEntry(Color color, LocalizedText name, Func< string, int, int, string > nameFunc)
Adds an entry to the minimap for this tile with the given color, default display name, and display name function. The parameters for the function are the default display name, x-coordinate, and y-coordinate. This should be called in SetDefaults.
Definition: ModTile.cs:169
virtual void SetDefaults()
Allows you to set the properties of this tile. Many properties are stored as arrays throughout Terrar...
Definition: ModTile.cs:229
Mod is an abstract class that you will override. It serves as a central place from which the mod&#39;s co...
Definition: Mod.cs:24
virtual void KillMultiTile(int i, int j, int frameX, int frameY)
This hook is called exactly once whenever a block encompassing multiple tiles is destroyed. You can use it to make your multi-tile block drop a single item, for example.
Definition: ModTile.cs:312
virtual bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak)
Called whenever this tile updates due to being placed or being next to a tile that is changed...
Definition: ModTile.cs:449
virtual bool HasSmartInteract()
Whether or not the smart interact function can select this tile. Useful for things like chests...
Definition: ModTile.cs:242
This class represents a type of modded tree. The tree will share a tile ID with the vanilla trees (5)...
void SetModTree(ModTree tree)
Allows this tile to grow the given modded tree.
Definition: ModTile.cs:196
This class represents a type of modded palm tree. The palm tree will share a tile ID with the vanilla...
virtual int SaplingGrowthType(ref int style)
Allows this tile to support a sapling that can eventually grow into a tree. The type of the sapling s...
Definition: ModTile.cs:558
virtual void SetSpriteEffects(int i, int j, ref SpriteEffects spriteEffects)
Allows you to determine whether or not the tile will draw itself flipped in the world.
Definition: ModTile.cs:354
virtual ushort GetMapOption(int i, int j)
Allows you to choose which minimap entry the tile at the given coordinates will use. 0 is the first entry added by AddMapEntry, 1 is the second entry, etc. Returns 0 by default.
Definition: ModTile.cs:432
virtual bool Autoload(ref string name, ref string texture)
Allows you to modify the name and texture path of this tile when it is autoloaded. Return true to autoload this tile. When a tile is autoloaded, that means you do not need to manually call Mod.AddTile. By default returns the mod&#39;s autoload property.
Definition: ModTile.cs:222
virtual bool KillSound(int i, int j)
Allows you to customize which sound you want to play when the tile at the given coordinates is hit...
Definition: ModTile.cs:251