mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Warn when imported features run outside vanilla height
This commit is contained in:
1 parent
832070cd69
commit
2d6977c916
2 files changed
+76
No files matched your search
@@ -36,6 +36,8 @@ import java.util.regex.Pattern;
|
||||
final class PackDimensionValidator {
|
||||
private static final String BORROWED_DIMENSION_TYPE = "borrowedDimensionType";
|
||||
private static final Pattern RESOURCE_KEY = Pattern.compile("[a-z0-9_.-]+:[a-z0-9/._-]+");
|
||||
private static final int VANILLA_OVERWORLD_MIN_Y = -64;
|
||||
private static final int VANILLA_OVERWORLD_MAX_Y = 320;
|
||||
|
||||
private PackDimensionValidator() {
|
||||
}
|
||||
@@ -60,6 +62,7 @@ final class PackDimensionValidator {
|
||||
}
|
||||
|
||||
validateImportedStructurePolicy(dimensionKey, dimJson, blockingErrors, warnings);
|
||||
validateImportedFeatureHeight(packFolder, dimensionKey, dimJson, warnings);
|
||||
validateDimensionHeights(packFolder, dimensionKey, dimJson, blockingErrors);
|
||||
validateBorrowedDimensionType(dimensionKey, dimJson, borrowedDimensionTypesSupported(), blockingErrors);
|
||||
validateSamplingStep(dimensionKey, dimJson, "terrainSamplingStep", 1, blockingErrors);
|
||||
@@ -276,6 +279,23 @@ final class PackDimensionValidator {
|
||||
}
|
||||
}
|
||||
|
||||
static void validateImportedFeatureHeight(File packFolder, String dimensionKey, JSONObject dimension,
|
||||
List<String> warnings) {
|
||||
JSONObject importedFeatures = dimension.optJSONObject("importedFeatures");
|
||||
if (importedFeatures == null || !importedFeatures.optBoolean("enabled", false)) {
|
||||
return;
|
||||
}
|
||||
JSONObject height = resolveDimensionHeight(packFolder, dimension);
|
||||
int minY = height == null ? VANILLA_OVERWORLD_MIN_Y : (int) height.optDouble("min", 16D);
|
||||
int maxY = height == null ? VANILLA_OVERWORLD_MAX_Y : (int) height.optDouble("max", 32D);
|
||||
if (minY >= VANILLA_OVERWORLD_MIN_Y && maxY <= VANILLA_OVERWORLD_MAX_Y) {
|
||||
return;
|
||||
}
|
||||
warnings.add("Dimension '" + dimensionKey + "' runs importedFeatures in a " + minY + ".." + maxY
|
||||
+ " world. Vanilla features anchored to the world bottom or top move with it, so ores such as"
|
||||
+ " diamond spread into extra bands. Narrow them with importedFeatures.steps or disabled.");
|
||||
}
|
||||
|
||||
static void validateStaticObjects(File packFolder, String dimensionKey, JSONObject dimension,
|
||||
List<String> blockingErrors) {
|
||||
if (!dimension.has("staticObjects")) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PackValidatorImportedFeatureHeightTest {
|
||||
@Rule
|
||||
public TemporaryFolder pack = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void deeperWorldWithFeaturesEnabledWarns() {
|
||||
List<String> warnings = validate(featuresEnabled(true).put("dimensionHeight", height(-256, 512)));
|
||||
|
||||
assertEquals(1, warnings.size());
|
||||
assertTrue(warnings.get(0), warnings.get(0).contains("Dimension 'overworld' runs importedFeatures in a -256..512 world"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaOverworldHeightStaysSilent() {
|
||||
assertTrue(validate(featuresEnabled(true).put("dimensionHeight", height(-64, 320))).isEmpty());
|
||||
assertTrue(validate(featuresEnabled(true)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shorterWorldInsideVanillaBoundsStaysSilent() {
|
||||
assertTrue(validate(featuresEnabled(true).put("dimensionHeight", height(0, 256))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledOrAbsentFeaturesStaySilent() {
|
||||
assertTrue(validate(featuresEnabled(false).put("dimensionHeight", height(-256, 512))).isEmpty());
|
||||
assertTrue(validate(new JSONObject().put("dimensionHeight", height(-256, 512))).isEmpty());
|
||||
}
|
||||
|
||||
private List<String> validate(JSONObject dimension) {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
PackDimensionValidator.validateImportedFeatureHeight(pack.getRoot(), "overworld", dimension, warnings);
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private static JSONObject featuresEnabled(boolean enabled) {
|
||||
return new JSONObject().put("importedFeatures", new JSONObject().put("enabled", enabled));
|
||||
}
|
||||
|
||||
private static JSONObject height(int min, int max) {
|
||||
return new JSONObject().put("min", min).put("max", max);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user