Skip to content

Commit 1db52d4

Browse files
committed
for all generators that support the 'attempts' keyword we now support a ranged version and do munge this internally as part of the load&parse sequence for all supported versions of the json format
1 parent 61e0fdc commit 1db52d4

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
lines changed

src/main/java/com/mcmoddev/orespawn/data/Constants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Constants {
3131
public static final String PRECISION = "precision";
3232

3333
public final class FormatBits {
34+
3435
private FormatBits() {}
3536

3637
public static final String MAX_SPREAD = "maxSpread";
@@ -44,6 +45,8 @@ private FormatBits() {}
4445
public static final String LENGTH = "length";
4546
public static final String WANDER = "wander";
4647
public static final String NODE_COUNT = "numObjects";
48+
public static final String ATTEMPTS_MIN = "minAttempts";
49+
public static final String ATTEMPTS_MAX = "maxAttempts";
4750
}
4851

4952
public final class FileBits {
@@ -75,14 +78,17 @@ private ConfigNames() {}
7578
public static final String PARAMETERS = "parameters";
7679
public static final String FILE_VERSION = "version";
7780
public static final String BLOCK_V2 = "name";
78-
81+
7982
public final class V2 {
8083
private V2() {}
8184
public static final String ENABLED = "enabled";
8285
public static final String RETROGEN = "retrogen";
8386
public static final String REPLACES = "replaces";
8487
public static final String GENERATOR = "generator";
88+
public static final String MINIMUM = "minimum";
89+
public static final String MAXIMUM = "maximum";
8590
}
91+
8692
public final class BiomeStuff {
8793
private BiomeStuff() {}
8894
public static final String WHITELIST = "includes";

src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,23 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
5353
int blockX = chunkX * 16 + 8;
5454
int blockZ = chunkZ * 16 + 8;
5555

56-
int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt();
57-
int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt();
58-
int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt();
59-
int variance = params.get(Constants.FormatBits.VARIATION).getAsInt();
60-
int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt();
61-
int tries = params.get(Constants.FormatBits.ATTEMPTS).getAsInt();
56+
int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt();
57+
int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt();
58+
int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt();
59+
int variance = params.get(Constants.FormatBits.VARIATION).getAsInt();
60+
int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt();
61+
int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt();
62+
int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt();
6263
int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt();
6364
int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt();
6465

66+
int tries;
67+
if( triesMax == triesMin ) {
68+
tries = triesMax;
69+
} else {
70+
tries = random.nextInt( triesMax - triesMin ) + triesMin;
71+
}
72+
6573
while( tries > 0 ) {
6674
if( this.random.nextInt(100) <= frequency ) {
6775
int xRand = random.nextInt(16);
@@ -179,7 +187,8 @@ public JsonObject getDefaultParameters() {
179187
defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24);
180188
defParams.addProperty(Constants.FormatBits.VARIATION, 4);
181189
defParams.addProperty(Constants.FormatBits.FREQUENCY, 25);
182-
defParams.addProperty(Constants.FormatBits.ATTEMPTS, 8);
190+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4);
191+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8 );
183192
return defParams;
184193
}
185194

src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
5959
int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt();
6060
int variance = params.get(Constants.FormatBits.VARIATION).getAsInt();
6161
int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt();
62-
int tries = params.get(Constants.FormatBits.ATTEMPTS).getAsInt();
62+
int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt();
63+
int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt();
6364

6465
// on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get
6566
// a size that will let us insert by the radius
@@ -81,6 +82,13 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
8182
int fSave = frequency;
8283
int tryCount = 0;
8384

85+
int tries;
86+
if( triesMax == triesMin ) {
87+
tries = triesMax;
88+
} else {
89+
tries = random.nextInt( triesMax - triesMin ) + triesMin;
90+
}
91+
8492
while( tries > 0 ) {
8593
if( this.random.nextInt(100) <= frequency ) {
8694
frequency = fSave;
@@ -170,7 +178,8 @@ public JsonObject getDefaultParameters() {
170178
defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24);
171179
defParams.addProperty(Constants.FormatBits.VARIATION, 4);
172180
defParams.addProperty(Constants.FormatBits.FREQUENCY, 25);
173-
defParams.addProperty(Constants.FormatBits.ATTEMPTS, 8);
181+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4);
182+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4);
174183
return defParams;
175184
}
176185

src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
5656
int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt();
5757
int vari = params.get(Constants.FormatBits.VARIATION).getAsInt();
5858
int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt();
59-
int tries = params.get(Constants.FormatBits.ATTEMPTS).getAsInt();
6059
int length = params.get(Constants.FormatBits.LENGTH).getAsInt();
6160
int wander = params.get(Constants.FormatBits.WANDER).getAsInt();
6261
int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt();
62+
int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt();
63+
int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt();
64+
65+
int tries;
66+
if( triesMax == triesMin ) {
67+
tries = triesMax;
68+
} else {
69+
tries = random.nextInt( triesMax - triesMin ) + triesMin;
70+
}
6371

6472
// we have an offset into the chunk but actually need something more
6573
while( tries > 0 ) {
@@ -240,7 +248,8 @@ public JsonObject getDefaultParameters() {
240248
defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256);
241249
defParams.addProperty(Constants.FormatBits.VARIATION, 16);
242250
defParams.addProperty(Constants.FormatBits.FREQUENCY, 50);
243-
defParams.addProperty(Constants.FormatBits.ATTEMPTS, 8);
251+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8);
252+
defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4);
244253
defParams.addProperty(Constants.FormatBits.LENGTH, 16);
245254
defParams.addProperty(Constants.FormatBits.WANDER, 75);
246255
defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3);

