tModLoader v0.11.8.9
A mod to make and play Terraria mods
ModTile.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
3using System;
4using System.Collections.Generic;
5using Terraria.Localization;
6
7namespace 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}
This class represents a type of modded cactus. The cactus will share a tile ID with the vanilla cacti...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
Definition: Mod.cs:25
ModProperties Properties
Definition: Mod.cs:52
virtual string Name
Stores the name of the mod. This name serves as the mod's identification, and also helps with saving ...
Definition: Mod.cs:42
This class represents a type of modded palm tree. The palm tree will share a tile ID with the vanilla...
This class represents a type of tile that can be added by a mod. Only one instance of this class will...
Definition: ModTile.cs:13
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 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 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 void SetDefaults()
Allows you to set the properties of this tile. Many properties are stored as arrays throughout Terrar...
Definition: ModTile.cs:229
bool disableSmartCursor
Whether or not the smart cursor function is disabled when the cursor hovers above this tile....
Definition: ModTile.cs:74
int soundType
The default type of sound made when this tile is hit. Defaults to 0.
Definition: ModTile.cs:46
Mod mod
The mod which has added this type of ModTile.
Definition: ModTile.cs:17
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 bool UnlockChest(int i, int j, ref short frameXAdjustment, ref int dustType, ref bool manual)
Allows customization of how a chest unlock is accomplished. By default, frameXAdjustment will be -36,...
string dresser
Same as chest, except use this if your block is a dresser (has a size of 3x2 instead of 2x2).
Definition: ModTile.cs:102
ushort Type
The internal ID of this type of tile.
Definition: ModTile.cs:33
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
bool bed
Whether or not this tile is a valid spawn point. Defaults to false. If you set this to true,...
Definition: ModTile.cs:110
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 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
bool sapling
Whether or not this tile is a sapling, which can grow into a modded tree or palm tree.
Definition: ModTile.cs:118
void SetModTree(ModTree tree)
Allows this tile to grow the given modded tree.
Definition: ModTile.cs:196
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
int drop
The default type of item dropped when this tile is killed. Defaults to 0, which means no item.
Definition: ModTile.cs:58
int[] adjTiles
An array of the IDs of tiles that this tile can be considered as when looking for crafting stations.
Definition: ModTile.cs:82
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,...
Definition: ModTile.cs:182
int chestDrop
The ID of the item that drops when this chest is destroyed. Defaults to 0. Honestly,...
Definition: ModTile.cs:98
ModTranslation CreateMapEntryName(string key=null)
Creates a ModTranslation object that you can use in AddMapEntry.
Definition: ModTile.cs:146
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
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 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
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 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
int openDoorID
The ID of the tile that this door transforms into when it is opened. Defaults to -1,...
Definition: ModTile.cs:90
virtual ushort GetMapOption(int i, int j)
Allows you to choose which minimap entry the tile at the given coordinates will use....
Definition: ModTile.cs:432
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
int closeDoorID
The ID of the tile that this door transforms into when it is closed. Defaults to -1,...
Definition: ModTile.cs:86
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
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....
Definition: ModTile.cs:408
int dresserDrop
The ID of the item that drops when this dresser is destroyed. Defaults to 0. Honestly,...
Definition: ModTile.cs:106
virtual bool IsLockedChest(int i, int j)
Return true if this Tile corresponds to a chest that is locked. Prevents Quick Stacking items into th...
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 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 void KillMultiTile(int i, int j, int frameX, int frameY)
This hook is called exactly once whenever a block encompassing multiple tiles is destroyed....
Definition: ModTile.cs:312
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....
Definition: ModTile.cs:222
void SetModPalmTree(ModPalmTree palmTree)
Allows this tile to grow the given modded palm tree.
Definition: ModTile.cs:204
int soundStyle
The default style of sound made when this tile is hit. Defaults to 1.
Definition: ModTile.cs:50
virtual bool HasSmartInteract()
Whether or not the smart interact function can select this tile. Useful for things like chests....
Definition: ModTile.cs:242
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
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
string Name
The name of this type of tile.
Definition: ModTile.cs:25
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 RightClick(int i, int j)
Allows you to make something happen when this tile is right-clicked by the player.
Definition: ModTile.cs:468
int animationFrameHeight
The height of a group of animation frames for this tile. Defaults to 0, which disables animations.
Definition: ModTile.cs:62
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 PostSetDefaults()
Allows you to override some default properties of this tile, such as Main.tileNoSunLight and Main....
Definition: ModTile.cs:235
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 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 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
virtual void SpecialDraw(int i, int j, SpriteBatch spriteBatch)
Special Draw. Only called if coordinates are placed in Main.specX/Y during DrawEffects....
Definition: ModTile.cs:424
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
virtual string HighlightTexture
The highlight texture used when this tile is selected by smart interact. Defaults to adding "_Highlig...
Definition: ModTile.cs:42
virtual bool NewRightClick(int i, int j)
Allows you to make something happen when this tile is right-clicked by the player....
Definition: ModTile.cs:477
float mineResist
A multiplier describing how much this block resists harvesting. Higher values will make it take longe...
Definition: ModTile.cs:66
void SetModCactus(ModCactus cactus)
Allows this tile to grow the given modded cactus.
Definition: ModTile.cs:212
void AddToArray(ref int[] array)
A convenient method for adding this tile's Type to the given array. This can be used with the arrays ...
Definition: ModTile.cs:123
int dustType
The default type of dust made when this tile is hit. Defaults to 0.
Definition: ModTile.cs:54
virtual bool CanExplode(int i, int j)
Whether or not the tile at the given coordinates can be killed by an explosion (ie....
Definition: ModTile.cs:320
bool disableSmartInteract
Whether or not the smart tile interaction function is disabled when the cursor hovers above this tile...
Definition: ModTile.cs:78
int minPick
The minimum pickaxe power required for pickaxes to mine this block. Defaults to 0.
Definition: ModTile.cs:70
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
string chest
The default name of this chest that is displayed when this 2x2 chest is open. Defaults to the empty s...
Definition: ModTile.cs:94
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
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
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 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 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 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
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,...
Definition: ModTile.cs:169
bool torch
Whether or not this tile behaves like a torch. If you are making a torch tile, then setting this to t...
Definition: ModTile.cs:114
This class represents a type of modded tree. The tree will share a tile ID with the vanilla trees (5)...
This serves as the central class from which tile-related functions are supported and carried out.
Definition: TileLoader.cs:15
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...