Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TreeTopsInfo.cs
Go to the documentation of this file.
1
using
System.IO
;
2
using
Microsoft.Xna.Framework
;
3
using
Terraria.Utilities
;
4
5
namespace
Terraria.GameContent
;
6
7
public
class
TreeTopsInfo
8
{
9
public
class
AreaId
10
{
11
public
const
int
Forest1
= 0;
12
13
public
const
int
Forest2
= 1;
14
15
public
const
int
Forest3
= 2;
16
17
public
const
int
Forest4
= 3;
18
19
public
const
int
Corruption
= 4;
20
21
public
const
int
Jungle
= 5;
22
23
public
const
int
Snow
= 6;
24
25
public
const
int
Hallow
= 7;
26
27
public
const
int
Crimson
= 8;
28
29
public
const
int
Desert = 9;
30
31
public
const
int
Ocean
= 10;
32
33
public
const
int
GlowingMushroom
= 11;
34
35
public
const
int
Underworld
= 12;
36
37
public
static
readonly
int
Count
= 13;
38
}
39
40
private
int
[]
_variations
=
new
int
[
AreaId
.
Count
];
41
42
public
void
Save
(
BinaryWriter
writer)
43
{
44
writer.Write(
_variations
.Length);
45
for
(
int
i = 0; i <
_variations
.Length; i++)
46
{
47
writer.Write(
_variations
[i]);
48
}
49
}
50
51
public
void
Load
(
BinaryReader
reader,
int
loadVersion)
52
{
53
if
(loadVersion < 211)
54
{
55
CopyExistingWorldInfo
();
56
return
;
57
}
58
int
num = reader.
ReadInt32
();
59
for
(
int
i = 0; i < num && i <
_variations
.Length; i++)
60
{
61
_variations
[i] = reader.
ReadInt32
();
62
}
63
}
64
65
public
void
SyncSend
(
BinaryWriter
writer)
66
{
67
for
(
int
i = 0; i <
_variations
.Length; i++)
68
{
69
writer.Write((
byte
)
_variations
[i]);
70
}
71
}
72
73
public
void
SyncReceive
(
BinaryReader
reader)
74
{
75
for
(
int
i = 0; i <
_variations
.Length; i++)
76
{
77
int
num =
_variations
[i];
78
_variations
[i] = reader.
ReadByte
();
79
if
(
_variations
[i] != num)
80
{
81
DoTreeFX
(i);
82
}
83
}
84
}
85
86
public
int
GetTreeStyle
(
int
areaId)
87
{
88
return
_variations
[areaId];
89
}
90
91
public
void
RandomizeTreeStyleBasedOnWorldPosition
(
UnifiedRandom
rand,
Vector2
worldPosition)
92
{
93
Point
pt =
new
Point
((
int
)(worldPosition.
X
/ 16f), (
int
)(worldPosition.
Y
/ 16f) + 1);
94
Tile
tileSafely =
Framing
.
GetTileSafely
(pt);
95
if
(tileSafely.
active
())
96
{
97
int
num = -1;
98
if
(tileSafely.
type
== 70)
99
{
100
num = 11;
101
}
102
else
if
(tileSafely.
type
== 53 &&
WorldGen
.
oceanDepths
(pt.
X
, pt.
Y
))
103
{
104
num = 10;
105
}
106
else
if
(tileSafely.
type
== 23)
107
{
108
num = 4;
109
}
110
else
if
(tileSafely.
type
== 199)
111
{
112
num = 8;
113
}
114
else
if
(tileSafely.
type
== 109 || tileSafely.
type
== 492)
115
{
116
num = 7;
117
}
118
else
if
(tileSafely.
type
== 53)
119
{
120
num = 9;
121
}
122
else
if
(tileSafely.
type
== 147)
123
{
124
num = 6;
125
}
126
else
if
(tileSafely.
type
== 60)
127
{
128
num = 5;
129
}
130
else
if
(tileSafely.
type
== 633)
131
{
132
num = 12;
133
}
134
else
if
(tileSafely.
type
== 2 || tileSafely.
type
== 477)
135
{
136
num = ((pt.X >=
Main
.
treeX
[0]) ? ((pt.
X
<
Main
.
treeX
[1]) ? 1 : ((pt.X >=
Main
.
treeX
[2]) ? 3 : 2)) : 0);
137
}
138
if
(num > -1)
139
{
140
RandomizeTreeStyle
(rand, num);
141
}
142
}
143
}
144
145
public
void
RandomizeTreeStyle
(
UnifiedRandom
rand,
int
areaId)
146
{
147
int
num =
_variations
[areaId];
148
bool
flag =
false
;
149
while
(
_variations
[areaId] == num)
150
{
151
switch
(areaId)
152
{
153
case
0:
154
case
1:
155
case
2:
156
case
3:
157
_variations
[areaId] = rand.
Next
(6);
158
break
;
159
case
4:
160
_variations
[areaId] = rand.
Next
(5);
161
break
;
162
case
5:
163
_variations
[areaId] = rand.
Next
(6);
164
break
;
165
case
6:
166
_variations
[areaId] = rand.NextFromList<
int
>(0, 1, 2, 21, 22, 3, 31, 32, 4, 41, 42, 5, 6, 7);
167
break
;
168
case
7:
169
_variations
[areaId] = rand.
Next
(5);
170
break
;
171
case
8:
172
_variations
[areaId] = rand.
Next
(6);
173
break
;
174
case
9:
175
_variations
[areaId] = rand.
Next
(5);
176
break
;
177
case
10:
178
_variations
[areaId] = rand.
Next
(6);
179
break
;
180
case
11:
181
_variations
[areaId] = rand.
Next
(4);
182
break
;
183
case
12:
184
_variations
[areaId] = rand.
Next
(6);
185
break
;
186
default
:
187
flag =
true
;
188
break
;
189
}
190
if
(flag)
191
{
192
break
;
193
}
194
}
195
if
(num !=
_variations
[areaId])
196
{
197
if
(
Main
.
netMode
== 2)
198
{
199
NetMessage
.
SendData
(7);
200
}
201
else
202
{
203
DoTreeFX
(areaId);
204
}
205
}
206
}
207
208
private
void
DoTreeFX
(
int
areaID)
209
{
210
}
211
212
public
void
CopyExistingWorldInfoForWorldGeneration
()
213
{
214
CopyExistingWorldInfo
();
215
}
216
217
private
void
CopyExistingWorldInfo
()
218
{
219
_variations
[0] =
Main
.
treeStyle
[0];
220
_variations
[1] =
Main
.
treeStyle
[1];
221
_variations
[2] =
Main
.
treeStyle
[2];
222
_variations
[3] =
Main
.
treeStyle
[3];
223
_variations
[4] =
WorldGen
.
corruptBG
;
224
_variations
[5] =
WorldGen
.
jungleBG
;
225
_variations
[6] =
WorldGen
.
snowBG
;
226
_variations
[7] =
WorldGen
.
hallowBG
;
227
_variations
[8] =
WorldGen
.
crimsonBG
;
228
_variations
[9] =
WorldGen
.
desertBG
;
229
_variations
[10] =
WorldGen
.
oceanBG
;
230
_variations
[11] =
WorldGen
.
mushroomBG
;
231
_variations
[12] =
WorldGen
.
underworldBG
;
232
}
233
}
System.IO.BinaryReader.ReadByte
virtual byte ReadByte()
Definition
BinaryReader.cs:164
System.IO.BinaryReader.ReadInt32
virtual int ReadInt32()
Definition
BinaryReader.cs:213
System.IO.BinaryReader
Definition
BinaryReader.cs:8
System.IO.BinaryWriter
Definition
BinaryWriter.cs:10
Terraria.Framing.GetTileSafely
static Tile GetTileSafely(Vector2 position)
Definition
Framing.cs:419
Terraria.Framing
Definition
Framing.cs:8
Terraria.GameContent.TreeTopsInfo.AreaId.Forest3
const int Forest3
Definition
TreeTopsInfo.cs:15
Terraria.GameContent.TreeTopsInfo.AreaId.Forest2
const int Forest2
Definition
TreeTopsInfo.cs:13
Terraria.GameContent.TreeTopsInfo.AreaId.Ocean
const int Ocean
Definition
TreeTopsInfo.cs:31
Terraria.GameContent.TreeTopsInfo.AreaId.Corruption
const int Corruption
Definition
TreeTopsInfo.cs:19
Terraria.GameContent.TreeTopsInfo.AreaId.Snow
const int Snow
Definition
TreeTopsInfo.cs:23
Terraria.GameContent.TreeTopsInfo.AreaId.Forest1
const int Forest1
Definition
TreeTopsInfo.cs:11
Terraria.GameContent.TreeTopsInfo.AreaId.Count
static readonly int Count
Definition
TreeTopsInfo.cs:37
Terraria.GameContent.TreeTopsInfo.AreaId.Jungle
const int Jungle
Definition
TreeTopsInfo.cs:21
Terraria.GameContent.TreeTopsInfo.AreaId.GlowingMushroom
const int GlowingMushroom
Definition
TreeTopsInfo.cs:33
Terraria.GameContent.TreeTopsInfo.AreaId.Crimson
const int Crimson
Definition
TreeTopsInfo.cs:27
Terraria.GameContent.TreeTopsInfo.AreaId.Forest4
const int Forest4
Definition
TreeTopsInfo.cs:17
Terraria.GameContent.TreeTopsInfo.AreaId.Hallow
const int Hallow
Definition
TreeTopsInfo.cs:25
Terraria.GameContent.TreeTopsInfo.AreaId.Underworld
const int Underworld
Definition
TreeTopsInfo.cs:35
Terraria.GameContent.TreeTopsInfo.AreaId
Definition
TreeTopsInfo.cs:10
Terraria.GameContent.TreeTopsInfo.RandomizeTreeStyleBasedOnWorldPosition
void RandomizeTreeStyleBasedOnWorldPosition(UnifiedRandom rand, Vector2 worldPosition)
Definition
TreeTopsInfo.cs:91
Terraria.GameContent.TreeTopsInfo.SyncSend
void SyncSend(BinaryWriter writer)
Definition
TreeTopsInfo.cs:65
Terraria.GameContent.TreeTopsInfo.SyncReceive
void SyncReceive(BinaryReader reader)
Definition
TreeTopsInfo.cs:73
Terraria.GameContent.TreeTopsInfo.Load
void Load(BinaryReader reader, int loadVersion)
Definition
TreeTopsInfo.cs:51
Terraria.GameContent.TreeTopsInfo.RandomizeTreeStyle
void RandomizeTreeStyle(UnifiedRandom rand, int areaId)
Definition
TreeTopsInfo.cs:145
Terraria.GameContent.TreeTopsInfo.DoTreeFX
void DoTreeFX(int areaID)
Definition
TreeTopsInfo.cs:208
Terraria.GameContent.TreeTopsInfo.GetTreeStyle
int GetTreeStyle(int areaId)
Definition
TreeTopsInfo.cs:86
Terraria.GameContent.TreeTopsInfo._variations
int[] _variations
Definition
TreeTopsInfo.cs:40
Terraria.GameContent.TreeTopsInfo.Save
void Save(BinaryWriter writer)
Definition
TreeTopsInfo.cs:42
Terraria.GameContent.TreeTopsInfo.CopyExistingWorldInfoForWorldGeneration
void CopyExistingWorldInfoForWorldGeneration()
Definition
TreeTopsInfo.cs:212
Terraria.GameContent.TreeTopsInfo.CopyExistingWorldInfo
void CopyExistingWorldInfo()
Definition
TreeTopsInfo.cs:217
Terraria.GameContent.TreeTopsInfo
Definition
TreeTopsInfo.cs:8
Terraria.Main.treeX
static int[] treeX
Definition
Main.cs:668
Terraria.Main.netMode
static int netMode
Definition
Main.cs:2095
Terraria.Main.treeStyle
static int[] treeStyle
Definition
Main.cs:670
Terraria.Main
Definition
Main.cs:79
Terraria.NetMessage.SendData
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
Terraria.NetMessage
Definition
NetMessage.cs:18
Terraria.Tile.type
ushort type
Definition
Tile.cs:8
Terraria.Tile.active
bool active()
Definition
Tile.cs:565
Terraria.Tile
Definition
Tile.cs:7
Terraria.Utilities.UnifiedRandom.Next
virtual int Next()
Definition
UnifiedRandom.cs:98
Terraria.Utilities.UnifiedRandom
Definition
UnifiedRandom.cs:7
Terraria.WorldGen.hallowBG
static int hallowBG
Definition
WorldGen.cs:914
Terraria.WorldGen.mushroomBG
static int mushroomBG
Definition
WorldGen.cs:922
Terraria.WorldGen.jungleBG
static int jungleBG
Definition
WorldGen.cs:910
Terraria.WorldGen.underworldBG
static int underworldBG
Definition
WorldGen.cs:924
Terraria.WorldGen.corruptBG
static int corruptBG
Definition
WorldGen.cs:908
Terraria.WorldGen.oceanDepths
static bool oceanDepths(int x, int y)
Definition
WorldGen.cs:7142
Terraria.WorldGen.desertBG
static int desertBG
Definition
WorldGen.cs:918
Terraria.WorldGen.crimsonBG
static int crimsonBG
Definition
WorldGen.cs:916
Terraria.WorldGen.snowBG
static int snowBG
Definition
WorldGen.cs:912
Terraria.WorldGen.oceanBG
static int oceanBG
Definition
WorldGen.cs:920
Terraria.WorldGen
Definition
WorldGen.cs:32
Microsoft.Xna.Framework
Definition
AlphaTestEffect.cs:1
System.IO
Definition
ConsoleStream.cs:3
Terraria.GameContent
Definition
AchievementsHelper.cs:1
Terraria.Utilities
Definition
ExtensionFilter.cs:1
Microsoft.Xna.Framework.Point.X
int X
Definition
Point.cs:14
Microsoft.Xna.Framework.Point.Y
int Y
Definition
Point.cs:17
Microsoft.Xna.Framework.Point
Definition
Point.cs:12
Microsoft.Xna.Framework.Vector2.X
float X
Definition
Vector2.cs:14
Microsoft.Xna.Framework.Vector2.Y
float Y
Definition
Vector2.cs:17
Microsoft.Xna.Framework.Vector2
Definition
Vector2.cs:12
source
Terraria.GameContent
TreeTopsInfo.cs
Generated by
1.10.0