tModLoader v2024.11
A mod to make and play Terraria mods
|
Represents a non-Player inventory, such as chests, portable storage, or NPC shops. More...
Inherits IFixLoadedData.
Public Member Functions | |
Chest (bool bank=false) | |
Create a new Chest with no name. | |
int | AddItemToShop (Item newItem) |
Adds an item to the first empty slot in this shop. More... | |
object | Clone () |
void | FixLoadedData () |
Calls Item.FixAgainstExploit on all of this chest's items. | |
void | SetupShop (int type) |
void | SetupShop (string shopName, NPC npc) |
override string | ToString () |
Static Public Member Functions | |
static int | AfterPlacement_Hook (int x, int y, int type=21, int style=0, int direction=1, int alternate=0) |
Registers a placed chest into the world. More... | |
static void | AskForChestToEatItem (Vector2 worldPosition, int duration) |
Visually opens the chest at worldPosition for duration ticks. More... | |
static bool | CanDestroyChest (int X, int Y) |
Determines if the chest at (X , Y ) can be destroyed. More... | |
static int | CreateChest (int X, int Y, int id=-1) |
Creates and registers a new chest into the world. More... | |
static bool | DestroyChest (int X, int Y) |
Attempts to destroy the chest at (X , Y ). More... | |
static void | DestroyChestDirect (int X, int Y, int id) |
Forcibly destroys the chest at (X , Y ) with ID id if it exists. Warning: This will destroy any items contained within the chest. More... | |
static int | FindChest (int X, int Y) |
Tries to find a Chest located at (X , Y ) (tile coordinates). More... | |
static int | FindChestByGuessing (int X, int Y) |
Tries to find the Chest associated with the tile at (X , Y ) (tile coordinates). More... | |
static int | FindEmptyChest (int x, int y, int type=21, int style=0, int direction=1, int alternate=0) |
Determines if a new chest can exist at tile coordinates (x , y ). More... | |
static List< int > | GetCurrentlyOpenChests () |
Gets a list of currently-open chests in the world. Never called on NetmodeID.MultiplayerClient. More... | |
static void | Initialize () |
static bool | IsLocked (int x, int y) |
Determines if the chest at Main.tile[x , y ] is locked. More... | |
static bool | IsLocked (int x, int y, Tile t) |
static bool | Lock (int X, int Y) |
Locks an unlocked chest. More... | |
static bool | NearOtherChests (int x, int y) |
Determines if there are any chests near the tile coordinates (x , y ). More... | |
static Item | PutItemInNearbyChest (Item item, Vector2 position) |
Attempts to move the given item into any chests near the given position. Cannot place items into a chest if IsPlayerInChest(int) or if that chest IsLocked(int, int) More... | |
static void | ServerPlaceItem (int plr, int slot) |
Attempts to move the item in plr 's inventory or Void Vault into nearby chests. Only called on NetmodeID.Server. More... | |
static void | SetupTravelShop () |
Sets up the NPCID.TravellingMerchant's shop. | |
static void | SetupTravelShop_AddToShop (int it, ref int added, ref int count) |
static void | SetupTravelShop_AdjustSlotRarities (int slotItemAttempts, ref int[] rarity) |
static bool | SetupTravelShop_CanAddItemToShop (int it) |
static void | SetupTravelShop_GetItem (Player playerWithHighestLuck, int[] rarity, ref int it, int minimumRarity=0) |
static void | SetupTravelShop_GetPainting (Player playerWithHighestLuck, int[] rarity, ref int it, int minimumRarity=0) |
static bool | Unlock (int X, int Y) |
Unlocks a locked chest. More... | |
static void | UpdateChestFrames () |
Visually updates all chests' frames. Chests that are being used (GetCurrentlyOpenChests) or eating an item (eatingAnimationTime) will not be opened. | |
static int | UsingChest (int i) |
Gets the Player currently using the given chest, if any. More... | |
static void | VisualizeChestTransfer (Vector2 position, Vector2 chestPosition, Item item, int amountMoved) |
Visually moves item from position to chestPosition . If called on NetmodeID.MultiplayerClient, sync the transfer to all clients. More... | |
static void | VisualizeChestTransfer_CoinsBatch (Vector2 position, Vector2 chestPosition, long coinsMoved) |
Visually moves coinsMoved worth of coins from position to chestPosition . If called on NetmodeID.MultiplayerClient, sync the transfer to all clients. More... | |
Public Attributes | |
bool | bankChest |
Unused. If true , this chest is a portable storage (such as ItemID.PiggyBank) linked to a player. | |
int | eatingAnimationTime |
The duration of this chest's eating animation in ticks. The eating animation plays when an item is quick-stacked into this chest. | |
int | frame |
The current frame of this chest's animation. | |
int | frameCounter |
The number of ticks this chest has been on its current frame value. | |
Item[] | item |
The items this chest contains. maxItems elements long. | |
string | name |
The player-assigned name of this chest. May not exceed MaxNameLength characters in length. | |
int | x |
The x-coordinate of this chest in the world, in tile coordinates. (Top left corner tile) | |
int | y |
The y-coordinate of this chest in the world, in tile coordinates. (Top left corner tile) | |
Static Public Attributes | |
static int[] | chestItemSpawn = new int[52] |
Associates a TileID.Containers style with the item type (Item.type) that is dropped when the chest is destroyed. maxChestTypes elements long. | |
static int[] | chestItemSpawn2 = new int[17] |
Associates a TileID.Containers2 style with the item type (Item.type) that is dropped when the chest is destroyed. maxChestTypes2 elements long. | |
const float | chestStackRange = 600f |
The maximum distance, in world coordinates, that a player can quick-stack items into chests. | |
static int[] | chestTypeToIcon = new int[52] |
Associates a TileID.Containers style with the item type (Item.type) that is shown when the chest is moused over. Differs from chestItemSpawn to show key items for locked chest styles. maxChestTypes elements long. | |
static int[] | chestTypeToIcon2 = new int[17] |
Associates a TileID.Containers2 style with the item type (Item.type) that is shown when the chest is moused over. maxChestTypes2 elements long. Differs from chestItemSpawn2 to show key items for locked chest styles. | |
static int[] | dresserItemSpawn = new int[43] |
Associates a TileID.Dressers style with the item type (Item.type) that is dropped when the dresser is destroyed. maxDresserTypes elements long. | |
static int[] | dresserTypeToIcon = new int[43] |
Associates a TileID.Dressers style with the item type (Item.type) that is shown when the dresser is moused over. maxDresserTypes elements long. | |
const int | maxChestTypes = 52 |
The number of vanilla chest styles contained in TileID.Containers. | |
const int | maxChestTypes2 = 17 |
The number of vanilla chest styles contained in TileID.Containers2. | |
const int | maxDresserTypes = 43 |
The number of vanilla dresser styles contained in TileID.Dressers. | |
const int | maxItems = 40 |
The maximum number of items chests can contain. | |
const int | MaxNameLength = 63 |
The maximum length that name is allowed to be. | |
int Chest.AddItemToShop | ( | Item | newItem | ) |
Adds an item to the first empty slot in this shop.
newItem | The item to add. |
0
if the item could not be added to the shop, or the index in item if the item was successfully added.
|
static |
Registers a placed chest into the world.
x | The x-coordinate to check, in tile coordinates. |
y | The y-coordinate to check, in tile coordinates. |
type | The tile type of the placed chest. |
style | The tile style of the placed chest. |
direction | Unused, but required for use with PlacementHook.hook. |
alternate | Unused, but required for use with PlacementHook.hook. |
-1
if there exists a chest in Main.chest at the coordinates (x , y ), or if Main.chest contains no null
elements.
|
static |
Visually opens the chest at worldPosition for duration ticks.
worldPosition | The position of the chest to ask, in world coordinates. |
duration | The duration of the eating animation in ticks. |
|
static |
Determines if the chest at (X , Y ) can be destroyed.
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
false
if a chest exists at (X , Y ) and if any element in that chest's item array is not Item.IsAir. Otherwise, returns true
.
|
static |
Creates and registers a new chest into the world.
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
id | The index in Main.chest that this chest should use. If id != -1 , placement cannot fail. |
-1
if id == -1
and FindEmptyChest(int, int, int, int, int, int) returns -1
. It is recommended to use WorldGen.PlaceChest(int, int, ushort, bool, int) to place chests into the world.
|
static |
Attempts to destroy the chest at (X , Y ).
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
false
if a chest exists at (X , Y ) and if any element in that chest's item array is not Item.IsAir. Otherwise, returns true
.
|
static |
Forcibly destroys the chest at (X , Y ) with ID id if it exists.
Warning: This will destroy any items contained within the chest.
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
id | The index in Main.chest of the chest to destroy. |
|
static |
Tries to find a Chest located at (X , Y ) (tile coordinates).
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
-1
if one doesn't exist.If you don't have the top-left corner of the chest tile, use FindChestByGuessing(int, int).
|
static |
Tries to find the Chest associated with the tile at (X , Y ) (tile coordinates).
X | The x-coordinate to check, in tile coordinates. |
Y | The y-coordinate to check, in tile coordinates. |
-1
if one doesn't exist.If you have the top-left corner of the chest tile, use FindChest(int, int).
|
static |
Determines if a new chest can exist at tile coordinates (x , y ).
x | The x-coordinate to check, in tile coordinates. |
y | The y-coordinate to check, in tile coordinates. |
type | Unused, but required for use with PlacementHook.hook. |
style | Unused, but required for use with PlacementHook.hook. |
direction | Unused, but required for use with PlacementHook.hook. |
alternate | Unused, but required for use with PlacementHook.hook. |
-1
if there exists a chest in Main.chest at the coordinates (x , y ), or if Main.chest contains no null
elements. null
element.
|
static |
Gets a list of currently-open chests in the world.
Never called on NetmodeID.MultiplayerClient.
|
static |
Determines if the chest at Main.tile[x , y ] is locked.
x | The x-coordinate of the chest to check, in tile coordinates. |
y | The y-coordinate of the chest to check, in tile coordinates. |
true
if the chest is locked, false
otherwise.
|
static |
x | |
y | |
t | The Tile at Main.tile[x , y ] |
|
static |
Locks an unlocked chest.
X | The x-coordinate of the unlocked chest, in tile coordinates. |
Y | The y-coordinate of the unlocked chest, in tile coordinates. |
true
if the chest successfully locked, false
otherwise.
|
static |
Determines if there are any chests near the tile coordinates (x , y ).
x | The x-coordinate to check, in tile coordinates. |
y | The y-coordinate to check, in tile coordinates. |
true
if any position in Main.tile within [-25, 25) tiles horizontally and [-8, 8) tiles vertically has a tile (Tile.HasTile) and if that tile's Tile.TileType is in TileID.Sets.BasicChest. Otherwise, returns false
.Attempts to move the given item into any chests near the given position. Cannot place items into a chest if IsPlayerInChest(int) or if that chest IsLocked(int, int)
item | The item to attempt moving. |
position | The position to attempt moving from. |
|
static |
Attempts to move the item in plr 's inventory or Void Vault into nearby chests.
Only called on NetmodeID.Server.
plr | The index of the Player in Main.player to try moving an item for. |
slot | The PlayerItemSlotID to move an item from. If slot < 58 , then that slot of plr 's inventory is moved. If slot >= PlayerItemSlotID.Bank4_0 && slot < PlayerItemSlotID.Bank4_0 + 40 , then that slot (minus PlayerItemSlotID.Bank4_0) of plr 's Void Vault is moved. Otherwise, no item is moved. |
It's recommended to use Player.QuickStackAllChests to handle this automatically.
|
static |
Unlocks a locked chest.
X | The x-coordinate of the locked chest, in tile coordinates. |
Y | The y-coordinate of the locked chest, in tile coordinates. |
true
if the chest successfully unlocked, false
otherwise.
|
static |
Gets the Player currently using the given chest, if any.
i | The index of the chest in Main.chest to check. |
-1
if no player is using this chest.
|
static |
Visually moves item from position to chestPosition .
If called on NetmodeID.MultiplayerClient, sync the transfer to all clients.
position | The original position of item in world coordinates. |
chestPosition | The position of the destination chest in world coordinates. |
item | The item to move. Only Item.type is read. |
amountMoved | Unused. |
|
static |
Visually moves coinsMoved worth of coins from position to chestPosition .
If called on NetmodeID.MultiplayerClient, sync the transfer to all clients.
position | The original position of the coins in world coordinates. |
chestPosition | The position of the destination chest in world coordinates. |
coinsMoved | The value of the coins moved in copper coins. |