Skip to content

Commit

Permalink
Fix multi dimensions (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
Synthitic authored Oct 2, 2021
1 parent 62faa27 commit ccaf6c1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/gregtech/api/worldgen/config/WorldConfigUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public static Predicate<WorldProvider> createWorldPredicate(JsonElement element)
allPredicates.add(wp -> wp.isNether() || wp.getDimensionType() == DimensionType.NETHER);
continue;
}
Function<WorldProvider, String> stringSupplier;
Function<WorldProvider, String> stringSupplier = null;
if (stringValue.startsWith("dimension_id:")) {
String filterValue = stringValue.substring(13);
if (filterValue.indexOf(':') == -1) {
int dimensionId = Integer.parseInt(filterValue);
return provider -> provider.getDimension() == dimensionId;
allPredicates.add(provider -> provider.getDimension() == dimensionId);
} else {
int indexOf = filterValue.indexOf(':');
int indexOfExclusive = indexOf + 1;
int minDimensionId = indexOf == 0 ? -Integer.MAX_VALUE : Integer.parseInt(filterValue.substring(0, indexOf));
int maxDimensionId = indexOfExclusive == filterValue.length() ? Integer.MAX_VALUE : Integer.parseInt(filterValue.substring(indexOfExclusive));
return provider -> provider.getDimension() >= minDimensionId && provider.getDimension() <= maxDimensionId;
allPredicates.add(provider -> provider.getDimension() >= minDimensionId && provider.getDimension() <= maxDimensionId);
}
} else if (stringValue.startsWith("name:")) {
stringSupplier = provider -> provider.getDimensionType().getName();
Expand All @@ -56,12 +56,16 @@ public static Predicate<WorldProvider> createWorldPredicate(JsonElement element)
stringSupplier = provider -> provider.getClass().getSimpleName();
stringValue = stringValue.substring(15);
} else throw new IllegalArgumentException("Unknown world predicate: " + stringValue);
if (stringValue.startsWith("*")) {
Pattern pattern = Pattern.compile(stringValue.substring(1));
return provider -> pattern.matcher(stringSupplier.apply(provider)).matches();
} else {
String finalStringValue = stringValue;
return provider -> finalStringValue.equalsIgnoreCase(stringSupplier.apply(provider));
if (stringSupplier != null) {
if (stringValue.startsWith("*")) {
Pattern pattern = Pattern.compile(stringValue.substring(1));
Function<WorldProvider, String> finalStringSupplier = stringSupplier;
allPredicates.add(provider -> pattern.matcher(finalStringSupplier.apply(provider)).matches());
} else {
String finalStringValue = stringValue;
Function<WorldProvider, String> finalStringSupplier1 = stringSupplier;
allPredicates.add(provider -> finalStringValue.equalsIgnoreCase(finalStringSupplier1.apply(provider)));
}
}
}

Expand Down

0 comments on commit ccaf6c1

Please sign in to comment.