TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ GetItemDrops()

virtual IEnumerable< Item > Terraria.ModLoader.ModTile.GetItemDrops ( int i,
int j )
inlinevirtualinherited

Allows customization of the items the tile at the given coordinates drops.

The default item drop is determined by finding an item with F:Terraria.Item.createTile and F:Terraria.Item.placeStyle matching the type and style of this tile. M:Terraria.ModLoader.ModTile.RegisterItemDrop(System.Int32,System.Int32[]) can be used to manually register item drops for tile styles with no corresponding item. It can also be used to register a fallback item, which will be dropped if no suitable item is found.

The default behavior should cover 99% of use cases, meaning that overriding this method should only be necessary in extremely unique tiles, such as tiles dropping multiple items, tiles dropping items with custom data, or tiles with custom tile style code.

When overriding, use yield return new Item(ItemTypeHere); for each spawned item. Note that a random prefix will be applied to these items, if applicable, so if specific prefixes or no prefix is needed for an item drop, it will have to be spawned in manually using M:Terraria.ModLoader.ModTile.KillMultiTile(System.Int32,System.Int32,System.Int32,System.Int32) or M:Terraria.ModLoader.ModTile.KillTile(System.Int32,System.Int32,System.Boolean@,System.Boolean@,System.Boolean@).

The style based drop logic is based on T:Terraria.ObjectData.TileObjectData. If a tile has custom 'styles' but still wants to make use of M:Terraria.ModLoader.ModTile.RegisterItemDrop(System.Int32,System.Int32[]), TileLoader.GetItemDropFromTypeAndStyle(Type, style) can be used to retrieve the associated item drop.

Use M:Terraria.ModLoader.ModTile.CanDrop(System.Int32,System.Int32) to conditionally prevent any item drops. Use M:Terraria.ModLoader.ModTile.KillMultiTile(System.Int32,System.Int32,System.Int32,System.Int32) or M:Terraria.ModLoader.ModTile.KillTile(System.Int32,System.Int32,System.Boolean@,System.Boolean@,System.Boolean@) for other logic such as cleaning up TileEntities or killing chests or signs.

Parameters
iThe x position in tile coordinates.
jThe y position in tile coordinates.

Definition at line 247 of file ModTile.cs.

248 {
249 Tile tile = Main.tile[i, j];
250 int style = TileObjectData.GetTileStyle(tile);
251 if (style == -1)
252 {
253 style = 0;
254 }
255 int dropItem = TileLoader.GetItemDropFromTypeAndStyle(tile.type, style);
256 if (dropItem > 0)
257 {
258 return new Item[1]
259 {
260 new Item(dropItem)
261 };
262 }
263 return null;
264 }
static int GetTileStyle(Tile getTile)

References Terraria.ModLoader.TileLoader.GetItemDropFromTypeAndStyle(), Terraria.ObjectData.TileObjectData.GetTileStyle(), Terraria.Main.tile, and Terraria.Tile.type.

+ Here is the call graph for this function: