Warn when imported features run outside vanilla height

This commit is contained in:
piexel authored and Brian Fopiano committed 2026-11-27 12:54:23 -05:00
1 parent 25c612b3c3
commit 7b39e39beb
2 files changed
+76

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,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);
}
}