Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WorldUtils.cs
Go to the documentation of this file.
1using System;
3
5
6public static class WorldUtils
7{
8 public static Rectangle ClampToWorld(Rectangle tileRectangle)
9 {
10 int num = Math.Max(0, Math.Min(tileRectangle.Left, Main.maxTilesX));
11 int num2 = Math.Max(0, Math.Min(tileRectangle.Top, Main.maxTilesY));
12 int num3 = Math.Max(0, Math.Min(tileRectangle.Right, Main.maxTilesX));
13 int num4 = Math.Max(0, Math.Min(tileRectangle.Bottom, Main.maxTilesY));
14 return new Rectangle(num, num2, num3 - num, num4 - num2);
15 }
16
17 public static bool Gen(Point origin, GenShape shape, GenAction action)
18 {
19 return shape.Perform(origin, action);
20 }
21
22 public static bool Gen(Point origin, GenShapeActionPair pair)
23 {
24 return pair.Shape.Perform(origin, pair.Action);
25 }
26
27 public static bool Find(Point origin, GenSearch search, out Point result)
28 {
29 result = search.Find(origin);
30 if (result == GenSearch.NOT_FOUND)
31 {
32 return false;
33 }
34 return true;
35 }
36
37 public static void ClearTile(int x, int y, bool frameNeighbors = false)
38 {
39 Main.tile[x, y].ClearTile();
40 if (frameNeighbors)
41 {
42 WorldGen.TileFrame(x + 1, y);
43 WorldGen.TileFrame(x - 1, y);
44 WorldGen.TileFrame(x, y + 1);
45 WorldGen.TileFrame(x, y - 1);
46 }
47 }
48
49 public static void ClearWall(int x, int y, bool frameNeighbors = false)
50 {
51 Main.tile[x, y].wall = 0;
52 if (frameNeighbors)
53 {
54 WorldGen.SquareWallFrame(x + 1, y);
55 WorldGen.SquareWallFrame(x - 1, y);
56 WorldGen.SquareWallFrame(x, y + 1);
57 WorldGen.SquareWallFrame(x, y - 1);
58 }
59 }
60
61 public static void TileFrame(int x, int y, bool frameNeighbors = false)
62 {
63 WorldGen.TileFrame(x, y, resetFrame: true);
64 if (frameNeighbors)
65 {
66 WorldGen.TileFrame(x + 1, y, resetFrame: true);
67 WorldGen.TileFrame(x - 1, y, resetFrame: true);
68 WorldGen.TileFrame(x, y + 1, resetFrame: true);
69 WorldGen.TileFrame(x, y - 1, resetFrame: true);
70 }
71 }
72
73 public static void ClearChestLocation(int x, int y)
74 {
75 ClearTile(x, y, frameNeighbors: true);
76 ClearTile(x - 1, y, frameNeighbors: true);
77 ClearTile(x, y - 1, frameNeighbors: true);
78 ClearTile(x - 1, y - 1, frameNeighbors: true);
79 }
80
81 public static void WireLine(Point start, Point end)
82 {
83 Point point = start;
84 Point point2 = end;
85 if (end.X < start.X)
86 {
87 Utils.Swap(ref end.X, ref start.X);
88 }
89 if (end.Y < start.Y)
90 {
91 Utils.Swap(ref end.Y, ref start.Y);
92 }
93 for (int i = start.X; i <= end.X; i++)
94 {
95 WorldGen.PlaceWire(i, point.Y);
96 }
97 for (int j = start.Y; j <= end.Y; j++)
98 {
99 WorldGen.PlaceWire(point2.X, j);
100 }
101 }
102
103 public static void DebugRegen()
104 {
107 Main.NewText("World Regen Complete.");
108 }
109
110 public static void DebugRotate()
111 {
112 int num = 0;
113 int num2 = 0;
114 int maxTilesY = Main.maxTilesY;
115 for (int i = 0; i < Main.maxTilesX / Main.maxTilesY; i++)
116 {
117 for (int j = 0; j < maxTilesY / 2; j++)
118 {
119 for (int k = j; k < maxTilesY - j; k++)
120 {
121 Tile tile = Main.tile[k + num, j + num2];
122 Main.tile[k + num, j + num2] = Main.tile[j + num, maxTilesY - k + num2];
123 Main.tile[j + num, maxTilesY - k + num2] = Main.tile[maxTilesY - k + num, maxTilesY - j + num2];
124 Main.tile[maxTilesY - k + num, maxTilesY - j + num2] = Main.tile[maxTilesY - j + num, k + num2];
125 Main.tile[maxTilesY - j + num, k + num2] = tile;
126 }
127 }
128 num += maxTilesY;
129 }
130 }
131}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static int maxTilesY
Definition Main.cs:1116
static WorldFileData ActiveWorldFileData
Definition Main.cs:1946
static void NewText(string newText, byte R=byte.MaxValue, byte G=byte.MaxValue, byte B=byte.MaxValue)
Definition Main.cs:61429
static int maxTilesX
Definition Main.cs:1114
static Tile[,] tile
Definition Main.cs:1675
bool Perform(Point origin, GenAction action)
static bool Gen(Point origin, GenShapeActionPair pair)
Definition WorldUtils.cs:22
static void TileFrame(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:61
static bool Find(Point origin, GenSearch search, out Point result)
Definition WorldUtils.cs:27
static void ClearChestLocation(int x, int y)
Definition WorldUtils.cs:73
static void WireLine(Point start, Point end)
Definition WorldUtils.cs:81
static void ClearTile(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:37
static Rectangle ClampToWorld(Rectangle tileRectangle)
Definition WorldUtils.cs:8
static bool Gen(Point origin, GenShape shape, GenAction action)
Definition WorldUtils.cs:17
static void ClearWall(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:49
static void GenerateWorld(int seed, GenerationProgress customProgressObject=null)
Definition WorldGen.cs:7175
static void SquareWallFrame(int i, int j, bool resetFrame=true)
static void clearWorld()
Definition WorldGen.cs:3373
static void TileFrame(int i, int j, bool resetFrame=false, bool noBreak=false)
static bool PlaceWire(int i, int j)