TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
TETeleportationPylon.cs
Go to the documentation of this file.
3
5
7{
8 private static byte _myEntityID;
9
10 private const int MyTileID = 597;
11
12 private const int entityTileWidth = 3;
13
14 private const int entityTileHeight = 4;
15
16 public override void RegisterTileEntityID(int assignedID)
17 {
18 _myEntityID = (byte)assignedID;
19 }
20
21 public override TileEntity GenerateInstance()
22 {
23 return new TETeleportationPylon();
24 }
25
26 public override void NetPlaceEntityAttempt(int x, int y)
27 {
29 {
31 return;
32 }
33 if (!(PylonLoader.PreCanPlacePylon(x, y, 597, pylonType) ?? (!Main.PylonSystem.HasPylonOfType(pylonType))))
34 {
36 return;
37 }
38 int number = Place(x, y);
39 NetMessage.SendData(86, -1, -1, null, number, x, y);
40 }
41
46
47 private static void RejectPlacementFromNet(int x, int y)
48 {
49 WorldGen.KillTile(x, y);
50 if (Main.netMode == 2)
51 {
52 NetMessage.SendData(17, -1, -1, null, 0, x, y);
53 }
54 }
55
56 public static int Place(int x, int y)
57 {
59 tETeleportationPylon.Position = new Point16(x, y);
60 tETeleportationPylon.ID = TileEntity.AssignNewID();
61 tETeleportationPylon.type = _myEntityID;
63 {
66 }
67 Main.PylonSystem.RequestImmediateUpdate();
68 return tETeleportationPylon.ID;
69 }
70
71 public static void Kill(int x, int y)
72 {
73 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
74 {
76 {
77 TileEntity.ByID.Remove(value.ID);
78 TileEntity.ByPosition.Remove(new Point16(x, y));
79 }
80 Main.PylonSystem.RequestImmediateUpdate();
81 }
82 }
83
84 public override string ToString()
85 {
86 return Position.X + "x " + Position.Y + "y";
87 }
88
89 public static void Framing_CheckTile(int callX, int callY)
90 {
92 {
93 return;
94 }
95 int num = callX;
96 int num2 = callY;
98 num -= tileSafely.frameX / 18 % 3;
99 num2 -= tileSafely.frameY / 18 % 4;
101 bool flag = false;
102 for (int i = num; i < num + 3; i++)
103 {
104 for (int j = num2; j < num2 + 4; j++)
105 {
106 Tile tile = Main.tile[i, j];
107 if (!tile.active() || tile.type != 597)
108 {
109 flag = true;
110 }
111 }
112 }
114 {
115 flag = true;
116 }
117 if (!flag)
118 {
119 return;
120 }
121 Kill(num, num2);
123 if (TileLoader.Drop(callX, callY, 470))
124 {
126 }
127 WorldGen.destroyObject = true;
128 for (int k = num; k < num + 3; k++)
129 {
130 for (int l = num2; l < num2 + 4; l++)
131 {
132 if (Main.tile[k, l].active() && Main.tile[k, l].type == 597)
133 {
135 }
136 }
137 }
138 WorldGen.destroyObject = false;
139 }
140
141 public static int GetPylonStyleFromTile(Tile tile)
142 {
143 return tile.frameX / 54;
144 }
145
146 public static int GetPylonItemTypeFromTileStyle(int style)
147 {
148 return style switch
149 {
150 1 => 4875,
151 2 => 4916,
152 3 => 4917,
153 4 => 4918,
154 5 => 4919,
155 6 => 4920,
156 7 => 4921,
157 8 => 4951,
158 _ => 4876,
159 };
160 }
161
162 public override bool IsTileValidForEntity(int x, int y)
163 {
164 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)
165 {
166 return false;
167 }
168 return true;
169 }
170
171 public static int PlacementPreviewHook_AfterPlacement(int x, int y, int type = 597, int style = 0, int direction = 1, int alternate = 0)
172 {
173 if (Main.netMode == 1)
174 {
175 NetMessage.SendTileSquare(Main.myPlayer, x - 1, y - 3, 3, 4);
176 NetMessage.SendData(87, -1, -1, null, x + -1, y + -3, (int)_myEntityID);
177 return -1;
178 }
179 return Place(x + -1, y + -3);
180 }
181
182 public static int PlacementPreviewHook_CheckIfCanPlace(int x, int y, int type = 597, int style = 0, int direction = 1, int alternate = 0)
183 {
185 if (flag.HasValue)
186 {
187 if (!flag.GetValueOrDefault())
188 {
189 return 1;
190 }
191 return 0;
192 }
194 if (Main.PylonSystem.HasPylonOfType(pylonTypeFromPylonTileStyle))
195 {
196 return 1;
197 }
198 return 0;
199 }
200
202 {
203 pylonType = TeleportPylonType.SurfacePurity;
204 Tile tile = Main.tile[x, y];
205 if (tile == null || !tile.active() || tile.type != 597)
206 {
207 return false;
208 }
209 int pylonStyle = tile.frameX / 54;
211 return true;
212 }
213
218
219 public static int Find(int x, int y)
220 {
221 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
222 {
223 return value.ID;
224 }
225 return -1;
226 }
227}
static Dictionary< int, TileEntity > ByID
Definition TileEntity.cs:20
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:22
static Tile GetTileSafely(Vector2 position)
Definition Framing.cs:421
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)
This particular overload uses two Vector2 to determine the actual spawn position.
Definition Item.cs:51478
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 TeleportPylonsSystem PylonSystem
Definition Main.cs:2022
static Tilemap tile
Definition Main.cs:1820
static ? bool PreCanPlacePylon(int x, int y, int tileType, TeleportPylonType pylonType)
static bool Drop(int i, int j, int type, bool includeLargeObjectDrops=true)
This serves as the central class from which tile-related functions are supported and carried out.
Definition TileLoader.cs:23
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)
static void SendTileSquare(int whoAmi, int tileX, int tileY, int xSize, int ySize, TileChangeType changeType=TileChangeType.None)
static bool destroyObject
Definition WorldGen.cs:1258
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static bool SolidTileAllowBottomSlope(int i, int j)
Allows Tile Entities that you want to be included in vanilla's pylon list to actually be added to the...
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