src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ private static void finallyParse(JsonObject parseJson, String filename) {
152152

153153
FeatureBuilder gen = spawn.newFeatureBuilder(nw.get(ConfigNames.FEATURE).getAsString());
154154
gen.setDefaultParameters();
155+
handleParameterFixes(nw);
155156
gen.setParameters(nw.getAsJsonObject(ConfigNames.PARAMETERS));
156157
spawn.enabled( nw.get(ConfigNames.V2.ENABLED).getAsBoolean());
157158
spawn.retrogen( nw.get(ConfigNames.V2.RETROGEN).getAsBoolean());
@@ -172,7 +173,23 @@ private static void finallyParse(JsonObject parseJson, String filename) {
172173
logic.create(builder);
173174
});
174175
}
175-
176+
177+
private static void handleParameterFixes ( JsonObject nw ) {
178+
JsonObject p = nw.getAsJsonObject( ConfigNames.PARAMETERS );
179+
if( p.has( Constants.FormatBits.ATTEMPTS) ) {
180+
if( p.get( Constants.FormatBits.ATTEMPTS ).isJsonObject() ) {
181+
p.add( Constants.FormatBits.ATTEMPTS_MIN, p.getAsJsonObject( Constants.FormatBits.ATTEMPTS ).get( ConfigNames.V2.MINIMUM ) );
182+
p.add( Constants.FormatBits.ATTEMPTS_MAX, p.getAsJsonObject( Constants.FormatBits.ATTEMPTS ).get( ConfigNames.V2.MAXIMUM ) );
183+
} else {
184+
p.addProperty( Constants.FormatBits.ATTEMPTS_MIN, p.get( Constants.FormatBits.ATTEMPTS ).getAsInt() );
185+
p.addProperty( Constants.FormatBits.ATTEMPTS_MAX, p.get( Constants.FormatBits.ATTEMPTS ).getAsInt() );
186+
}
187+
p.remove( Constants.FormatBits.ATTEMPTS );
188+
nw.remove( ConfigNames.PARAMETERS );
189+
nw.add( ConfigNames.PARAMETERS, p );
190+
}
191+
}
192+
176193
private static List<IBlockState> getReplacements(String configField, int dimension) {
177194
String work = configField.toLowerCase();
178195

src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public JsonObject parseJson(JsonObject entries, String fileName) {
2929
ore.addProperty("retrogen", true);
3030
ore.addProperty("enabled", true);
3131

32-
3332
JsonObject oreOut = handleVersionDifferences( ore, entries.get(ConfigNames.FILE_VERSION).getAsString() );
3433
dimData.add(oreOut);
3534
}

0 commit comments

Comments
 (0)