TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
MinecartDiggerHelper.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
3using Terraria.ID;
4
6
8{
10
11 public void TryDigging(Player player, Vector2 trackWorldPosition, int digDirectionX, int digDirectionY)
12 {
13 //IL_0003: Unknown result type (might be due to invalid IL or missing references)
14 //IL_0004: Unknown result type (might be due to invalid IL or missing references)
15 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
16 //IL_000a: Unknown result type (might be due to invalid IL or missing references)
17 //IL_0021: Unknown result type (might be due to invalid IL or missing references)
18 //IL_0030: Unknown result type (might be due to invalid IL or missing references)
19 //IL_0031: Unknown result type (might be due to invalid IL or missing references)
20 //IL_004c: Unknown result type (might be due to invalid IL or missing references)
21 //IL_004d: Unknown result type (might be due to invalid IL or missing references)
22 //IL_005a: Unknown result type (might be due to invalid IL or missing references)
23 //IL_005b: Unknown result type (might be due to invalid IL or missing references)
24 //IL_0061: Unknown result type (might be due to invalid IL or missing references)
25 //IL_0069: Unknown result type (might be due to invalid IL or missing references)
26 //IL_009a: Unknown result type (might be due to invalid IL or missing references)
27 //IL_009b: Unknown result type (might be due to invalid IL or missing references)
28 //IL_009c: Unknown result type (might be due to invalid IL or missing references)
29 //IL_009d: Unknown result type (might be due to invalid IL or missing references)
30 //IL_00ad: Unknown result type (might be due to invalid IL or missing references)
31 //IL_00b6: Unknown result type (might be due to invalid IL or missing references)
32 //IL_0076: Unknown result type (might be due to invalid IL or missing references)
33 //IL_0077: Unknown result type (might be due to invalid IL or missing references)
34 //IL_007d: Unknown result type (might be due to invalid IL or missing references)
35 //IL_0085: Unknown result type (might be due to invalid IL or missing references)
36 //IL_00e3: Unknown result type (might be due to invalid IL or missing references)
37 //IL_00f4: Unknown result type (might be due to invalid IL or missing references)
38 //IL_00fd: Unknown result type (might be due to invalid IL or missing references)
39 //IL_011a: Unknown result type (might be due to invalid IL or missing references)
40 //IL_012a: Unknown result type (might be due to invalid IL or missing references)
41 //IL_0130: Unknown result type (might be due to invalid IL or missing references)
42 //IL_0161: Unknown result type (might be due to invalid IL or missing references)
43 //IL_0162: Unknown result type (might be due to invalid IL or missing references)
44 //IL_016b: Unknown result type (might be due to invalid IL or missing references)
45 //IL_016c: Unknown result type (might be due to invalid IL or missing references)
46 digDirectionY = 0;
47 Point point = trackWorldPosition.ToTileCoordinates();
48 if (Framing.GetTileSafely(point).type != 314 || (double)point.Y < Main.worldSurface)
49 {
50 return;
51 }
52 Point point2 = point;
53 point2.X += digDirectionX;
54 point2.Y += digDirectionY;
55 if (AlreadyLeadsIntoWantedTrack(point, point2) || (digDirectionY == 0 && (AlreadyLeadsIntoWantedTrack(point, new Point(point2.X, point2.Y - 1)) || AlreadyLeadsIntoWantedTrack(point, new Point(point2.X, point2.Y + 1)))))
56 {
57 return;
58 }
59 int num = 5;
60 if (digDirectionY != 0)
61 {
62 num = 5;
63 }
64 Point point3 = point2;
65 Point point4 = point3;
66 point4.Y -= num - 1;
67 int x = point4.X;
68 for (int i = point4.Y; i <= point3.Y; i++)
69 {
70 if (!CanGetPastTile(x, i) || !HasPickPower(player, x, i))
71 {
72 return;
73 }
74 }
75 if (CanConsumeATrackItem(player))
76 {
77 int x2 = point4.X;
78 for (int j = point4.Y; j <= point3.Y; j++)
79 {
81 }
82 ConsumeATrackItem(player);
84 player.velocity.X = MathHelper.Clamp(player.velocity.X, -1f, 1f);
86 {
88 }
89 }
90 }
91
92 private bool CanConsumeATrackItem(Player player)
93 {
94 return FindMinecartTrackItem(player) != null;
95 }
96
97 private void ConsumeATrackItem(Player player)
98 {
99 Item item = FindMinecartTrackItem(player);
100 item.stack--;
101 if (item.stack == 0)
102 {
103 item.TurnToAir();
104 }
105 }
106
108 {
109 Item result = null;
110 for (int i = 0; i < 58; i++)
111 {
112 if (player.selectedItem != i || (player.itemAnimation <= 0 && player.reuseDelay <= 0 && player.itemTime <= 0))
113 {
114 Item item = player.inventory[i];
115 if (item.type == 2340 && item.stack > 0)
116 {
117 result = item;
118 break;
119 }
120 }
121 }
122 return result;
123 }
124
125 private void PoundTrack(Point spot)
126 {
127 //IL_0005: Unknown result type (might be due to invalid IL or missing references)
128 //IL_000b: Unknown result type (might be due to invalid IL or missing references)
129 //IL_0026: Unknown result type (might be due to invalid IL or missing references)
130 //IL_002c: Unknown result type (might be due to invalid IL or missing references)
131 //IL_004a: Unknown result type (might be due to invalid IL or missing references)
132 //IL_0051: Unknown result type (might be due to invalid IL or missing references)
133 if (Main.tile[spot.X, spot.Y].type == 314 && Minecart.FrameTrack(spot.X, spot.Y, pound: true) && Main.netMode == 1)
134 {
135 NetMessage.SendData(17, -1, -1, null, 15, spot.X, spot.Y, 1f);
136 }
137 }
138
140 {
141 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
142 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
143 //IL_0042: Unknown result type (might be due to invalid IL or missing references)
144 //IL_0043: Unknown result type (might be due to invalid IL or missing references)
145 //IL_0051: Unknown result type (might be due to invalid IL or missing references)
146 //IL_005d: Unknown result type (might be due to invalid IL or missing references)
149 if (!tileSafely.active() || tileSafely.type != 314)
150 {
151 return false;
152 }
153 if (!tileSafely2.active() || tileSafely2.type != 314)
154 {
155 return false;
156 }
159 {
160 return false;
161 }
163 {
164 return false;
165 }
166 return true;
167 }
168
170 {
171 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
172 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
173 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
174 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
175 int num = endCoords.Y - startCoords.Y;
176 int num2 = endCoords.X - startCoords.X;
177 expectedStartLeft = null;
178 expectedStartRight = null;
179 expectedEndLeft = null;
180 expectedEndRight = null;
181 if (num2 == -1)
182 {
185 }
186 if (num2 == 1)
187 {
190 }
191 }
192
194 {
195 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
196 //IL_0002: Unknown result type (might be due to invalid IL or missing references)
198 }
199
201 {
202 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
203 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
204 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
205 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
206 //IL_0037: Unknown result type (might be due to invalid IL or missing references)
207 //IL_0057: Unknown result type (might be due to invalid IL or missing references)
211 if (tileSafely.active() && tileSafely.type == 314)
212 {
214 }
215 if (tileSafely2.active() && tileSafely2.type == 314)
216 {
218 }
219 }
220
221 private bool HasPickPower(Player player, int x, int y)
222 {
223 if (player.HasEnoughPickPowerToHurtTile(x, y))
224 {
225 return true;
226 }
227 return false;
228 }
229
230 private bool CanGetPastTile(int x, int y)
231 {
232 if (WorldGen.CheckTileBreakability(x, y) != 0)
233 {
234 return false;
235 }
237 {
238 return false;
239 }
240 Tile tile = Main.tile[x, y];
241 if (tile.active() && (TileID.Sets.Falling[tile.type] || (tile.type == 26 && !Main.hardMode) || !WorldGen.CanKillTile(x, y)))
242 {
243 return false;
244 }
245 return true;
246 }
247
248 private void PlaceATrack(int x, int y)
249 {
250 int num = 314;
251 int num2 = 0;
252 if (WorldGen.PlaceTile(x, y, num, mute: false, forced: false, Main.myPlayer, num2))
253 {
254 NetMessage.SendData(17, -1, -1, null, 1, x, y, num, num2);
255 }
256 }
257
258 private void MineTheTileIfNecessary(int x, int y)
259 {
260 AchievementsHelper.CurrentlyMining = true;
261 if (Main.tile[x, y].active())
262 {
263 WorldGen.KillTile(x, y);
264 NetMessage.SendData(17, -1, -1, null, 0, x, y);
265 }
266 AchievementsHelper.CurrentlyMining = false;
267 }
268}
Vector2 velocity
The velocity of this Entity in world coordinates per tick.
Definition Entity.cs:33
static Tile GetTileSafely(Vector2 position)
Definition Framing.cs:421
void TryDigging(Player player, Vector2 trackWorldPosition, int digDirectionX, int digDirectionY)
bool DoTheTracksConnectProperly(Point tileCoordsOfFrontWheel, Point tileCoordsWeWantToReach)
static void GetExpectedDirections(Point startCoords, Point endCoords, out int? expectedStartLeft, out int? expectedStartRight, out int? expectedEndLeft, out int? expectedEndRight)
bool HasPickPower(Player player, int x, int y)
void CorrectTrackConnections(Point startCoords, Point endCoords)
bool AlreadyLeadsIntoWantedTrack(Point tileCoordsOfFrontWheel, Point tileCoordsWeWantToReach)
static bool[] Falling
Definition TileID.cs:368
int stack
The current stack of the item. F:Terraria.Item.maxStack indicates the max possible stack.
Definition Item.cs:396
void TurnToAir(bool fullReset=false)
Definition Item.cs:51791
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 double worldSurface
The y-coordinate of the top of the dirt layer, in tile coordinates. Corresponds to 0' on the Depth Me...
Definition Main.cs:1351
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 bool hardMode
Definition Main.cs:1091
static bool FrameTrack(int i, int j, bool pound, bool mute=false)
Definition Minecart.cs:1105
static void TryFittingTileOrientation(Point tileCoords, int? expectedYOffsetForLeft, int? expectedYOffsetForRight)
Definition Minecart.cs:1788
static bool GetAreExpectationsForSidesMet(Point tileCoords, int? expectedYOffsetForLeft, int? expectedYOffsetForRight)
Definition Minecart.cs:1762
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)
bool HasEnoughPickPowerToHurtTile(int x, int y)
Definition Player.cs:54467
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 KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static bool CanKillTile(int i, int j, SpecialKillTileContext context)
static int CheckTileBreakability(int x, int y)
static bool CheckTileBreakability2_ShouldTileSurvive(int x, int y)
ref ushort type
Legacy code, use P:Terraria.Tile.TileType instead.
Definition Tile.cs:522
bool active()
Legacy code, use P:Terraria.Tile.HasTile instead.
Definition Tile.cs:999
A data structure used for accessing information about tiles, walls, wires, and liquids at a single po...
Definition Tile.cs:15