Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TileObject.cs
Go to the documentation of this file.
6using Terraria.ID;
8
9namespace Terraria;
10
11public struct TileObject
12{
13 public int xCoord;
14
15 public int yCoord;
16
17 public int type;
18
19 public int style;
20
21 public int alternate;
22
23 public int random;
24
25 public static TileObject Empty = default(TileObject);
26
28
29 public static bool Place(TileObject toBePlaced)
30 {
31 TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
32 if (tileData == null)
33 {
34 return false;
35 }
36 if (tileData.HookPlaceOverride.hook != null)
37 {
38 int arg;
39 int arg2;
41 {
42 arg = toBePlaced.xCoord;
43 arg2 = toBePlaced.yCoord;
44 }
45 else
46 {
47 arg = toBePlaced.xCoord + tileData.Origin.X;
48 arg2 = toBePlaced.yCoord + tileData.Origin.Y;
49 }
50 if (tileData.HookPlaceOverride.hook(arg, arg2, toBePlaced.type, toBePlaced.style, 1, toBePlaced.alternate) == tileData.HookPlaceOverride.badReturn)
51 {
52 return false;
53 }
54 }
55 else
56 {
57 ushort num = (ushort)toBePlaced.type;
58 int num2 = 0;
59 int num3 = 0;
60 int num4 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
61 int num5 = 0;
62 if (tileData.StyleWrapLimit > 0)
63 {
64 num5 = num4 / tileData.StyleWrapLimit * tileData.StyleLineSkip;
65 num4 %= tileData.StyleWrapLimit;
66 }
67 if (tileData.StyleHorizontal)
68 {
69 num2 = tileData.CoordinateFullWidth * num4;
70 num3 = tileData.CoordinateFullHeight * num5;
71 }
72 else
73 {
74 num2 = tileData.CoordinateFullWidth * num5;
75 num3 = tileData.CoordinateFullHeight * num4;
76 }
77 int num6 = toBePlaced.xCoord;
78 int num7 = toBePlaced.yCoord;
79 for (int i = 0; i < tileData.Width; i++)
80 {
81 for (int j = 0; j < tileData.Height; j++)
82 {
83 Tile tileSafely = Framing.GetTileSafely(num6 + i, num7 + j);
84 if (tileSafely.active() && tileSafely.type != 484 && (Main.tileCut[tileSafely.type] || TileID.Sets.BreakableWhenPlacing[tileSafely.type]))
85 {
86 WorldGen.KillTile(num6 + i, num7 + j);
87 if (!Main.tile[num6 + i, num7 + j].active() && Main.netMode != 0)
88 {
89 NetMessage.SendData(17, -1, -1, null, 0, num6 + i, num7 + j);
90 }
91 }
92 }
93 }
94 for (int k = 0; k < tileData.Width; k++)
95 {
96 int num8 = num2 + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
97 int num9 = num3;
98 for (int l = 0; l < tileData.Height; l++)
99 {
100 Tile tileSafely2 = Framing.GetTileSafely(num6 + k, num7 + l);
101 if (!tileSafely2.active())
102 {
103 tileSafely2.active(active: true);
104 tileSafely2.frameX = (short)num8;
105 tileSafely2.frameY = (short)num9;
106 tileSafely2.type = num;
107 }
108 num9 += tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
109 }
110 }
111 }
112 if (tileData.FlattenAnchors)
113 {
114 AnchorData anchorBottom = tileData.AnchorBottom;
115 if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
116 {
117 int num10 = toBePlaced.xCoord + anchorBottom.checkStart;
118 int j2 = toBePlaced.yCoord + tileData.Height;
119 for (int m = 0; m < anchorBottom.tileCount; m++)
120 {
121 Tile tileSafely3 = Framing.GetTileSafely(num10 + m, j2);
122 if (Main.tileSolid[tileSafely3.type] && !Main.tileSolidTop[tileSafely3.type] && tileSafely3.blockType() != 0)
123 {
124 WorldGen.SlopeTile(num10 + m, j2);
125 }
126 }
127 }
128 anchorBottom = tileData.AnchorTop;
129 if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
130 {
131 int num11 = toBePlaced.xCoord + anchorBottom.checkStart;
132 int j3 = toBePlaced.yCoord - 1;
133 for (int n = 0; n < anchorBottom.tileCount; n++)
134 {
135 Tile tileSafely4 = Framing.GetTileSafely(num11 + n, j3);
136 if (Main.tileSolid[tileSafely4.type] && !Main.tileSolidTop[tileSafely4.type] && tileSafely4.blockType() != 0)
137 {
138 WorldGen.SlopeTile(num11 + n, j3);
139 }
140 }
141 }
142 anchorBottom = tileData.AnchorRight;
143 if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
144 {
145 int i2 = toBePlaced.xCoord + tileData.Width;
146 int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
147 for (int num13 = 0; num13 < anchorBottom.tileCount; num13++)
148 {
149 Tile tileSafely5 = Framing.GetTileSafely(i2, num12 + num13);
150 if (Main.tileSolid[tileSafely5.type] && !Main.tileSolidTop[tileSafely5.type] && tileSafely5.blockType() != 0)
151 {
152 WorldGen.SlopeTile(i2, num12 + num13);
153 }
154 }
155 }
156 anchorBottom = tileData.AnchorLeft;
157 if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
158 {
159 int i3 = toBePlaced.xCoord - 1;
160 int num14 = toBePlaced.yCoord + anchorBottom.checkStart;
161 for (int num15 = 0; num15 < anchorBottom.tileCount; num15++)
162 {
163 Tile tileSafely6 = Framing.GetTileSafely(i3, num14 + num15);
164 if (Main.tileSolid[tileSafely6.type] && !Main.tileSolidTop[tileSafely6.type] && tileSafely6.blockType() != 0)
165 {
166 WorldGen.SlopeTile(i3, num14 + num15);
167 }
168 }
169 }
170 }
171 return true;
172 }
173
174 public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false, int? forcedRandom = null)
175 {
177 objectData = Empty;
178 if (tileData == null)
179 {
180 return false;
181 }
182 int num = x - tileData.Origin.X;
183 int num2 = y - tileData.Origin.Y;
184 if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
185 {
186 return false;
187 }
188 bool flag = tileData.RandomStyleRange > 0;
190 {
191 TileObjectPreviewData.placementCache = new TileObjectPreviewData();
192 }
194 int num3 = 0;
195 if (tileData.AlternatesCount != 0)
196 {
197 num3 = tileData.AlternatesCount;
198 }
199 float num4 = -1f;
200 float num5 = -1f;
201 int num6 = 0;
202 TileObjectData tileObjectData = null;
203 int num7 = -1;
204 while (num7 < num3)
205 {
206 num7++;
208 if (tileData2.Direction != 0 && ((tileData2.Direction == TileObjectDirection.PlaceLeft && dir == 1) || (tileData2.Direction == TileObjectDirection.PlaceRight && dir == -1)))
209 {
210 continue;
211 }
212 int num8 = x - tileData2.Origin.X;
213 int num9 = y - tileData2.Origin.Y;
214 if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5)
215 {
216 return false;
217 }
218 Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
219 int num10 = 0;
220 int num11 = 0;
221 if (tileData2.AnchorTop.tileCount != 0)
222 {
223 if (rectangle.Y == 0)
224 {
225 rectangle.Y = -1;
226 rectangle.Height++;
227 num11++;
228 }
229 int checkStart = tileData2.AnchorTop.checkStart;
230 if (checkStart < rectangle.X)
231 {
232 rectangle.Width += rectangle.X - checkStart;
233 num10 += rectangle.X - checkStart;
234 rectangle.X = checkStart;
235 }
236 int num12 = checkStart + tileData2.AnchorTop.tileCount - 1;
237 int num13 = rectangle.X + rectangle.Width - 1;
238 if (num12 > num13)
239 {
240 rectangle.Width += num12 - num13;
241 }
242 }
243 if (tileData2.AnchorBottom.tileCount != 0)
244 {
245 if (rectangle.Y + rectangle.Height == tileData2.Height)
246 {
247 rectangle.Height++;
248 }
249 int checkStart2 = tileData2.AnchorBottom.checkStart;
250 if (checkStart2 < rectangle.X)
251 {
252 rectangle.Width += rectangle.X - checkStart2;
253 num10 += rectangle.X - checkStart2;
254 rectangle.X = checkStart2;
255 }
256 int num14 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
257 int num15 = rectangle.X + rectangle.Width - 1;
258 if (num14 > num15)
259 {
260 rectangle.Width += num14 - num15;
261 }
262 }
263 if (tileData2.AnchorLeft.tileCount != 0)
264 {
265 if (rectangle.X == 0)
266 {
267 rectangle.X = -1;
268 rectangle.Width++;
269 num10++;
270 }
271 int num16 = tileData2.AnchorLeft.checkStart;
272 if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
273 {
274 num16--;
275 }
276 if (num16 < rectangle.Y)
277 {
278 rectangle.Width += rectangle.Y - num16;
279 num11 += rectangle.Y - num16;
280 rectangle.Y = num16;
281 }
282 int num17 = num16 + tileData2.AnchorLeft.tileCount - 1;
283 if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
284 {
285 num17 += 2;
286 }
287 int num18 = rectangle.Y + rectangle.Height - 1;
288 if (num17 > num18)
289 {
290 rectangle.Height += num17 - num18;
291 }
292 }
293 if (tileData2.AnchorRight.tileCount != 0)
294 {
295 if (rectangle.X + rectangle.Width == tileData2.Width)
296 {
297 rectangle.Width++;
298 }
299 int num19 = tileData2.AnchorLeft.checkStart;
300 if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
301 {
302 num19--;
303 }
304 if (num19 < rectangle.Y)
305 {
306 rectangle.Width += rectangle.Y - num19;
307 num11 += rectangle.Y - num19;
308 rectangle.Y = num19;
309 }
310 int num20 = num19 + tileData2.AnchorRight.tileCount - 1;
311 if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
312 {
313 num20 += 2;
314 }
315 int num21 = rectangle.Y + rectangle.Height - 1;
316 if (num20 > num21)
317 {
318 rectangle.Height += num20 - num21;
319 }
320 }
321 if (onlyCheck)
322 {
323 objectPreview.Reset();
324 objectPreview.Active = true;
325 objectPreview.Type = (ushort)type;
326 objectPreview.Style = (short)style;
327 objectPreview.Alternate = num7;
328 objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
329 objectPreview.ObjectStart = new Point16(num10, num11);
330 objectPreview.Coordinates = new Point16(num8 - num10, num9 - num11);
331 }
332 float num22 = 0f;
333 float num23 = tileData2.Width * tileData2.Height;
334 float num24 = 0f;
335 float num25 = 0f;
336 for (int i = 0; i < tileData2.Width; i++)
337 {
338 for (int j = 0; j < tileData2.Height; j++)
339 {
340 Tile tileSafely = Framing.GetTileSafely(num8 + i, num9 + j);
341 bool flag2 = !tileData2.LiquidPlace(tileSafely);
342 bool flag3 = false;
343 if (tileData2.AnchorWall)
344 {
345 num25 += 1f;
346 if (!tileData2.isValidWallAnchor(tileSafely.wall))
347 {
348 flag3 = true;
349 }
350 else
351 {
352 num24 += 1f;
353 }
354 }
355 bool flag4 = false;
356 if (tileSafely.active() && (!Main.tileCut[tileSafely.type] || tileSafely.type == 484 || tileSafely.type == 654) && !TileID.Sets.BreakableWhenPlacing[tileSafely.type])
357 {
358 flag4 = true;
359 }
360 if (flag4 || flag2 || flag3)
361 {
362 if (onlyCheck)
363 {
364 objectPreview[i + num10, j + num11] = 2;
365 }
366 continue;
367 }
368 if (onlyCheck)
369 {
370 objectPreview[i + num10, j + num11] = 1;
371 }
372 num22 += 1f;
373 }
374 }
375 AnchorData anchorBottom = tileData2.AnchorBottom;
376 if (anchorBottom.tileCount != 0)
377 {
378 num25 += (float)anchorBottom.tileCount;
379 int height = tileData2.Height;
380 for (int k = 0; k < anchorBottom.tileCount; k++)
381 {
382 int num26 = anchorBottom.checkStart + k;
383 Tile tileSafely = Framing.GetTileSafely(num8 + num26, num9 + height);
384 bool flag5 = false;
385 if (tileSafely.nactive())
386 {
387 if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
388 {
389 flag5 = tileData2.isValidTileAnchor(tileSafely.type);
390 }
391 if (!flag5 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
392 {
393 if (TileID.Sets.Platforms[tileSafely.type])
394 {
395 _ = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
396 if (!tileSafely.halfBrick() && WorldGen.PlatformProperTopFrame(tileSafely.frameX))
397 {
398 flag5 = true;
399 }
400 }
401 else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
402 {
403 flag5 = true;
404 }
405 }
406 if (!flag5 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && !TileID.Sets.Platforms[tileSafely.type] && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
407 {
408 flag5 = true;
409 }
410 if (!flag5 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
411 {
412 int num27 = tileSafely.blockType();
413 if ((uint)(num27 - 4) <= 1u)
414 {
415 flag5 = tileData2.isValidTileAnchor(tileSafely.type);
416 }
417 }
418 if (!flag5 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
419 {
420 flag5 = true;
421 }
422 }
423 else if (!flag5 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
424 {
425 flag5 = true;
426 }
427 if (!flag5)
428 {
429 if (onlyCheck)
430 {
431 objectPreview[num26 + num10, height + num11] = 2;
432 }
433 continue;
434 }
435 if (onlyCheck)
436 {
437 objectPreview[num26 + num10, height + num11] = 1;
438 }
439 num24 += 1f;
440 }
441 }
442 anchorBottom = tileData2.AnchorTop;
443 if (anchorBottom.tileCount != 0)
444 {
445 num25 += (float)anchorBottom.tileCount;
446 int num28 = -1;
447 for (int l = 0; l < anchorBottom.tileCount; l++)
448 {
449 int num29 = anchorBottom.checkStart + l;
450 Tile tileSafely = Framing.GetTileSafely(num8 + num29, num9 + num28);
451 bool flag6 = false;
452 if (tileSafely.nactive())
453 {
454 if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
455 {
456 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
457 }
458 if (!flag6 && (anchorBottom.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || (TileID.Sets.Platforms[tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[tileSafely.type] && !tileSafely.bottomSlope())
459 {
460 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
461 }
462 if (!flag6 && (anchorBottom.type & AnchorType.Platform) == AnchorType.Platform && TileID.Sets.Platforms[tileSafely.type])
463 {
464 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
465 }
466 if (!flag6 && (anchorBottom.type & AnchorType.PlatformNonHammered) == AnchorType.PlatformNonHammered && TileID.Sets.Platforms[tileSafely.type] && tileSafely.slope() == 0 && !tileSafely.halfBrick())
467 {
468 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
469 }
470 if (!flag6 && (anchorBottom.type & AnchorType.PlanterBox) == AnchorType.PlanterBox && tileSafely.type == 380)
471 {
472 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
473 }
474 if (!flag6 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
475 {
476 int num27 = tileSafely.blockType();
477 if ((uint)(num27 - 2) <= 1u)
478 {
479 flag6 = tileData2.isValidTileAnchor(tileSafely.type);
480 }
481 }
482 if (!flag6 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
483 {
484 flag6 = true;
485 }
486 }
487 else if (!flag6 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
488 {
489 flag6 = true;
490 }
491 if (!flag6)
492 {
493 if (onlyCheck)
494 {
495 objectPreview[num29 + num10, num28 + num11] = 2;
496 }
497 continue;
498 }
499 if (onlyCheck)
500 {
501 objectPreview[num29 + num10, num28 + num11] = 1;
502 }
503 num24 += 1f;
504 }
505 }
506 anchorBottom = tileData2.AnchorRight;
507 if (anchorBottom.tileCount != 0)
508 {
509 num25 += (float)anchorBottom.tileCount;
510 int width = tileData2.Width;
511 for (int m = 0; m < anchorBottom.tileCount; m++)
512 {
513 int num30 = anchorBottom.checkStart + m;
514 Tile tileSafely = Framing.GetTileSafely(num8 + width, num9 + num30);
515 bool flag7 = false;
516 if (tileSafely.nactive())
517 {
518 if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
519 {
520 flag7 = tileData2.isValidTileAnchor(tileSafely.type);
521 }
522 if (!flag7 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
523 {
524 int num27 = tileSafely.blockType();
525 if (num27 == 2 || num27 == 4)
526 {
527 flag7 = tileData2.isValidTileAnchor(tileSafely.type);
528 }
529 }
530 if (!flag7 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
531 {
532 flag7 = true;
533 if (m == 0)
534 {
535 num25 += 1f;
536 Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num30 - 1);
537 if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[tileSafely2.type])
538 {
539 num24 += 1f;
540 if (onlyCheck)
541 {
542 objectPreview[width + num10, num30 + num11 - 1] = 1;
543 }
544 }
545 else if (onlyCheck)
546 {
547 objectPreview[width + num10, num30 + num11 - 1] = 2;
548 }
549 }
550 if (m == anchorBottom.tileCount - 1)
551 {
552 num25 += 1f;
553 Tile tileSafely3 = Framing.GetTileSafely(num8 + width, num9 + num30 + 1);
554 if (tileSafely3.nactive() && TileID.Sets.IsATreeTrunk[tileSafely3.type])
555 {
556 num24 += 1f;
557 if (onlyCheck)
558 {
559 objectPreview[width + num10, num30 + num11 + 1] = 1;
560 }
561 }
562 else if (onlyCheck)
563 {
564 objectPreview[width + num10, num30 + num11 + 1] = 2;
565 }
566 }
567 }
568 if (!flag7 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
569 {
570 flag7 = true;
571 }
572 }
573 else if (!flag7 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
574 {
575 flag7 = true;
576 }
577 if (!flag7)
578 {
579 if (onlyCheck)
580 {
581 objectPreview[width + num10, num30 + num11] = 2;
582 }
583 continue;
584 }
585 if (onlyCheck)
586 {
587 objectPreview[width + num10, num30 + num11] = 1;
588 }
589 num24 += 1f;
590 }
591 }
592 anchorBottom = tileData2.AnchorLeft;
593 if (anchorBottom.tileCount != 0)
594 {
595 num25 += (float)anchorBottom.tileCount;
596 int num31 = -1;
597 for (int n = 0; n < anchorBottom.tileCount; n++)
598 {
599 int num32 = anchorBottom.checkStart + n;
600 Tile tileSafely = Framing.GetTileSafely(num8 + num31, num9 + num32);
601 bool flag8 = false;
602 if (tileSafely.nactive())
603 {
604 if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
605 {
606 flag8 = tileData2.isValidTileAnchor(tileSafely.type);
607 }
608 if (!flag8 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
609 {
610 int num27 = tileSafely.blockType();
611 if (num27 == 3 || num27 == 5)
612 {
613 flag8 = tileData2.isValidTileAnchor(tileSafely.type);
614 }
615 }
616 if (!flag8 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
617 {
618 flag8 = true;
619 if (n == 0)
620 {
621 num25 += 1f;
622 Tile tileSafely4 = Framing.GetTileSafely(num8 + num31, num9 + num32 - 1);
623 if (tileSafely4.nactive() && TileID.Sets.IsATreeTrunk[tileSafely4.type])
624 {
625 num24 += 1f;
626 if (onlyCheck)
627 {
628 objectPreview[num31 + num10, num32 + num11 - 1] = 1;
629 }
630 }
631 else if (onlyCheck)
632 {
633 objectPreview[num31 + num10, num32 + num11 - 1] = 2;
634 }
635 }
636 if (n == anchorBottom.tileCount - 1)
637 {
638 num25 += 1f;
639 Tile tileSafely5 = Framing.GetTileSafely(num8 + num31, num9 + num32 + 1);
640 if (tileSafely5.nactive() && TileID.Sets.IsATreeTrunk[tileSafely5.type])
641 {
642 num24 += 1f;
643 if (onlyCheck)
644 {
645 objectPreview[num31 + num10, num32 + num11 + 1] = 1;
646 }
647 }
648 else if (onlyCheck)
649 {
650 objectPreview[num31 + num10, num32 + num11 + 1] = 2;
651 }
652 }
653 }
654 if (!flag8 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
655 {
656 flag8 = true;
657 }
658 }
659 else if (!flag8 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
660 {
661 flag8 = true;
662 }
663 if (!flag8)
664 {
665 if (onlyCheck)
666 {
667 objectPreview[num31 + num10, num32 + num11] = 2;
668 }
669 continue;
670 }
671 if (onlyCheck)
672 {
673 objectPreview[num31 + num10, num32 + num11] = 1;
674 }
675 num24 += 1f;
676 }
677 }
678 if (tileData2.HookCheckIfCanPlace.hook != null)
679 {
681 {
682 _ = tileData2.Origin;
683 _ = tileData2.Origin;
684 }
685 if (tileData2.HookCheckIfCanPlace.hook(x, y, type, style, dir, num7) == tileData2.HookCheckIfCanPlace.badReturn && tileData2.HookCheckIfCanPlace.badResponse == 0)
686 {
687 num24 = 0f;
688 num22 = 0f;
689 objectPreview.AllInvalid();
690 }
691 }
692 float num33 = num24 / num25;
693 float num34 = num22 / num23;
694 if (num34 == 1f && num25 == 0f)
695 {
696 num23 = 1f;
697 num25 = 1f;
698 num33 = 1f;
699 num34 = 1f;
700 }
701 if (num33 == 1f && num34 == 1f)
702 {
703 num4 = 1f;
704 num5 = 1f;
705 num6 = num7;
706 tileObjectData = tileData2;
707 break;
708 }
709 if (num33 > num4 || (num33 == num4 && num34 > num5))
710 {
712 num4 = num33;
713 num5 = num34;
714 tileObjectData = tileData2;
715 num6 = num7;
716 }
717 }
718 int num35 = -1;
719 if (flag)
720 {
722 {
723 TileObjectPreviewData.randomCache = new TileObjectPreviewData();
724 }
725 bool flag9 = false;
727 {
728 Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
729 Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
730 int num36 = coordinates.X + objectStart.X;
731 int num37 = coordinates.Y + objectStart.Y;
732 int num38 = x - tileData.Origin.X;
733 int num39 = y - tileData.Origin.Y;
734 if (num36 != num38 || num37 != num39)
735 {
736 flag9 = true;
737 }
738 }
739 else
740 {
741 flag9 = true;
742 }
743 int randomStyleRange = tileData.RandomStyleRange;
744 int num40 = Main.rand.Next(tileData.RandomStyleRange);
745 if (forcedRandom.HasValue)
746 {
747 num40 = (forcedRandom.Value % randomStyleRange + randomStyleRange) % randomStyleRange;
748 }
749 num35 = ((!flag9 && !forcedRandom.HasValue) ? TileObjectPreviewData.randomCache.Random : num40);
750 }
751 if (tileData.SpecificRandomStyles != null)
752 {
754 {
755 TileObjectPreviewData.randomCache = new TileObjectPreviewData();
756 }
757 bool flag10 = false;
759 {
760 Point16 coordinates2 = TileObjectPreviewData.randomCache.Coordinates;
761 Point16 objectStart2 = TileObjectPreviewData.randomCache.ObjectStart;
762 int num41 = coordinates2.X + objectStart2.X;
763 int num42 = coordinates2.Y + objectStart2.Y;
764 int num43 = x - tileData.Origin.X;
765 int num44 = y - tileData.Origin.Y;
766 if (num41 != num43 || num42 != num44)
767 {
768 flag10 = true;
769 }
770 }
771 else
772 {
773 flag10 = true;
774 }
775 int num45 = tileData.SpecificRandomStyles.Length;
776 int num46 = Main.rand.Next(num45);
777 if (forcedRandom.HasValue)
778 {
779 num46 = (forcedRandom.Value % num45 + num45) % num45;
780 }
781 num35 = ((!flag10 && !forcedRandom.HasValue) ? TileObjectPreviewData.randomCache.Random : (tileData.SpecificRandomStyles[num46] - style));
782 }
783 if (onlyCheck)
784 {
785 if (num4 != 1f || num5 != 1f)
786 {
788 num7 = num6;
789 }
790 objectPreview.Random = num35;
791 if (tileData.RandomStyleRange > 0 || tileData.SpecificRandomStyles != null)
792 {
794 }
795 }
796 if (!onlyCheck)
797 {
798 objectData.xCoord = x - tileObjectData.Origin.X;
799 objectData.yCoord = y - tileObjectData.Origin.Y;
800 objectData.type = type;
801 objectData.style = style;
802 objectData.alternate = num7;
803 objectData.random = num35;
804 }
805 if (num4 == 1f)
806 {
807 return num5 == 1f;
808 }
809 return false;
810 }
811
812 public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
813 {
814 Point16 coordinates = op.Coordinates;
815 Texture2D value = TextureAssets.Tile[op.Type].Value;
817 int num = 0;
818 int num2 = 0;
819 int num3 = tileData.CalculatePlacementStyle(op.Style, op.Alternate, op.Random);
820 int num4 = 0;
821 int num5 = tileData.DrawYOffset;
822 int drawXOffset = tileData.DrawXOffset;
823 num3 += tileData.DrawStyleOffset;
824 int num6 = tileData.StyleWrapLimit;
825 int num7 = tileData.StyleLineSkip;
826 if (tileData.StyleWrapLimitVisualOverride.HasValue)
827 {
828 num6 = tileData.StyleWrapLimitVisualOverride.Value;
829 }
830 if (tileData.styleLineSkipVisualOverride.HasValue)
831 {
832 num7 = tileData.styleLineSkipVisualOverride.Value;
833 }
834 if (num6 > 0)
835 {
836 num4 = num3 / num6 * num7;
837 num3 %= num6;
838 }
839 if (tileData.StyleHorizontal)
840 {
841 num = tileData.CoordinateFullWidth * num3;
842 num2 = tileData.CoordinateFullHeight * num4;
843 }
844 else
845 {
846 num = tileData.CoordinateFullWidth * num4;
847 num2 = tileData.CoordinateFullHeight * num3;
848 }
849 for (int i = 0; i < op.Size.X; i++)
850 {
851 int x = num + (i - op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
852 int num8 = num2;
853 for (int j = 0; j < op.Size.Y; j++)
854 {
855 int num9 = coordinates.X + i;
856 int num10 = coordinates.Y + j;
857 if (j == 0 && tileData.DrawStepDown != 0 && WorldGen.SolidTile(Framing.GetTileSafely(num9, num10 - 1)))
858 {
859 num5 += tileData.DrawStepDown;
860 }
861 if (op.Type == 567)
862 {
863 num5 = ((j != 0) ? tileData.DrawYOffset : (tileData.DrawYOffset - 2));
864 }
865 int num11 = op[i, j];
866 Color color;
867 if (num11 != 1)
868 {
869 if (num11 != 2)
870 {
871 continue;
872 }
873 color = Color.Red * 0.7f;
874 }
875 else
876 {
877 color = Color.White;
878 }
879 color *= 0.5f;
880 if (i >= op.ObjectStart.X && i < op.ObjectStart.X + tileData.Width && j >= op.ObjectStart.Y && j < op.ObjectStart.Y + tileData.Height)
881 {
882 SpriteEffects spriteEffects = SpriteEffects.None;
883 if (tileData.DrawFlipHorizontal && num9 % 2 == 0)
884 {
885 spriteEffects |= SpriteEffects.FlipHorizontally;
886 }
887 if (tileData.DrawFlipVertical && num10 % 2 == 0)
888 {
889 spriteEffects |= SpriteEffects.FlipVertically;
890 }
891 int coordinateWidth = tileData.CoordinateWidth;
892 int num12 = tileData.CoordinateHeights[j - op.ObjectStart.Y];
893 if (op.Type == 114 && j == 1)
894 {
895 num12 += 2;
896 }
897 sb.Draw(sourceRectangle: new Rectangle(x, num8, coordinateWidth, num12), texture: value, position: new Vector2(num9 * 16 - (int)(position.X + (float)(coordinateWidth - 16) / 2f) + drawXOffset, num10 * 16 - (int)position.Y + num5), color: color, rotation: 0f, origin: Vector2.Zero, scale: 1f, effects: spriteEffects, layerDepth: 0f);
898 num8 += num12 + tileData.CoordinatePadding;
899 }
900 }
901 }
902 }
903}
void Draw(Texture2D texture, Vector2 position, Color color)
static Tile GetTileSafely(Vector2 position)
Definition Framing.cs:419
static Asset< Texture2D >[] Tile
static bool[] BreakableWhenPlacing
Definition TileID.cs:277
static bool[] NotReallySolid
Definition TileID.cs:257
static bool[] Platforms
Definition TileID.cs:163
static bool[] IsATreeTrunk
Definition TileID.cs:91
static int maxTilesY
Definition Main.cs:1116
static bool[] tileSolidTop
Definition Main.cs:1469
static bool[] tileCut
Definition Main.cs:1433
static bool[] tileTable
Definition Main.cs:1459
static int netMode
Definition Main.cs:2095
static int maxTilesX
Definition Main.cs:1114
static bool[] tileSolid
Definition Main.cs:1471
static Tile[,] tile
Definition Main.cs:1675
static UnifiedRandom rand
Definition Main.cs:1387
static bool[] tileNoAttach
Definition Main.cs:1487
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)
Definition NetMessage.cs:88
int CalculatePlacementStyle(int style, int alternate, int random)
static TileObjectData GetTileData(int type, int style, int alternate=0)
bool bottomSlope()
Definition Tile.cs:317
bool nactive()
Definition Tile.cs:257
bool topSlope()
Definition Tile.cs:307
ushort type
Definition Tile.cs:8
short frameX
Definition Tile.cs:22
bool active()
Definition Tile.cs:565
int blockType()
Definition Tile.cs:219
byte slope()
Definition Tile.cs:684
ushort wall
Definition Tile.cs:10
bool halfBrick()
Definition Tile.cs:650
static bool SolidTile(Tile testTile)
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static bool SlopeTile(int i, int j, int slope=0, bool noEffects=false)
static bool PlatformProperTopFrame(short frameX)
Func< int, int, int, int, int, int, int > hook
static bool Place(TileObject toBePlaced)
Definition TileObject.cs:29
static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck=false, int? forcedRandom=null)
static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
static TileObject Empty
Definition TileObject.cs:25
static TileObjectPreviewData objectPreview
Definition TileObject.cs:27