TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
TEFoodPlatter.cs
Go to the documentation of this file.
1using System.IO;
2using Microsoft.Xna.Framework;
4using Terraria.ID;
7
9
11{
12 private static byte _myEntityID;
13
14 public Item item;
15
16 public override void RegisterTileEntityID(int assignedID)
17 {
18 _myEntityID = (byte)assignedID;
19 }
20
21 public override void NetPlaceEntityAttempt(int x, int y)
22 {
23 NetPlaceEntity(x, y);
24 }
25
26 public static void NetPlaceEntity(int x, int y)
27 {
28 int number = Place(x, y);
29 NetMessage.SendData(86, -1, -1, null, number, x, y);
30 }
31
32 public override TileEntity GenerateInstance()
33 {
34 return new TEFoodPlatter();
35 }
36
38 {
39 item = new Item();
40 }
41
42 public static int Place(int x, int y)
43 {
45 tEFoodPlatter.Position = new Point16(x, y);
46 tEFoodPlatter.ID = TileEntity.AssignNewID();
47 tEFoodPlatter.type = _myEntityID;
49 {
52 }
53 return tEFoodPlatter.ID;
54 }
55
56 public override bool IsTileValidForEntity(int x, int y)
57 {
58 return ValidTile(x, y);
59 }
60
61 public static int Hook_AfterPlacement(int x, int y, int type = 520, int style = 0, int direction = 1, int alternate = 0)
62 {
63 if (Main.netMode == 1)
64 {
66 NetMessage.SendData(87, -1, -1, null, x, y, (int)_myEntityID);
67 return -1;
68 }
69 return Place(x, y);
70 }
71
72 public static void Kill(int x, int y)
73 {
74 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
75 {
77 {
78 TileEntity.ByID.Remove(value.ID);
79 TileEntity.ByPosition.Remove(new Point16(x, y));
80 }
81 }
82 }
83
84 public static int Find(int x, int y)
85 {
86 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
87 {
88 return value.ID;
89 }
90 return -1;
91 }
92
93 public static bool ValidTile(int x, int y)
94 {
95 if (!Main.tile[x, y].active() || Main.tile[x, y].type != 520 || Main.tile[x, y].frameY != 0)
96 {
97 return false;
98 }
99 return true;
100 }
101
102 public override void WriteExtraData(BinaryWriter writer, bool networkSend)
103 {
106 writer.Write((short)item.stack);
107 }
108
109 public override void ReadExtraData(BinaryReader reader, bool networkSend)
110 {
111 item = new Item();
112 item.netDefaults(reader.ReadInt16());
113 item.Prefix(reader.ReadByte());
114 item.stack = reader.ReadInt16();
115 }
116
117 public override string ToString()
118 {
119 return Position.X + "x " + Position.Y + "y item: " + item;
120 }
121
122 public void DropItem()
123 {
124 if (Main.netMode != 1)
125 {
127 }
128 item = new Item();
129 }
130
131 public static void TryPlacing(int x, int y, Item item, int stack)
132 {
133 //IL_002d: Unknown result type (might be due to invalid IL or missing references)
134 WorldGen.RangeFrame(x, y, x + 1, y + 1);
135 int num = Find(x, y);
136 if (num == -1)
137 {
138 Item.NewItem((IEntitySource)new EntitySource_TileBreak(x, y), new Rectangle(x * 16, y * 16, 16, 16), item, noBroadcast: false, noGrabDelay: false, reverseLookup: false);
139 return;
140 }
142 if (tEFoodPlatter.item.stack > 0)
143 {
144 tEFoodPlatter.DropItem();
145 }
146 tEFoodPlatter.item = ItemLoader.TransferWithLimit(item, stack);
147 NetMessage.SendData(86, -1, -1, null, tEFoodPlatter.ID, x, y);
148 }
149
150 public static void OnPlayerInteraction(Player player, int clickX, int clickY)
151 {
152 if (FitsFoodPlatter(player.inventory[player.selectedItem]) && !player.inventory[player.selectedItem].favorited)
153 {
157 return;
158 }
159 int num = Find(clickX, clickY);
160 if (num != -1 && ((TEFoodPlatter)TileEntity.ByID[num]).item.stack > 0)
161 {
164 if (Main.netMode == 1)
165 {
166 NetMessage.SendData(17, -1, -1, null, 0, clickX, clickY, 1f);
167 }
168 }
169 }
170
171 public static bool FitsFoodPlatter(Item i)
172 {
173 if (i.stack > 0)
174 {
175 return ItemID.Sets.IsFood[i.type];
176 }
177 return false;
178 }
179
180 public static void PlaceItemInFrame(Player player, int x, int y)
181 {
182 if (!player.ItemTimeIsZero)
183 {
184 return;
185 }
186 int num = Find(x, y);
187 if (num == -1)
188 {
189 return;
190 }
191 if (((TEFoodPlatter)TileEntity.ByID[num]).item.stack > 0)
192 {
193 WorldGen.KillTile(x, y, fail: true);
194 if (Main.netMode == 1)
195 {
196 NetMessage.SendData(17, -1, -1, null, 0, Player.tileTargetX, y, 1f);
197 }
198 }
199 if (Main.netMode == 1)
200 {
201 NetMessage.SendData(133, -1, -1, null, x, y, player.selectedItem, player.whoAmI, 1);
203 }
204 else
205 {
206 TryPlacing(x, y, player.inventory[player.selectedItem], 1);
207 }
208 if (player.selectedItem == 58)
209 {
210 Main.mouseItem = player.inventory[player.selectedItem].Clone();
211 }
212 player.releaseUseItem = false;
213 player.mouseInterface = true;
214 WorldGen.RangeFrame(x, y, x + 1, y + 1);
215 }
216
217 public void FixLoadedData()
218 {
220 }
221
222 public override void SaveData(TagCompound tag)
223 {
224 tag["item"] = ItemIO.Save(item);
225 }
226
227 public override void LoadData(TagCompound tag)
228 {
229 item = ItemIO.Load(tag.GetCompound("item"));
230 }
231
232 public override void NetSend(BinaryWriter writer)
233 {
234 ItemIO.Send(item, writer, writeStack: true);
235 }
236
237 public override void NetReceive(BinaryReader reader)
238 {
239 item = ItemIO.Receive(reader, readStack: true);
240 }
241}
static Dictionary< int, TileEntity > ByID
Definition TileEntity.cs:20
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:22
int whoAmI
The index of this Entity within its specific array. These arrays track the entities in the world....
Definition Entity.cs:16
static void PlaceItemInFrame(Player player, int x, int y)
override void NetPlaceEntityAttempt(int x, int y)
override void LoadData(TagCompound tag)
Allows you to load custom data that you have saved for this tile entity. Try to write defensive load...
static void TryPlacing(int x, int y, Item item, int stack)
override void RegisterTileEntityID(int assignedID)
override void NetSend(BinaryWriter writer)
Allows you to send custom data for this tile entity between client and server, which will be handled ...
static void OnPlayerInteraction(Player player, int clickX, int clickY)
override void ReadExtraData(BinaryReader reader, bool networkSend)
override void SaveData(TagCompound tag)
Allows you to save custom data for this tile entity. NOTE: The provided tag is always empty by def...
static int Hook_AfterPlacement(int x, int y, int type=520, int style=0, int direction=1, int alternate=0)
override void NetReceive(BinaryReader reader)
Receives custom data sent in the M:Terraria.DataStructures.TileEntity.NetSend(System....
override void WriteExtraData(BinaryWriter writer, bool networkSend)
override bool IsTileValidForEntity(int x, int y)
static bool[] IsFood
If true for a given item type (F:Terraria.Item.type), then that item is food. Food items can be pla...
Definition ItemID.cs:446
Item Clone()
Definition Item.cs:51739
void netDefaults(int type)
Definition Item.cs:1927
int stack
The current stack of the item. F:Terraria.Item.maxStack indicates the max possible stack.
Definition Item.cs:396
bool Prefix(int prefixWeWant)
Attempts to apply a prefix to this T:Terraria.Item.
Definition Item.cs:1279
bool favorited
If true, then the given item is favorited. Favorited items cannot be dropped, automatically moved in...
Definition Item.cs:354
static int NewItem(IEntitySource source, Vector2 pos, Vector2 randomBox, int Type, int Stack=1, bool noBroadcast=false, int prefixGiven=0, bool noGrabDelay=false, bool reverseLookup=false)
This particular overload uses two Vector2 to determine the actual spawn position.
Definition Item.cs:51478
void FixAgainstExploit()
Definition Item.cs:49916
int type
The Item ID of this item. The Item ID is a unique number assigned to each Item loaded into the game....
Definition Item.cs:345
static int myPlayer
The index in F:Terraria.Main.player of this client's Player. If this is 255, this client is the ser...
Definition Main.cs:1958
static int netMode
Denotes the current network mode: 0 for single player client, 1 for multiplayer client,...
Definition Main.cs:2182
static Tilemap tile
Definition Main.cs:1820
static void WriteByteVanillaPrefix(Item item, BinaryWriter writer)
Definition ItemIO.cs:38
static TagCompound Save(Item item)
Definition ItemIO.cs:48
static void Receive(Item item, BinaryReader reader, bool readStack=false, bool readFavorite=false)
Definition ItemIO.cs:217
static void Load(Item item, TagCompound tag)
Definition ItemIO.cs:98
static void WriteShortVanillaID(Item item, BinaryWriter writer)
Definition ItemIO.cs:18
static void Send(Item item, BinaryWriter writer, bool writeStack=false, bool writeFavorite=false)
Definition ItemIO.cs:202
Tag compounds contained named values, serialisable as per the NBT spec: NBT spec wiki page All primi...
static Item TransferWithLimit(Item source, int limit)
Extract up to limit items from source . If some items remain, M:Terraria.ModLoader....
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
static void SendData(int msgType, int remoteClient=-1, int ignoreClient=-1, NetworkText text=null, int number=0, float number2=0f, float number3=0f, float number4=0f, int number5=0, int number6=0, int number7=0)
static void SendTileSquare(int whoAmi, int tileX, int tileY, int xSize, int ySize, TileChangeType changeType=TileChangeType.None)
void GamepadEnableGrappleCooldown()
Definition Player.cs:22476
bool ItemTimeIsZero
Definition Player.cs:4402
static int tileTargetX
Definition Player.cs:2650
Item[] inventory
The player's normal inventory. Indexes 0-9 hold the hotbar items, 10-49 the rest of the main inventor...
Definition Player.cs:1767
static void FindRecipes(bool canDelayCheck=false)
Definition Recipe.cs:486
A Recipe is a collection of ingredients, tiles, and a resulting Item. This is how players can craft i...
Definition Recipe.cs:22
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static void RangeFrame(int startX, int startY, int endX, int endY)
This object encapsulates context information about the source of a particular spawning event of an It...