Skip to content

Commit 978eba7

Browse files
author
hamstar0
committed
v1.1.9.1 - Modified world gen to give up more easily
* Modified world gen to better avoid RNG overlap with Wormholes * Modified world gen to give up more easily
1 parent eda0d38 commit 978eba7

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

MountedMagicMirrors/MyWorldGen.cs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Terraria.ID;
66
using Terraria.ModLoader;
77
using Terraria.World.Generation;
8+
using HamstarHelpers.Classes.Errors;
89
using HamstarHelpers.Classes.Tiles.TilePattern;
910
using HamstarHelpers.Helpers.Debug;
1011
using HamstarHelpers.Helpers.DotNET.Extensions;
@@ -75,8 +76,6 @@ public MountedMirrorsGenPass( int mirrors ) : base( "PopulateMountedMirrors", 1f
7576
////////////////
7677

7778
public override void Apply( GenerationProgress progress ) {
78-
(int TileX, int TileY) randCenterTile;
79-
8079
if( progress != null ) {
8180
progress.Message = "Pre-placing Mounted Magic Mirrors: %";
8281
}
@@ -87,54 +86,72 @@ public override void Apply( GenerationProgress progress ) {
8786
return;
8887
}
8988

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+
}
94102

95-
this.MirrorPositions.Set2D( randCenterTile.TileX, randCenterTile.TileY );
103+
randCenterTile = myRandCenterTile.Value;
96104

97-
this.SpawnMirror( randCenterTile.TileX, randCenterTile.TileY );
105+
this.MirrorPositions.Set2D( randCenterTile.TileX, randCenterTile.TileY );
98106

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 );
100113
}
101114
}
102115

103116

104117
////////////////
105118

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;
107121
int attempts = 0;
108122

109123
do {
110-
randTileCenter = this.GetRandomMirrorableCenterTile( maxAttempts );
124+
myRandTileCenter = this.GetRandomMirrorableCenterTile( maxAttempts );
125+
if( !myRandTileCenter.HasValue ) {
126+
break;
127+
}
111128

112-
if( !this.HasNearbyMirrors(randTileCenter.TileX, randTileCenter.TileY) ) {
113-
return true;
129+
if( !this.HasNearbyMirrors(myRandTileCenter.Value.TileX, myRandTileCenter.Value.TileY) ) {
130+
return myRandTileCenter;
114131
}
115132
} while( attempts++ < maxAttempts );
116133

117-
return false;
134+
return null;
118135
}
119136

120137

121-
private (int TileX, int TileY) GetRandomMirrorableCenterTile( int maxAttempts ) {
138+
////////////////
139+
140+
private (int TileX, int TileY)? GetRandomMirrorableCenterTile( int maxAttempts ) {
122141
int attempts = 0;
123142
int randTileX, randTileY;
124143
var bounds = MountedMirrorsGenPass.GetTileBoundsForWorld();
125144

126145
do {
127-
WorldGen.genRand.Next(); // Desyncs this from Wormholes?
128-
WorldGen.genRand.Next();
129146
randTileX = WorldGen.genRand.Next( bounds.minTileX, bounds.maxTileX );
130147
randTileY = WorldGen.genRand.Next( bounds.minTileY, bounds.maxTileY );
131148

132149
if( this.MirrorSpacePattern.Check( randTileX, randTileY ) ) {
133-
break;
150+
return (randTileX, randTileY);
134151
}
135152
} while( attempts++ < maxAttempts );
136153

137-
return (randTileX, randTileY);
154+
return null;
138155
}
139156

140157

MountedMagicMirrors/build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
displayName = Mounted Magic Mirrors
22
author = hamstar
3-
version = 1.1.9
3+
version = 1.1.9.1
44
modReferences = HamstarHelpers@5.9.4
55
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
66
homepage = https://forums.terraria.org/index.php?threads/mounted-magic-mirrors-fast-travel.83296/

0 commit comments

Comments
 (0)