175 {
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 {
192 }
194 int num3 = 0;
196 {
198 }
199 float num4 = -1f;
200 float num5 = -1f;
201 int num6 = 0;
203 int num7 = -1;
204 while (num7 < num3)
205 {
206 num7++;
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 }
219 int num10 = 0;
220 int num11 = 0;
222 {
223 if (rectangle.
Y == 0)
224 {
225 rectangle.Y = -1;
227 num11++;
228 }
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 }
244 {
246 {
248 }
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 }
264 {
265 if (rectangle.
X == 0)
266 {
267 rectangle.X = -1;
269 num10++;
270 }
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;
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 }
294 {
295 if (rectangle.
X + rectangle.
Width == tileData2.
Width)
296 {
298 }
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;
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 {
324 objectPreview.Active = true;
325 objectPreview.Type = (ushort)
type;
327 objectPreview.Alternate = num7;
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);
342 bool flag3 = false;
344 {
345 num25 += 1f;
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 {
365 }
366 continue;
367 }
368 if (onlyCheck)
369 {
371 }
372 num22 += 1f;
373 }
374 }
377 {
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 {
390 }
392 {
394 {
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 }
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 {
416 }
417 }
419 {
420 flag5 = true;
421 }
422 }
424 {
425 flag5 = true;
426 }
427 if (!flag5)
428 {
429 if (onlyCheck)
430 {
432 }
433 continue;
434 }
435 if (onlyCheck)
436 {
438 }
439 num24 += 1f;
440 }
441 }
444 {
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 {
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 {
461 }
463 {
465 }
467 {
469 }
471 {
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 {
480 }
481 }
483 {
484 flag6 = true;
485 }
486 }
488 {
489 flag6 = true;
490 }
491 if (!flag6)
492 {
493 if (onlyCheck)
494 {
496 }
497 continue;
498 }
499 if (onlyCheck)
500 {
502 }
503 num24 += 1f;
504 }
505 }
508 {
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 {
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 {
528 }
529 }
531 {
532 flag7 = true;
533 if (m == 0)
534 {
535 num25 += 1f;
536 Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num30 - 1);
538 {
539 num24 += 1f;
540 if (onlyCheck)
541 {
543 }
544 }
545 else if (onlyCheck)
546 {
548 }
549 }
551 {
552 num25 += 1f;
553 Tile tileSafely3 = Framing.GetTileSafely(num8 + width, num9 + num30 + 1);
555 {
556 num24 += 1f;
557 if (onlyCheck)
558 {
560 }
561 }
562 else if (onlyCheck)
563 {
565 }
566 }
567 }
569 {
570 flag7 = true;
571 }
572 }
574 {
575 flag7 = true;
576 }
577 if (!flag7)
578 {
579 if (onlyCheck)
580 {
582 }
583 continue;
584 }
585 if (onlyCheck)
586 {
588 }
589 num24 += 1f;
590 }
591 }
594 {
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 {
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 {
614 }
615 }
617 {
618 flag8 = true;
619 if (n == 0)
620 {
621 num25 += 1f;
622 Tile tileSafely4 = Framing.GetTileSafely(num8 + num31, num9 + num32 - 1);
624 {
625 num24 += 1f;
626 if (onlyCheck)
627 {
629 }
630 }
631 else if (onlyCheck)
632 {
634 }
635 }
637 {
638 num25 += 1f;
639 Tile tileSafely5 = Framing.GetTileSafely(num8 + num31, num9 + num32 + 1);
641 {
642 num24 += 1f;
643 if (onlyCheck)
644 {
646 }
647 }
648 else if (onlyCheck)
649 {
651 }
652 }
653 }
655 {
656 flag8 = true;
657 }
658 }
660 {
661 flag8 = true;
662 }
663 if (!flag8)
664 {
665 if (onlyCheck)
666 {
668 }
669 continue;
670 }
671 if (onlyCheck)
672 {
674 }
675 num24 += 1f;
676 }
677 }
679 {
681 {
684 }
686 {
687 num24 = 0f;
688 num22 = 0f;
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 {
724 }
725 bool flag9 = false;
727 {
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 }
745 if (forcedRandom.HasValue)
746 {
747 num40 = (forcedRandom.Value % randomStyleRange + randomStyleRange) % randomStyleRange;
748 }
750 }
752 {
754 {
756 }
757 bool flag10 = false;
759 {
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 }
776 int num46 = Main.rand.Next(num45);
777 if (forcedRandom.HasValue)
778 {
779 num46 = (forcedRandom.Value % num45 + num45) % num45;
780 }
782 }
783 if (onlyCheck)
784 {
785 if (num4 != 1f || num5 != 1f)
786 {
788 num7 = num6;
789 }
790 objectPreview.Random = num35;
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 }
static TileObjectPreviewData randomCache
static TileObjectPreviewData placementCache
static bool[] BreakableWhenPlacing
static bool[] NotReallySolid
static bool[] IsATreeTrunk
bool isValidWallAnchor(int type)
bool LiquidPlace(Tile checkTile)
TileObjectDirection Direction
bool isValidTileAnchor(int type)
bool isValidAlternateAnchor(int type)
int[] SpecificRandomStyles
static int PlatformFrameWidth()
static TileObjectData GetTileData(int type, int style, int alternate=0)
PlacementHook HookCheckIfCanPlace
bool processedCoordinates
Func< int, int, int, int, int, int, int > hook
static TileObjectPreviewData objectPreview