Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TETeleportationPylon.cs
Go to the documentation of this file.
2
4
6{
7 private static byte _myEntityID;
8
9 private const int MyTileID = 597;
10
11 private const int entityTileWidth = 3;
12
13 private const int entityTileHeight = 4;
14
15 public override void RegisterTileEntityID(int assignedID)
16 {
17 _myEntityID = (byte)assignedID;
18 }
19
20 public override TileEntity GenerateInstance()
21 {
22 return new TETeleportationPylon();
23 }
24
25 public override void NetPlaceEntityAttempt(int x, int y)
26 {
27 if (!TryGetPylonTypeFromTileCoords(x, y, out var pylonType))
28 {
30 return;
31 }
32 if (Main.PylonSystem.HasPylonOfType(pylonType))
33 {
35 return;
36 }
37 int number = Place(x, y);
38 NetMessage.SendData(86, -1, -1, null, number, x, y);
39 }
40
41 public bool TryGetPylonType(out TeleportPylonType pylonType)
42 {
43 return TryGetPylonTypeFromTileCoords(Position.X, Position.Y, out pylonType);
44 }
45
46 private static void RejectPlacementFromNet(int x, int y)
47 {
48 WorldGen.KillTile(x, y);
49 if (Main.netMode == 2)
50 {
51 NetMessage.SendData(17, -1, -1, null, 0, x, y);
52 }
53 }
54
55 public static int Place(int x, int y)
56 {
57 TETeleportationPylon tETeleportationPylon = new TETeleportationPylon();
58 tETeleportationPylon.Position = new Point16(x, y);
59 tETeleportationPylon.ID = TileEntity.AssignNewID();
60 tETeleportationPylon.type = _myEntityID;
62 {
63 TileEntity.ByID[tETeleportationPylon.ID] = tETeleportationPylon;
64 TileEntity.ByPosition[tETeleportationPylon.Position] = tETeleportationPylon;
65 }
66 Main.PylonSystem.RequestImmediateUpdate();
67 return tETeleportationPylon.ID;
68 }
69
70 public static void Kill(int x, int y)
71 {
72 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
73 {
75 {
76 TileEntity.ByID.Remove(value.ID);
77 TileEntity.ByPosition.Remove(new Point16(x, y));
78 }
79 Main.PylonSystem.RequestImmediateUpdate();
80 }
81 }
82
83 public override string ToString()
84 {
85 return Position.X + "x " + Position.Y + "y";
86 }
87
88 public static void Framing_CheckTile(int callX, int callY)
89 {
91 {
92 return;
93 }
94 int num = callX;
95 int num2 = callY;
96 Tile tileSafely = Framing.GetTileSafely(callX, callY);
97 num -= tileSafely.frameX / 18 % 3;
98 num2 -= tileSafely.frameY / 18 % 4;
99 int pylonStyleFromTile = GetPylonStyleFromTile(tileSafely);
100 bool flag = false;
101 for (int i = num; i < num + 3; i++)
102 {
103 for (int j = num2; j < num2 + 4; j++)
104 {
105 Tile tile = Main.tile[i, j];
106 if (!tile.active() || tile.type != 597)
107 {
108 flag = true;
109 }
110 }
111 }
112 if (!WorldGen.SolidTileAllowBottomSlope(num, num2 + 4) || !WorldGen.SolidTileAllowBottomSlope(num + 1, num2 + 4) || !WorldGen.SolidTileAllowBottomSlope(num + 2, num2 + 4))
113 {
114 flag = true;
115 }
116 if (!flag)
117 {
118 return;
119 }
120 Kill(num, num2);
121 int pylonItemTypeFromTileStyle = GetPylonItemTypeFromTileStyle(pylonStyleFromTile);
122 Item.NewItem(new EntitySource_TileBreak(num, num2), num * 16, num2 * 16, 48, 64, pylonItemTypeFromTileStyle);
123 WorldGen.destroyObject = true;
124 for (int k = num; k < num + 3; k++)
125 {
126 for (int l = num2; l < num2 + 4; l++)
127 {
128 if (Main.tile[k, l].active() && Main.tile[k, l].type == 597)
129 {
130 WorldGen.KillTile(k, l);
131 }
132 }
133 }
134 WorldGen.destroyObject = false;
135 }
136
137 public static int GetPylonStyleFromTile(Tile tile)
138 {
139 return tile.frameX / 54;
140 }
141
142 public static int GetPylonItemTypeFromTileStyle(int style)
143 {
144 return style switch
145 {
146 1 => 4875,
147 2 => 4916,
148 3 => 4917,
149 4 => 4918,
150 5 => 4919,
151 6 => 4920,
152 7 => 4921,
153 8 => 4951,
154 _ => 4876,
155 };
156 }
157
158 public override bool IsTileValidForEntity(int x, int y)
159 {
160 if (!Main.tile[x, y].active() || Main.tile[x, y].type != 597 || Main.tile[x, y].frameY != 0 || Main.tile[x, y].frameX % 54 != 0)
161 {
162 return false;
163 }
164 return true;
165 }
166
167 public static int PlacementPreviewHook_AfterPlacement(int x, int y, int type = 597, int style = 0, int direction = 1, int alternate = 0)
168 {
169 if (Main.netMode == 1)
170 {
171 NetMessage.SendTileSquare(Main.myPlayer, x - 1, y - 3, 3, 4);
172 NetMessage.SendData(87, -1, -1, null, x + -1, y + -3, (int)_myEntityID);
173 return -1;
174 }
175 return Place(x + -1, y + -3);
176 }
177
178 public static int PlacementPreviewHook_CheckIfCanPlace(int x, int y, int type = 597, int style = 0, int direction = 1, int alternate = 0)
179 {
180 TeleportPylonType pylonTypeFromPylonTileStyle = GetPylonTypeFromPylonTileStyle(style);
181 if (Main.PylonSystem.HasPylonOfType(pylonTypeFromPylonTileStyle))
182 {
183 return 1;
184 }
185 return 0;
186 }
187
188 private bool TryGetPylonTypeFromTileCoords(int x, int y, out TeleportPylonType pylonType)
189 {
190 pylonType = TeleportPylonType.SurfacePurity;
191 Tile tile = Main.tile[x, y];
192 if (tile == null || !tile.active() || tile.type != 597)
193 {
194 return false;
195 }
196 int pylonStyle = tile.frameX / 54;
197 pylonType = GetPylonTypeFromPylonTileStyle(pylonStyle);
198 return true;
199 }
200
202 {
203 return (TeleportPylonType)pylonStyle;
204 }
205
206 public static int Find(int x, int y)
207 {
208 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
209 {
210 return value.ID;
211 }
212 return -1;
213 }
214}
static Dictionary< int, TileEntity > ByID
Definition TileEntity.cs:18
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:20
static Tile GetTileSafely(Vector2 position)
Definition Framing.cs:419
static int PlacementPreviewHook_CheckIfCanPlace(int x, int y, int type=597, int style=0, int direction=1, int alternate=0)
static int PlacementPreviewHook_AfterPlacement(int x, int y, int type=597, int style=0, int direction=1, int alternate=0)
static TeleportPylonType GetPylonTypeFromPylonTileStyle(int pylonStyle)
bool TryGetPylonTypeFromTileCoords(int x, int y, out TeleportPylonType pylonType)
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)
Definition Item.cs:49697
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static TeleportPylonsSystem PylonSystem
Definition Main.cs:1872
static Tile[,] tile
Definition Main.cs:1675
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
static void SendTileSquare(int whoAmi, int tileX, int tileY, int xSize, int ySize, TileChangeType changeType=TileChangeType.None)
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
static bool destroyObject
Definition WorldGen.cs:1020
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static bool SolidTileAllowBottomSlope(int i, int j)