mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-27 14:30:14 +00:00
Merged dimension takeover
This commit is contained in:
commit
79e220298f
54 files changed
+1505
-95
No files matched your search
+79
@@ -6,6 +6,7 @@ import art.arcane.iris.world.IrisEnvironment;
|
||||
import org.junit.Test;
|
||||
|
||||
import static art.arcane.iris.generation.terrain.IrisDimensionTypeOptions.TriState.TRUE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -137,6 +138,84 @@ public class IrisDimensionRuntimeContractTest {
|
||||
IrisDimensionRuntimeContract.requireHotloadCompatible("Studio world", active, replacement, "iris");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expectedContractUsesTheBorrowedTypeKey() {
|
||||
IrisDimension dimension = borrowedDimension("aether:the_aether", 0, 256);
|
||||
|
||||
assertEquals("aether:the_aether", IrisDimensionRuntimeContract.expected(dimension, "iris").typeKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedTypeAcceptsAPackRangeInsideTheBorrowedRange() {
|
||||
IrisDimensionRuntimeContract expected = IrisDimensionRuntimeContract.expected(
|
||||
borrowedDimension("aether:the_aether", 0, 192), "iris");
|
||||
|
||||
expected.requireBorrowedFit("Modded level 'aether:the_aether'",
|
||||
new IrisDimensionRuntimeContract("aether:the_aether", 0, 256, 256));
|
||||
expected.requireBorrowedFit("Modded level 'aether:the_aether'",
|
||||
new IrisDimensionRuntimeContract("aether:the_aether", 0, 192, 64));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedTypeRejectsAPackTopAboveTheBorrowedTop() {
|
||||
IrisDimensionRuntimeContract expected = IrisDimensionRuntimeContract.expected(
|
||||
borrowedDimension("aether:the_aether", 0, 320), "iris");
|
||||
|
||||
assertBorrowedFitRejected(expected, new IrisDimensionRuntimeContract("aether:the_aether", 0, 256, 256),
|
||||
"0..320", "0..256");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedTypeRejectsAPackMinimumThatDiffersFromTheBorrowedMinimum() {
|
||||
IrisDimensionRuntimeContract expected = IrisDimensionRuntimeContract.expected(
|
||||
borrowedDimension("aether:the_aether", 16, 256), "iris");
|
||||
|
||||
assertBorrowedFitRejected(expected, new IrisDimensionRuntimeContract("aether:the_aether", 0, 256, 256),
|
||||
"16..256", "0..256");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedTypeRejectsALevelUsingAnotherType() {
|
||||
IrisDimensionRuntimeContract expected = IrisDimensionRuntimeContract.expected(
|
||||
borrowedDimension("aether:the_aether", 0, 256), "iris");
|
||||
|
||||
assertBorrowedFitRejected(expected, new IrisDimensionRuntimeContract("minecraft:overworld", 0, 256, 256),
|
||||
"aether:the_aether", "minecraft:overworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hotloadRejectsBorrowedTypeChanges() {
|
||||
IrisDimension active = hotloadDimension();
|
||||
IrisDimension replacement = hotloadDimension();
|
||||
replacement.setBorrowedDimensionType("aether:the_aether");
|
||||
|
||||
assertHotloadRejected(active, replacement, "aether:the_aether");
|
||||
}
|
||||
|
||||
private IrisDimension borrowedDimension(String typeKey, int minHeight, int maxHeight) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setLoadKey("skylands");
|
||||
dimension.setBorrowedDimensionType(typeKey);
|
||||
dimension.setDimensionHeight(new IrisRange(minHeight, maxHeight));
|
||||
dimension.setLogicalHeight(maxHeight - minHeight);
|
||||
return dimension;
|
||||
}
|
||||
|
||||
private void assertBorrowedFitRejected(IrisDimensionRuntimeContract expected,
|
||||
IrisDimensionRuntimeContract actual,
|
||||
String expectedFragment,
|
||||
String actualFragment) {
|
||||
try {
|
||||
expected.requireBorrowedFit("Modded level 'aether:the_aether'", actual);
|
||||
fail("A borrowed dimension type that cannot hold the pack range must be rejected");
|
||||
} catch (IrisDimensionContractException e) {
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Modded level 'aether:the_aether'"));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains(expectedFragment));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains(actualFragment));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Generation was refused"));
|
||||
}
|
||||
}
|
||||
|
||||
private IrisDimensionRuntimeContract expectedContract() {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setLoadKey("overworld");
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PackValidatorBorrowedDimensionTypeTest {
|
||||
@Test
|
||||
public void acceptsAbsentEmptyAndRegistryKeys() {
|
||||
assertTrue(validate("{}").isEmpty());
|
||||
assertTrue(validate("{\"borrowedDimensionType\":\"\"}").isEmpty());
|
||||
assertTrue(validate("{\"borrowedDimensionType\":\"aether:the_aether\"}").isEmpty());
|
||||
assertTrue(validate("{\"borrowedDimensionType\":\"minecraft:the_end\"}").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsValuesThatAreNotNamespacedRegistryKeys() {
|
||||
assertEquals(List.of("Dimension 'main' borrowedDimensionType must be a namespaced dimension type key such as aether:the_aether, but was 'the_aether'."),
|
||||
validate("{\"borrowedDimensionType\":\"the_aether\"}"));
|
||||
assertEquals(List.of("Dimension 'main' borrowedDimensionType must be a namespaced dimension type key such as aether:the_aether, but was 'Aether:The Aether'."),
|
||||
validate("{\"borrowedDimensionType\":\"Aether:The Aether\"}"));
|
||||
assertEquals(List.of("Dimension 'main' borrowedDimensionType must be a namespaced dimension type key such as aether:the_aether, but was '42'."),
|
||||
validate("{\"borrowedDimensionType\":42}"));
|
||||
}
|
||||
|
||||
private static List<String> validate(String json) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
PackDimensionValidator.validateBorrowedDimensionType("main", new JSONObject(json), errors);
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "1720dcd78ce7d4ef6fc601cb8d8703d42a35625e8038ab04e98db03514df5959";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "2db2ba19e3466b7c686adca580943c1cc832bf0b44a0568e8db86a920116cfc0";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
+34
@@ -153,6 +153,40 @@ public class GenerationRegistryContractFactoryTest {
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedDimensionTypeIsRecordedAsAnExternalDefinitionInsteadOfAGeneratedType() throws Exception {
|
||||
File pack = temporary.newFolder("borrowed-pack");
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(pack);
|
||||
when(data.getContentGate()).thenReturn(mock(ContentGate.class));
|
||||
IrisDimension dimension = spy(new IrisDimension().setBorrowedDimensionType("aether:the_aether"));
|
||||
dimension.setLoadKey("skylands");
|
||||
stubDimensions(data, dimension);
|
||||
doReturn(new KList<>()).when(dimension).getReachableBiomes(any());
|
||||
doReturn(new KList<>()).when(dimension).getAllRegions(any());
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.blockTypeKeys()).thenReturn(new KList<>());
|
||||
when(registries.entityKeys()).thenReturn(new KList<>());
|
||||
FakeGenerationRegistry generationRegistry = new FakeGenerationRegistry("test-runtime");
|
||||
|
||||
GenerationRegistryContract contract = GenerationRegistryContractFactory.create(
|
||||
data,
|
||||
dimension,
|
||||
GenerationPackFingerprint.compute(pack.toPath(), GenerationPackFingerprint.CURRENT_VERSION),
|
||||
DataVersion.getLatest().get(),
|
||||
registries,
|
||||
generationRegistry
|
||||
);
|
||||
|
||||
GenerationRegistryContract.PhysicalResourceKey borrowed = key(
|
||||
GenerationRegistryContractFactory.DIMENSION_TYPE_REGISTRY, "aether:the_aether");
|
||||
assertTrue(contract.definitions().containsKey(borrowed));
|
||||
assertFalse(contract.generatedSources().containsKey(borrowed));
|
||||
assertFalse(contract.definitions().containsKey(key(
|
||||
GenerationRegistryContractFactory.DIMENSION_TYPE_REGISTRY, "test:skylands_type")));
|
||||
assertEquals("aether:the_aether", dimension.dimensionTypeResourceKey(generationRegistry, "borrowed-pack"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateLogicalBiomeIdsKeepExactDefinitionsAndChooseStableLegacyAlias() throws Exception {
|
||||
File pack = temporary.newFolder("duplicate-biomes");
|
||||
|
||||
Reference in new issue
Block a user