5
5
using Terraria . ID ;
6
6
using Terraria . ModLoader ;
7
7
using Terraria . World . Generation ;
8
+ using HamstarHelpers . Classes . Errors ;
8
9
using HamstarHelpers . Classes . Tiles . TilePattern ;
9
10
using HamstarHelpers . Helpers . Debug ;
10
11
using HamstarHelpers . Helpers . DotNET . Extensions ;
@@ -75,8 +76,6 @@ public MountedMirrorsGenPass( int mirrors ) : base( "PopulateMountedMirrors", 1f
75
76
////////////////
76
77
77
78
public override void Apply ( GenerationProgress progress ) {
78
- ( int TileX , int TileY ) randCenterTile ;
79
-
80
79
if ( progress != null ) {
81
80
progress . Message = "Pre-placing Mounted Magic Mirrors: %" ;
82
81
}
@@ -87,54 +86,72 @@ public override void Apply( GenerationProgress progress ) {
87
86
return ;
88
87
}
89
88
90
- for ( int i = 0 ; i < this . NeededMirrors ; i ++ ) {
91
- if ( ! this . GetRandomOpenMirrorableCenterTile ( out randCenterTile , 1000 ) ) {
92
- break ;
93
- }
89
+ for ( int i = 0 ; i < 1000 ; i ++ ) {
90
+ WorldGen . genRand . Next ( ) ; // Desyncs this from Wormholes?
91
+ }
92
+
93
+ ( int TileX , int TileY ) ? myRandCenterTile ;
94
+ ( int TileX , int TileY ) randCenterTile ;
95
+
96
+ try {
97
+ for ( int i = 0 ; i < this . NeededMirrors ; i ++ ) {
98
+ myRandCenterTile = this . GetRandomOpenMirrorableCenterTile ( 1000 ) ;
99
+ if ( ! myRandCenterTile . HasValue ) {
100
+ break ;
101
+ }
94
102
95
- this . MirrorPositions . Set2D ( randCenterTile . TileX , randCenterTile . TileY ) ;
103
+ randCenterTile = myRandCenterTile . Value ;
96
104
97
- this . SpawnMirror ( randCenterTile . TileX , randCenterTile . TileY ) ;
105
+ this . MirrorPositions . Set2D ( randCenterTile . TileX , randCenterTile . TileY ) ;
98
106
99
- progress ? . Set ( ( float ) i / ( float ) this . NeededMirrors ) ;
107
+ this . SpawnMirror ( randCenterTile . TileX , randCenterTile . TileY ) ;
108
+
109
+ progress ? . Set ( ( float ) i / ( float ) this . NeededMirrors ) ;
110
+ }
111
+ } catch ( Exception e ) {
112
+ throw new ModHelpersException ( "Mounted Mirrors world gen failed." , e ) ;
100
113
}
101
114
}
102
115
103
116
104
117
////////////////
105
118
106
- private bool GetRandomOpenMirrorableCenterTile ( out ( int TileX , int TileY ) randTileCenter , int maxAttempts ) {
119
+ private ( int TileX , int TileY ) ? GetRandomOpenMirrorableCenterTile ( int maxAttempts ) {
120
+ ( int TileX , int TileY ) ? myRandTileCenter = null ;
107
121
int attempts = 0 ;
108
122
109
123
do {
110
- randTileCenter = this . GetRandomMirrorableCenterTile ( maxAttempts ) ;
124
+ myRandTileCenter = this . GetRandomMirrorableCenterTile ( maxAttempts ) ;
125
+ if ( ! myRandTileCenter . HasValue ) {
126
+ break ;
127
+ }
111
128
112
- if ( ! this . HasNearbyMirrors ( randTileCenter . TileX , randTileCenter . TileY ) ) {
113
- return true ;
129
+ if ( ! this . HasNearbyMirrors ( myRandTileCenter . Value . TileX , myRandTileCenter . Value . TileY ) ) {
130
+ return myRandTileCenter ;
114
131
}
115
132
} while ( attempts ++ < maxAttempts ) ;
116
133
117
- return false ;
134
+ return null ;
118
135
}
119
136
120
137
121
- private ( int TileX , int TileY ) GetRandomMirrorableCenterTile ( int maxAttempts ) {
138
+ ////////////////
139
+
140
+ private ( int TileX , int TileY ) ? GetRandomMirrorableCenterTile ( int maxAttempts ) {
122
141
int attempts = 0 ;
123
142
int randTileX , randTileY ;
124
143
var bounds = MountedMirrorsGenPass . GetTileBoundsForWorld ( ) ;
125
144
126
145
do {
127
- WorldGen . genRand . Next ( ) ; // Desyncs this from Wormholes?
128
- WorldGen . genRand . Next ( ) ;
129
146
randTileX = WorldGen . genRand . Next ( bounds . minTileX , bounds . maxTileX ) ;
130
147
randTileY = WorldGen . genRand . Next ( bounds . minTileY , bounds . maxTileY ) ;
131
148
132
149
if ( this . MirrorSpacePattern . Check ( randTileX , randTileY ) ) {
133
- break ;
150
+ return ( randTileX , randTileY ) ;
134
151
}
135
152
} while ( attempts ++ < maxAttempts ) ;
136
153
137
- return ( randTileX , randTileY ) ;
154
+ return null ;
138
155
}
139
156
140
157
0 commit comments