Warn on imported feature height (#1274)

- Warn when importedFeatures runs outside -64..320
- Point at disabled and disabledSteps to remove ores
- Stay silent when imported features are off
This commit is contained in:
Piexel authored and GitHub committed 2026-11-27 12:58:04 -05:00
1 parent 25c612b3c3
commit 4c90095361
2 files changed
+89

No files matched your search

@@ -39,6 +39,8 @@ final class PackDimensionValidator {
private static final String STYLE_SNIPPET_TYPE = "style";
private static final String RANGE_SNIPPET_TYPE = "range";
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() {
}
@@ -63,6 +65,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);
@@ -278,6 +281,24 @@ 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);
// Vanilla anchors ore bands to the world bottom and top, so any height other than -64..320 moves them.
if (minY == VANILLA_OVERWORLD_MIN_Y && maxY == VANILLA_OVERWORLD_MAX_Y) {
return;
}
warnings.add("Dimension '" + dimensionKey + "' runs importedFeatures in a " + minY + ".." + maxY
+ " world. Vanilla ores shift with the height; remove them with importedFeatures.disabled"
+ " (minecraft:ore) or disabledSteps (UNDERGROUND_ORES).");
}
static void validateStaticObjects(File packFolder, String dimensionKey, JSONObject dimension,
List<String> blockingErrors) {
if (!dimension.has("staticObjects")) {
@@ -0,0 +1,68 @@
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 shorterWorldInsideVanillaBoundsWarns() {
List<String> warnings = validate(featuresEnabled(true).put("dimensionHeight", height(0, 256)));
assertEquals(1, warnings.size());
assertTrue(warnings.get(0), warnings.get(0).contains("in a 0..256 world"));
}
@Test
public void warningPointsAtTheSettingsThatRemoveOres() {
String warning = validate(featuresEnabled(true).put("dimensionHeight", height(-256, 512))).get(0);
assertTrue(warning, warning.contains("importedFeatures.disabled"));
assertTrue(warning, warning.contains("disabledSteps"));
assertTrue(warning, !warning.contains("importedFeatures.steps"));
}
@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);
}
}