mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Batch 3 of the API review: Iris offers its facades as extensions
- IrisPackWorld offers IrisSeeds, LiveWorld, ObjectHost, FloatingHost, StructureHost (and the engine to the structure built-ins) through extension(); IrisPackSettings the facades a reach needs. withLog, the Source interfaces and the of(...) casts are gone (HostExtensions). - The invocation inputs offer IrisChunk / IrisMantleChunk, MatterMantle and ObjectPlacement; IrisChunk.current(), IrisMantleChunk.current() and IrisPlacement.runBound are gone. A chunk stage's MatterMantle is its own chunk plus the loaded neighbours (OwnChunkMatter). - IrisPackResources serves find(kind, id) / ids(kind) and maps ids back to pack keys at the host's edge (keyOf); ModuleServices, ContentServices, the settings decoder (a bare ResourceId is the pack's id), ModuleSettings and CaveBiomeAnswers convert there. - MantleCaverns, IrisModuleMantle and PlacementMantle answer isCarved. - Starts get a StartKey per platform start (weakly held). - Bukkit adapters read the Optional-valued items, entities and effects. - Tests follow; the loot and entity pins are retaken after checking that the old printing of the new values gives the old hashes.
This commit is contained in:
1 parent
7fc4445ab7
commit
4bacc306e9
82 files changed
+783
-693
No files matched your search
@@ -50,6 +50,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -133,9 +134,9 @@ public class BuiltInModulesJarServicesTest {
|
||||
try (LoadedPack loaded = load()) {
|
||||
Loot loot = loaded.catalog().services(Loot.class).getFirst();
|
||||
|
||||
List<Loot.Source> tables = loot.tables(world, new Loot.Site(AT, null, false, false));
|
||||
List<Loot.Source> tables = loot.tables(world, new Loot.Site(AT, Optional.empty(), false, false));
|
||||
|
||||
assertEquals(List.of(new Loot.Table("dungeon/chest")), tables);
|
||||
assertEquals(List.of(new Loot.Table(world.resources().idOf("dungeon/chest"))), tables);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +186,9 @@ public class CarveSettingsDecodingTest {
|
||||
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"carvingBiome\": \"carving/mushroom\"}"), "biome test");
|
||||
|
||||
assertEquals("carving/mushroom", settings.find(CarvingBiomeSettings.class).orElseThrow().biome());
|
||||
assertEquals(Set.of("carving/mushroom"), settings.treeBiomes());
|
||||
assertEquals(Set.of(), settings.usedBiomes(ModuleSettings.NONE));
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
assertEquals(Set.of("carving/mushroom"), settings.treeBiomes(resources));
|
||||
assertEquals(Set.of(), settings.usedBiomes(resources, ModuleSettings.NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
@@ -40,7 +41,7 @@ import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
@@ -62,7 +63,7 @@ import static org.mockito.Mockito.when;
|
||||
* own noise over an empty pack, a few blocks by name and the world's seeds, all in memory, so the module is tested through IrisApi alone.
|
||||
* Biomes and regions have the ids {@code test:<key>}; a declaration made for {@code <key>} has the source {@code test:<kind>/<key>}.
|
||||
*/
|
||||
public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
||||
public final class CarveTestWorld implements PackWorld {
|
||||
public static final String NAMESPACE = "test";
|
||||
public static final int MIN_HEIGHT = -64;
|
||||
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
|
||||
@@ -149,13 +150,9 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
return seed == IrisSeed.CARVE ? carveSeed : carveSeed + seed.ordinal();
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
IrisSeeds seeds = seed -> seed == IrisSeed.CARVE ? carveSeed : carveSeed + seed.ordinal();
|
||||
return type == IrisSeeds.class ? Optional.of(type.cast(seeds)) : Optional.empty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -196,17 +193,16 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
||||
if (key.type() != PackBiome.class) {
|
||||
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||
if (!kind.equals(BIOMES)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.ofNullable((T) biomes.get(key.id()));
|
||||
return Optional.ofNullable(kind.type().cast(biomes.get(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceId> ids(Class<?> type) {
|
||||
return type == PackBiome.class ? biomes.keySet().stream().sorted().toList() : List.of();
|
||||
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||
return kind.equals(BIOMES) ? biomes.keySet().stream().sorted().toList() : List.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public class DimensionBottomTest {
|
||||
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
||||
record(context.terrain());
|
||||
viewBounds.add(context.access().bounds());
|
||||
ObjectPlacement.current().anchoredAt(BOTTOM);
|
||||
context.extension(ObjectPlacement.class).orElseThrow().anchoredAt(BOTTOM);
|
||||
context.access().set(new PlacedBlock(new BlockPosition(0, BOTTOM, 0), STONE, Optional.empty()));
|
||||
context.access().mantle().layer(MARKS).set(0, BOTTOM, 0, "bottom");
|
||||
});
|
||||
@@ -187,7 +187,7 @@ public class DimensionBottomTest {
|
||||
public void aMantleStageWritingAtHeightZeroHitsTheBottomOfTheMantle() {
|
||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).stream()
|
||||
.filter(component -> component.stage().stage().id().toString().equals("test:bottom/mantle"))
|
||||
.forEach(component -> component.generate(0, 0, storage::chunk));
|
||||
.forEach(component -> component.generate(0, 0, storage::chunk, new IrisMantleChunk(engine, null, 0, 0, null)));
|
||||
|
||||
assertEquals("bottom", storage.value(MARKS, TEXT, 0, BOTTOM, 0));
|
||||
assertSamplesAndBoundsAgree();
|
||||
|
||||
@@ -120,10 +120,11 @@ public class FloatingSettingsDecodingTest {
|
||||
ModuleSettings biomeSettings = decoder.decode(Level.BIOME, biome, "biome magnetics/plains");
|
||||
ModuleSettings dimensionSettings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld");
|
||||
|
||||
Set<String> used = biomeSettings.usedBiomes(dimensionSettings);
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
Set<String> used = biomeSettings.usedBiomes(resources, dimensionSettings);
|
||||
|
||||
assertEquals(new LinkedHashSet<>(List.of("mushroom/forest", "carving/mushroom", "tropical/wilds", "carving/lush-child")), used);
|
||||
assertEquals(Set.of(), biomeSettings.treeBiomes());
|
||||
assertEquals(Set.of(), biomeSettings.treeBiomes(resources));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,9 +134,10 @@ public class FloatingSettingsDecodingTest {
|
||||
ModuleSettings biomeSettings = BuiltInPack.settings(new FloatingChildSettings(List.of(child)));
|
||||
ModuleSettings dimensionSettings = BuiltInPack.settings(new CarvingSettings(List.of(band)));
|
||||
|
||||
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(dimensionSettings));
|
||||
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(resources, dimensionSettings));
|
||||
assertEquals("without bands the name is taken as a biome key", new LinkedHashSet<>(List.of("floating/target", "deep")),
|
||||
biomeSettings.usedBiomes(ModuleSettings.NONE));
|
||||
biomeSettings.usedBiomes(resources, ModuleSettings.NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -86,7 +86,7 @@ public class IrisLiveWorldTest {
|
||||
ModuleResourceFixture.serve(data);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getMinHeight()).thenReturn(BOTTOM);
|
||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
||||
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -118,11 +118,20 @@ public class IrisModuleMantleTest {
|
||||
@Test
|
||||
public void theMatterSideGivesTheMantleChunksTheInvocationReachesAndNoOthers() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
MatterMantle matter = MatterMantle.of(mantle);
|
||||
MatterMantle matter = mantle;
|
||||
|
||||
org.junit.Assert.assertSame(chunk(3, 4), matter.chunk(3, 4));
|
||||
org.junit.Assert.assertNull("nothing is loaded that the host did not say is", matter.loadedChunk(3, 4));
|
||||
org.junit.Assert.assertThrows(IllegalArgumentException.class, () -> MatterMantle.of(new InMemoryOnly()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aChunkInvocationsMatterHoldsItsOwnChunkAndReadsNeighboursOnlyWhenLoaded() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 48, HEIGHT, 48));
|
||||
MatterMantle own = new OwnChunkMatter(mantle, 1, 1);
|
||||
|
||||
org.junit.Assert.assertSame(chunk(1, 1), own.chunk(1, 1));
|
||||
org.junit.Assert.assertNull("a neighbour is no chunk of the invocation's own", own.chunk(2, 1));
|
||||
org.junit.Assert.assertNull("a neighbour the world does not hold is not read", own.loadedChunk(2, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,7 +308,8 @@ public class IrisModuleMantleTest {
|
||||
|
||||
try (LoadedPack pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
|
||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk);
|
||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk,
|
||||
new IrisMantleChunk(engine, null, 0, 0, null));
|
||||
|
||||
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
|
||||
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
|
||||
@@ -317,32 +327,4 @@ public class IrisModuleMantleTest {
|
||||
private static DataInputStream input(byte[] bytes) {
|
||||
return new DataInputStream(new ByteArrayInputStream(bytes));
|
||||
}
|
||||
|
||||
/** A mantle that is none of Iris's. */
|
||||
private static final class InMemoryOnly implements com.volmit.mantle.Mantle {
|
||||
@Override
|
||||
public BlockBox bounds() {
|
||||
return new BlockBox(0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MantleLayer<T> layer(MantleKey<T> key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<BlockState> blocks() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,9 @@ import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackRegion;
|
||||
@@ -109,21 +110,21 @@ public class IrisPackResourcesTest {
|
||||
|
||||
@Test
|
||||
public void aPackObjectIsItsGeometry() {
|
||||
Optional<GeneratedObject> found = resources.find(new ResourceKey<>(id("trees/oak"), GeneratedObject.class));
|
||||
Optional<GeneratedObject> found = resources.find(PackResources.OBJECTS, id("trees/oak"));
|
||||
|
||||
assertSame(tree, found.orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackBiomeIsBuiltFromTheBiomeFile() {
|
||||
PackBiome biome = resources.require(new ResourceKey<>(id("desert/dunes"), PackBiome.class));
|
||||
PackBiome biome = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||
|
||||
assertEquals(new PackBiome(id("desert/dunes"), "Dunes", ResourceId.parse("minecraft:desert"), 3, List.of(id("desert/oasis"))), biome);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackRegionIsBuiltFromTheRegionFileWithItsFourBiomeListsAsPackIds() {
|
||||
PackRegion region = resources.require(new ResourceKey<>(id("desert"), PackRegion.class));
|
||||
PackRegion region = resources.require(PackResources.REGIONS, id("desert"));
|
||||
|
||||
assertEquals(new PackRegion(id("desert"), "The Desert", 2, List.of(id("desert/dunes")), List.of(id("ocean")),
|
||||
List.of(id("beach")), List.of(id("caves/dry"))), region);
|
||||
@@ -131,8 +132,8 @@ public class IrisPackResourcesTest {
|
||||
|
||||
@Test
|
||||
public void oneIdCanBeABiomeAndARegion() {
|
||||
PackBiome biome = resources.require(new ResourceKey<>(id("desert"), PackBiome.class));
|
||||
PackRegion region = resources.require(new ResourceKey<>(id("desert"), PackRegion.class));
|
||||
PackBiome biome = resources.require(PackResources.BIOMES, id("desert"));
|
||||
PackRegion region = resources.require(PackResources.REGIONS, id("desert"));
|
||||
|
||||
assertEquals("Desert biome", biome.name());
|
||||
assertEquals("The Desert", region.name());
|
||||
@@ -140,19 +141,27 @@ public class IrisPackResourcesTest {
|
||||
|
||||
@Test
|
||||
public void anIdThePackLacksForThatKindIsAbsent() {
|
||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(id("desert/dunes"), PackRegion.class)));
|
||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(id("trees/birch"), GeneratedObject.class)));
|
||||
assertEquals(Optional.empty(), resources.find(PackResources.REGIONS, id("desert/dunes")));
|
||||
assertEquals(Optional.empty(), resources.find(PackResources.OBJECTS, id("trees/birch")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anIdOfAnotherNamespaceIsAbsent() {
|
||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(new ResourceId("other", "trees/oak"), GeneratedObject.class)));
|
||||
assertEquals(Optional.empty(), resources.find(PackResources.OBJECTS, new ResourceId("other", "trees/oak")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTypeIrisDoesNotServeIsRejectedWhetherOrNotTheIdExists() {
|
||||
assertThrows(IllegalArgumentException.class, () -> resources.find(new ResourceKey<>(id("trees/oak"), String.class)));
|
||||
assertThrows(IllegalArgumentException.class, () -> resources.find(new ResourceKey<>(id("missing"), String.class)));
|
||||
public void aKindIrisDoesNotServeIsRejectedWhetherOrNotTheIdExists() {
|
||||
ResourceKind<GeneratedObject> unserved = ResourceKind.of("test:unserved", "unserved", GeneratedObject.class);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> resources.find(unserved, id("trees/oak")));
|
||||
assertThrows(IllegalArgumentException.class, () -> resources.find(unserved, id("missing")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theIdsOfAKindAreThePacksKeysOfThatKindInIdOrder() {
|
||||
assertEquals(List.of(id("desert"), id("desert/dunes")), resources.ids(PackResources.BIOMES));
|
||||
assertEquals(List.of(id("trees/oak")), resources.ids(PackResources.OBJECTS));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,15 +169,13 @@ public class IrisPackResourcesTest {
|
||||
when(objectLoader.getPossibleKeys()).thenReturn(new String[]{"trees/broken"});
|
||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> fresh.find(new ResourceKey<>(id("trees/broken"), GeneratedObject.class)));
|
||||
assertThrows(IllegalStateException.class, () -> fresh.find(PackResources.OBJECTS, id("trees/broken")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eachResourceIsBuiltOncePerSnapshot() {
|
||||
ResourceKey<PackBiome> key = new ResourceKey<>(id("desert/dunes"), PackBiome.class);
|
||||
|
||||
PackBiome first = resources.require(key);
|
||||
PackBiome second = resources.require(key);
|
||||
PackBiome first = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||
PackBiome second = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||
|
||||
assertSame(first, second);
|
||||
verify(biomeLoader, times(1)).load("desert/dunes");
|
||||
@@ -182,6 +189,6 @@ public class IrisPackResourcesTest {
|
||||
when(objectLoader.load("Trees/Oak")).thenReturn(object);
|
||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||
|
||||
assertSame(tree, fresh.require(new ResourceKey<>(id("trees/oak"), GeneratedObject.class)));
|
||||
assertSame(tree, fresh.require(PackResources.OBJECTS, id("trees/oak")));
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSampler;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.host.OptionsMetadata;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
@@ -30,7 +31,6 @@ import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -60,15 +60,10 @@ public class IrisWorldFacadesTest {
|
||||
}
|
||||
|
||||
for (IrisSeed seed : IrisSeed.values()) {
|
||||
assertEquals(seed.name(), expected.get(seed).longValue(), seed.of(world));
|
||||
assertEquals(seed.name(), expected.get(seed).longValue(), world.extension(IrisSeeds.class).orElseThrow().seed(seed));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldIrisDoesNotGenerateHasNoIrisSeeds() {
|
||||
assertThrows(IllegalArgumentException.class, () -> IrisSeed.POST.of(mock(PackWorld.class)));
|
||||
}
|
||||
|
||||
private static Engine engine(IrisDimension dimension) {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
@@ -131,24 +132,18 @@ public class ModuleLogTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldViewCarriesTheModulesLogAndSharesTheWorldsState() {
|
||||
public void theWorldOffersIrissOwnCodeTheEngineAndItsSeedsAsExtensions() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getPost()).thenReturn(POST_SEED);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
IrisPackWorld world = new IrisPackWorld(engine);
|
||||
ModuleLog decorant = log();
|
||||
PackWorld world = new IrisPackWorld(engine);
|
||||
|
||||
PackWorld view = world.withLog(decorant);
|
||||
|
||||
assertSame(decorant, view.log());
|
||||
assertSame("one view per module", view, world.withLog(decorant));
|
||||
assertSame(view, view.withLog(decorant));
|
||||
assertSame("state is the world's", world.state(Marker.class, ignored -> new Marker()), view.state(Marker.class, ignored -> new Marker()));
|
||||
assertSame("Iris's own code still reaches the engine through a view", engine, IrisPackWorld.of(view).engine());
|
||||
assertEquals("and its seeds", POST_SEED, IrisSeed.POST.of(view));
|
||||
assertSame(engine, world.extension(Engine.class).orElseThrow());
|
||||
assertEquals(POST_SEED, world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.POST));
|
||||
assertTrue("nothing else is offered", world.extension(String.class).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,7 +167,4 @@ public class ModuleLogTest {
|
||||
private String err() {
|
||||
return err.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static final class Marker {
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -34,7 +35,7 @@ public final class ModuleResourceFixture {
|
||||
private static final Map<IrisPackResources, ModuleResourceFixture> SERVED = new IdentityHashMap<>();
|
||||
|
||||
private final IrisPackResources resources;
|
||||
private final Map<Class<?>, List<ResourceId>> ids = new HashMap<>();
|
||||
private final Map<ResourceKind<?>, List<ResourceId>> ids = new HashMap<>();
|
||||
|
||||
private ModuleResourceFixture(IrisPackResources resources) {
|
||||
this.resources = resources;
|
||||
@@ -45,6 +46,8 @@ public final class ModuleResourceFixture {
|
||||
IrisPackResources resources = mock(IrisPackResources.class);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(resources.idOf(anyString())).thenAnswer(invocation -> idOf(invocation.getArgument(0)));
|
||||
when(resources.keyOf(any(ResourceId.class))).thenAnswer(invocation -> keyOf(invocation.getArgument(0)));
|
||||
when(resources.keyOf(any(ResourceKind.class), any(ResourceId.class))).thenAnswer(invocation -> keyOf(invocation.getArgument(1)));
|
||||
ModuleResourceFixture fixture = new ModuleResourceFixture(resources);
|
||||
SERVED.put(resources, fixture);
|
||||
return fixture;
|
||||
@@ -82,14 +85,18 @@ public final class ModuleResourceFixture {
|
||||
/** Serves {@code resource} as the resource of {@code kind} the pack names by {@code key}. */
|
||||
public <T> ModuleResourceFixture resource(ResourceKind<T> kind, String key, T resource) {
|
||||
ResourceId id = idOf(key);
|
||||
when(resources.find(kind.key(id))).thenReturn(Optional.of(resource));
|
||||
List<ResourceId> kindIds = ids.computeIfAbsent(kind.type(), ignored -> new ArrayList<>());
|
||||
when(resources.find(kind, id)).thenReturn(Optional.of(resource));
|
||||
List<ResourceId> kindIds = ids.computeIfAbsent(kind, ignored -> new ArrayList<>());
|
||||
kindIds.add(id);
|
||||
when(resources.ids(kind.type())).thenReturn(kindIds.stream().sorted().toList());
|
||||
when(resources.ids(kind)).thenReturn(kindIds.stream().sorted().toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
private static ResourceId idOf(String key) {
|
||||
return new ResourceId(NAMESPACE, key.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9_./-]", "_"));
|
||||
}
|
||||
|
||||
private static String keyOf(ResourceId id) {
|
||||
return id.namespace().equals(NAMESPACE) ? id.path() : id.toString();
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import com.volmit.ModuleSetup;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
@@ -88,30 +89,30 @@ public class ModuleServicesTest {
|
||||
var registry = setup.registry();
|
||||
registry.registerService(ObjectsAt.class, new ObjectsAt() {
|
||||
@Override
|
||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
public Set<ResourceId> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
logOwners.add(id + (world.log() == registeredLog ? " has its own log" : " has another module's log"));
|
||||
return Set.of(object + "@" + chunkX + "," + chunkZ);
|
||||
return Set.of(world.resources().idOf(object + "/" + chunkX + "/" + chunkZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
||||
return new PlacedBy(Set.of(object + "-biome"), Set.of(id + "-region"));
|
||||
public PlacedBy placedBy(PackWorld world, ResourceId placedObject) {
|
||||
return new PlacedBy(Set.of(world.resources().idOf(object + "-biome")), Set.of(world.resources().idOf(id.replace(':', '-') + "-region")));
|
||||
}
|
||||
});
|
||||
registry.registerService(StructureLocator.class, new StructureLocator() {
|
||||
@Override
|
||||
public Set<String> structures(PackResources resources) {
|
||||
return Set.of(structure, structure + "/unplaced");
|
||||
public Set<ResourceId> structures(PackResources resources) {
|
||||
return Set.of(resources.idOf(structure), resources.idOf(structure + "/unplaced"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> locatable(PackWorld world) {
|
||||
return Set.of(structure);
|
||||
public Set<ResourceId> locatable(PackWorld world) {
|
||||
return Set.of(world.resources().idOf(structure));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
searches.add(id + " " + key + " " + fromX + " " + fromZ + " " + maxRadiusChunks);
|
||||
public LocateResult locate(PackWorld world, ResourceId located, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
searches.add(id + " " + located.path() + " " + fromX + " " + fromZ + " " + maxRadiusChunks);
|
||||
return LocateResult.found(new BlockPosition(fromX + 16, 70, fromZ));
|
||||
}
|
||||
});
|
||||
@@ -130,6 +131,7 @@ public class ModuleServicesTest {
|
||||
when(modules.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(modules);
|
||||
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
||||
PackResourceFixture.holdNoObjectsBiomesOrRegions(data);
|
||||
IrisPackResources resources = new IrisPackResources(data, List::of);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
engine = mock(Engine.class);
|
||||
@@ -148,7 +150,7 @@ public class ModuleServicesTest {
|
||||
|
||||
@Test
|
||||
public void objectsAtCombinesEveryModulesObjectsInModuleOrder() {
|
||||
assertEquals(List.of("tree@3,-4", "bush@3,-4", "rock@3,-4"), List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
||||
assertEquals(List.of("tree/3/-4", "bush/3/-4", "rock/3/-4"),List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,10 +162,10 @@ public class ModuleServicesTest {
|
||||
|
||||
@Test
|
||||
public void objectPlacersCombineTheBiomesAndRegionsOfEveryModule() {
|
||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, "trees/oak");
|
||||
ModuleServices.ObjectPlacers placers = ModuleServices.objectPlacers(engine, "trees/oak");
|
||||
|
||||
assertEquals(Set.of("rock-biome", "tree-biome", "bush-biome"), placers.biomes());
|
||||
assertEquals(Set.of("test:zeta-region", "test:alpha-region", "test:beta-region"), placers.regions());
|
||||
assertEquals(Set.of("test-zeta-region", "test-alpha-region", "test-beta-region"), placers.regions());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,7 +183,7 @@ public class ModuleServicesTest {
|
||||
ModuleServices.StructureSearch result = ModuleServices.locateStructure(engine, "Castle", 100, -200, 64);
|
||||
|
||||
assertEquals(new ModuleServices.StructureSearch(ModuleServices.StructureSearch.Outcome.FOUND, 116, 70 - 64, -200), result);
|
||||
assertEquals(List.of("test:beta Castle 100 -200 64"), searches);
|
||||
assertEquals("the key is read as the pack's lower-case id", List.of("test:beta castle 100 -200 64"), searches);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ModuleWorldsTest {
|
||||
assertEquals(List.of("loaded", "started"), calls);
|
||||
assertEquals(SEED, world.seed());
|
||||
assertSame(data.getPackResources(), world.resources());
|
||||
assertSame(engine, IrisPackWorld.of(world).engine());
|
||||
assertSame(engine, world.engine());
|
||||
Remembered built = world.state(Remembered.class, ignored -> new Remembered(calls));
|
||||
assertSame(built, generation.state(Remembered.class, ignored -> new Remembered(calls)));
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ public class PackModuleResourceKindTest {
|
||||
|
||||
public final class KeepValidator implements Validator {
|
||||
public void validate(ValidationContext pack) {
|
||||
for (ResourceId id : pack.resources().ids(Keep.class)) {
|
||||
Keep keep = pack.resources().require(CastleModule.KEEPS.key(id));
|
||||
for (ResourceId id : pack.resources().ids(CastleModule.KEEPS)) {
|
||||
Keep keep = pack.resources().require(CastleModule.KEEPS, id);
|
||||
if (keep.towers() > 8) {
|
||||
pack.report(Problem.error(Subject.file("keeps/" + id.path() + ".json"), "Keep has " + keep.towers() + " towers; at most 8 fit."));
|
||||
}
|
||||
ResourceId next = new ResourceId(id.namespace(), keep.next().isEmpty() ? id.path() : keep.next());
|
||||
if (pack.resources().find(CastleModule.KEEPS.key(next)).isEmpty()) {
|
||||
if (pack.resources().find(CastleModule.KEEPS, next).isEmpty()) {
|
||||
pack.report(Problem.warning(Subject.resource(id), "Keep leads to missing keep " + keep.next() + "."));
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class PackModuleResourceKindTest {
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void aPackModulesKindIsReadFromItsFolderAndServedByType() throws Exception {
|
||||
public void aPackModulesKindIsReadFromItsFolderAndServedAsThatKind() throws Exception {
|
||||
Path pack = castlePack("castles");
|
||||
write(pack, "keeps/main.json", "{\"towers\":6,\"next\":\"towers/north\"}");
|
||||
write(pack, "keeps/towers/north.json", "{}");
|
||||
@@ -117,14 +117,14 @@ public class PackModuleResourceKindTest {
|
||||
ResourceKind<?> keeps = keepKind(data);
|
||||
ResourceId main = new ResourceId("castles", "main");
|
||||
|
||||
assertEquals(List.of(main, new ResourceId("castles", "towers/north")), data.getPackResources().ids(keeps.type()));
|
||||
Object keep = data.getPackResources().find(keeps.key(main)).orElseThrow();
|
||||
assertEquals(List.of(main, new ResourceId("castles", "towers/north")), data.getPackResources().ids(keeps));
|
||||
Object keep = data.getPackResources().find(keeps, main).orElseThrow();
|
||||
assertEquals(6, keep.getClass().getMethod("towers").invoke(keep));
|
||||
assertEquals("towers/north", keep.getClass().getMethod("next").invoke(keep));
|
||||
Object north = data.getPackResources().find(keeps.key(new ResourceId("castles", "towers/north"))).orElseThrow();
|
||||
Object north = data.getPackResources().find(keeps, new ResourceId("castles", "towers/north")).orElseThrow();
|
||||
assertEquals("an omitted field keeps its default", 4, north.getClass().getMethod("towers").invoke(north));
|
||||
assertSame("read once per pack load", keep, data.getPackResources().find(keeps.key(main)).orElseThrow());
|
||||
assertTrue(data.getPackResources().find(keeps.key(new ResourceId("castles", "missing"))).isEmpty());
|
||||
assertSame("read once per pack load", keep, data.getPackResources().find(keeps, main).orElseThrow());
|
||||
assertTrue(data.getPackResources().find(keeps, new ResourceId("castles", "missing")).isEmpty());
|
||||
assertTrue(data.getPackResources().moduleFolderNames().containsAll(List.of("keeps", "structures")));
|
||||
assertTrue(data.resourceFolderNames().contains("keeps"));
|
||||
} finally {
|
||||
@@ -140,7 +140,7 @@ public class PackModuleResourceKindTest {
|
||||
try {
|
||||
ResourceKind<?> keeps = keepKind(data);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> data.getPackResources().find(keeps.key(new ResourceId("broken-castles", "main"))));
|
||||
assertThrows(IllegalStateException.class, () -> data.getPackResources().find(keeps, new ResourceId("broken-castles", "main")));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.List;
|
||||
@@ -39,8 +41,31 @@ public final class PackResourceFixture {
|
||||
return resources;
|
||||
}
|
||||
|
||||
/** The key of the oak in the pack in {@code packFolder}. */
|
||||
public static ResourceKey<GeneratedObject> oakKey(java.io.File packFolder) {
|
||||
return new ResourceKey<>(new PackResourceIds(packFolder).of(OAK_KEY), GeneratedObject.class);
|
||||
/** The oak {@code resources} serve, as a module finds it by its key. */
|
||||
public static GeneratedObject oak(PackResources resources) {
|
||||
return resources.require(PackResources.OBJECTS, resources.idOf(OAK_KEY));
|
||||
}
|
||||
|
||||
/** The resources of a pack in {@code packFolder} without objects, biomes or regions, which names its keys by id. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static IrisPackResources empty(java.io.File packFolder) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(packFolder);
|
||||
holdNoObjectsBiomesOrRegions(data);
|
||||
return new IrisPackResources(data, List::of);
|
||||
}
|
||||
|
||||
/** Makes {@code data} (a mock) a pack without objects, biomes or regions, so resources built over it index none. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void holdNoObjectsBiomesOrRegions(IrisData data) {
|
||||
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisRegion> regions = mock(ResourceLoader.class);
|
||||
when(objects.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(biomes.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(regions.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(data.getObjectLoader()).thenReturn(objects);
|
||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||
when(data.getRegionLoader()).thenReturn(regions);
|
||||
}
|
||||
}
|
||||
@@ -44,17 +44,16 @@ public class ToolWorldTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyLogViewSharesTheStateAndClosingTheWorldClosesIt() {
|
||||
public void theWorldKeepsItsStateUntilItIsClosed() {
|
||||
PackResources resources = mock(PackResources.class);
|
||||
Tracked tracked;
|
||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class))) {
|
||||
tracked = world.state(Tracked.class, ignored -> new Tracked());
|
||||
PackWorld view = world.withLog(mock(ModuleLog.class));
|
||||
|
||||
assertSame(tracked, view.state(Tracked.class, ignored -> new Tracked()));
|
||||
assertSame(resources, view.resources());
|
||||
assertEquals(SEED, view.seed());
|
||||
assertEquals(0, view.minHeight());
|
||||
assertSame(tracked, world.state(Tracked.class, ignored -> new Tracked()));
|
||||
assertSame(resources, world.resources());
|
||||
assertEquals(SEED, world.seed());
|
||||
assertEquals(0, world.minHeight());
|
||||
assertFalse(tracked.closed);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public class TreeDefinitionIndexTest {
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<IrisRegion>().qadd(region));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.decorant.Decorator;
|
||||
@@ -71,7 +72,7 @@ public class BiomeDecoratorsTest {
|
||||
|
||||
@Test
|
||||
public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() {
|
||||
long decoratorSeed = IrisSeed.DECORATOR.of(world);
|
||||
long decoratorSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.DECORATOR);
|
||||
long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed();
|
||||
long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed();
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleSetup;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.CaveBiomes;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Before;
|
||||
@@ -86,6 +87,7 @@ public class EngineCaveBiomeTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mockEngine() {
|
||||
data = mock(IrisData.class);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||
when(biomes.load("band/deep")).thenReturn(band);
|
||||
@@ -112,13 +114,13 @@ public class EngineCaveBiomeTest {
|
||||
private CaveBiomes caves(String overridden, int minDepth) {
|
||||
return new CaveBiomes() {
|
||||
@Override
|
||||
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return Optional.ofNullable(overridden);
|
||||
public Optional<ResourceId> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return Optional.ofNullable(overridden).map(world.resources()::idOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
||||
return biomeKey.equals("cave/lush") ? minDepth : 0;
|
||||
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||
return biome.equals(world.resources().idOf("cave/lush")) ? minDepth : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -170,14 +172,14 @@ public class EngineCaveBiomeTest {
|
||||
CaveBiomes counting = caves(null, 10);
|
||||
serve(new CaveBiomes() {
|
||||
@Override
|
||||
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return y > SURFACE_Y ? Optional.of("band/deep") : Optional.empty();
|
||||
public Optional<ResourceId> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return y > SURFACE_Y ? Optional.of(world.resources().idOf("band/deep")) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
||||
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||
depthQuestions.incrementAndGet();
|
||||
return counting.minDepthBelowSurface(world, biomeKey);
|
||||
return counting.minDepthBelowSurface(world, biome);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ public class HintedLocatorTest {
|
||||
when(engine.isClosed()).thenReturn(false);
|
||||
when(engine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
stubReachableBiomes();
|
||||
|
||||
+3
-3
@@ -62,7 +62,7 @@ public class StructureResourcesTest {
|
||||
public void theStructureModuleListsThePacksStructuresForIrissIndexThroughItsLocator() throws Exception {
|
||||
IrisData data = IrisData.openValidation(castlePack("listed").toFile());
|
||||
try {
|
||||
assertEquals(Set.of("castle"), new StructureLocating().structures(data.getPackResources()));
|
||||
assertEquals(Set.of(new ResourceId("listed", "castle")), new StructureLocating().structures(data.getPackResources()));
|
||||
assertEquals(Set.of("castle"), ModuleServices.structureKeys(data));
|
||||
} finally {
|
||||
data.close();
|
||||
@@ -81,7 +81,7 @@ public class StructureResourcesTest {
|
||||
assertEquals("castle", castle.getLoadKey());
|
||||
assertEquals(pack.resolve("structures/castle.json").toFile(), castle.getLoadFile());
|
||||
assertSame(data, castle.getLoader());
|
||||
assertSame(castle, data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("castles", "castle"))).orElseThrow());
|
||||
assertSame(castle, data.getPackResources().find(StructureResources.STRUCTURES, new ResourceId("castles", "castle")).orElseThrow());
|
||||
assertEquals("castle/start", StructureResources.pool(data, "castle/start").getPieces().getFirst().getPiece());
|
||||
assertEquals("castle/start", StructureResources.piece(data, "castle/start").getObject());
|
||||
assertEquals(List.of("castle"), StructureResources.structureKeys(data));
|
||||
@@ -101,7 +101,7 @@ public class StructureResourcesTest {
|
||||
try {
|
||||
assertNull(StructureResources.structure(data, "ruin"));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("broken", "ruin"))));
|
||||
() -> data.getPackResources().find(StructureResources.STRUCTURES, new ResourceId("broken", "ruin")));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.vanilla.PieceKind;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
@@ -249,7 +250,7 @@ final class FitFixture {
|
||||
Piece... pieces) {
|
||||
StartMemo memo = new StartMemo(terrainJson, stiltsJson);
|
||||
StructureFit.Start start = new StructureFit.Start() {
|
||||
private final Object key = new Object();
|
||||
private final StartKey key = StartKey.create();
|
||||
|
||||
@Override
|
||||
public ResourceId structure() {
|
||||
@@ -287,7 +288,7 @@ final class FitFixture {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object key() {
|
||||
public StartKey key() {
|
||||
return key;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,6 +37,8 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* What a loot table gives at fixed spots of a fixed world, as the whole drawn items, hashed. The numbers were taken
|
||||
* before the loot classes became settings of the loot module; a change in them changes the loot of existing worlds.
|
||||
* They were retaken once when an item's absent values became {@code Optional}s: the items printed the old way (absent
|
||||
* values as {@code null}) still hashed to the old numbers, -492887340, -92432338, -1096436977, -1436497629 and -1714085578.
|
||||
*/
|
||||
public class LootDrawPinTest {
|
||||
private static final long LOOT_SEED = 8123456789L;
|
||||
@@ -78,6 +80,6 @@ public class LootDrawPinTest {
|
||||
hashes.add(drops.toString().hashCode());
|
||||
}
|
||||
|
||||
assertEquals(List.of(-492887340, -92432338, -1096436977, -1436497629, -1714085578), hashes);
|
||||
assertEquals(List.of(-1656514080, 672855254, -359051997, -717275247, 1936773406), hashes);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -52,7 +53,7 @@ public class LootItemsTest {
|
||||
assertEquals(amount, drop.amount());
|
||||
assertEquals(level, drop.enchantments().getFirst().level());
|
||||
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
|
||||
assertEquals(damage, drop.damage(), 0D);
|
||||
assertEquals(damage, drop.damage().orElseThrow(), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +65,7 @@ public class LootItemsTest {
|
||||
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
|
||||
|
||||
assertEquals(2, drop.amount());
|
||||
assertNull(drop.damage());
|
||||
assertTrue(drop.damage().isEmpty());
|
||||
assertEquals(untouched.nextLong(), rng.nextLong());
|
||||
}
|
||||
|
||||
@@ -85,9 +86,9 @@ public class LootItemsTest {
|
||||
List<ItemDrop> drops = new LootItems(registry, true).draw("dungeon", table, LOOT_SEED, 0, 64, 0);
|
||||
|
||||
for (ItemDrop drop : drops) {
|
||||
assertEquals(new ItemDrop.Source("dungeon", 4, 3), drop.source());
|
||||
assertEquals(Optional.of(new ItemDrop.Source(Optional.of("dungeon"), 4, 3)), drop.source());
|
||||
}
|
||||
assertTrue(new LootItems(registry, false).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source() == null));
|
||||
assertTrue(new LootItems(registry, false).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source().isEmpty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -156,7 +156,7 @@ public class LootValidatorTest {
|
||||
public void aTableThatFailsToLoadIsReportedWithoutStoppingTheCheck() {
|
||||
table("fine", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
table("broken", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
when(resources.find(LootResources.TABLES.key(new ResourceId("test", "broken")))).thenThrow(new IllegalStateException("Expected an int but was STRING at line 1 column 12 path $.rarity"));
|
||||
when(resources.find(LootResources.TABLES, new ResourceId("test", "broken"))).thenThrow(new IllegalStateException("Expected an int but was STRING at line 1 column 12 path $.rarity"));
|
||||
|
||||
assertEquals(List.of("Loot table 'broken' cannot be read: Expected an int but was STRING at line 1 column 12 path $.rarity"), errors());
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class PlacementLootTest {
|
||||
private static final String EAST_CHEST = "minecraft:chest[facing=east]";
|
||||
private static final long LOOT_SEED = 99L;
|
||||
|
||||
private PackResources resources;
|
||||
private PlacementLoot placement;
|
||||
|
||||
@Before
|
||||
@@ -63,7 +64,7 @@ public class PlacementLootTest {
|
||||
for (String key : List.of("everywhere", "chests", "this-chest", "other")) {
|
||||
fixture.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, "{\"name\": \"" + key + "\"}"));
|
||||
}
|
||||
PackResources resources = data.getPackResources();
|
||||
resources = data.getPackResources();
|
||||
BlockRegistry blocks = mock(BlockRegistry.class);
|
||||
when(resources.blocks()).thenReturn(blocks);
|
||||
when(blocks.resolve(any(BlockState.class))).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
@@ -71,19 +72,23 @@ public class PlacementLootTest {
|
||||
placement = new PlacementLoot(resources, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
private Loot.Table table(String key) {
|
||||
return new Loot.Table(resources.idOf(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTableThatNamesTheExactStateBeatsOneThatNamesTheKindOfBlock() {
|
||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("chests", 1, false, CHEST), entry("this-chest", 1, true, CHEST));
|
||||
|
||||
assertEquals(new Loot.Table("this-chest"), pick(List.of(), pack, CHEST));
|
||||
assertEquals(new Loot.Table("chests"), pick(List.of(), pack, EAST_CHEST));
|
||||
assertEquals(table("this-chest"), pick(List.of(), pack, CHEST));
|
||||
assertEquals(table("chests"), pick(List.of(), pack, EAST_CHEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTableThatNamesNoBlockServesChestsNothingElseNames() {
|
||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("other", 1, false, "minecraft:barrel"));
|
||||
|
||||
assertEquals(new Loot.Table("everywhere"), pick(List.of(), pack, CHEST));
|
||||
assertEquals(table("everywhere"), pick(List.of(), pack, CHEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,10 +106,10 @@ public class PlacementLootTest {
|
||||
|
||||
for (int i = 0; i < 4000; i++) {
|
||||
Loot.Source picked = placement.pick(List.of(), pack, BlockState.parse(CHEST), rng, 0, 64, 0);
|
||||
if (picked.equals(new Loot.Table("everywhere"))) {
|
||||
if (picked.equals(table("everywhere"))) {
|
||||
everywhere++;
|
||||
} else {
|
||||
assertEquals(new Loot.Table("chests"), picked);
|
||||
assertEquals(table("chests"), picked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-11
@@ -56,7 +56,7 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
|
||||
private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
|
||||
FloatingHost floating = mock(FloatingHost.class);
|
||||
return new FloatingPack() {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
|
||||
@@ -65,17 +65,12 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHost objects() {
|
||||
return objects;
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
if (type == FloatingHost.class) {
|
||||
return Optional.of(type.cast(floating));
|
||||
}
|
||||
return type == ObjectHost.class ? Optional.of(type.cast(objects)) : Optional.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private interface FloatingPack extends PackSettings, FloatingHost.Source, ObjectHost.Source {
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
@@ -14,23 +15,23 @@ import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
/** Object placing builds its placements' noise and its procedural objects' variants before generation asks. */
|
||||
public class ObjectWarmUpTest {
|
||||
@Test
|
||||
public void everyPlacementAndProceduralObjectOfBiomesAndRegionsIsBuilt() {
|
||||
ObjectHost host = mock(ObjectHost.class);
|
||||
IrisSeed.Source seeds = mock(IrisSeed.Source.class);
|
||||
PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(ObjectHost.Source.class, IrisSeed.Source.class));
|
||||
when(((ObjectHost.Source) world).objects()).thenReturn(host);
|
||||
when(((IrisSeed.Source) world).seed(IrisSeed.COMPONENT)).thenReturn(1337L);
|
||||
IrisSeeds seeds = seed -> seed == IrisSeed.COMPONENT ? 1337L : 0L;
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.extension(IrisSeeds.class)).thenReturn(Optional.of(seeds));
|
||||
ObjectPlacement biomePlacement = placement();
|
||||
ObjectPlacement regionPlacement = placement();
|
||||
ProceduralObjectSettings biomeProceduralSettings = new ProceduralObjectSettings();
|
||||
|
||||
@@ -44,7 +44,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
/** Trees only replace the platform's growth when the dimension asks for it and a placement of the area grows that species. */
|
||||
public class TreeGrowingTest {
|
||||
@@ -63,8 +62,8 @@ public class TreeGrowingTest {
|
||||
host = mock(ObjectHost.class);
|
||||
settings = mock(FeatureSettings.class);
|
||||
when(host.columnSettings()).thenReturn(settings);
|
||||
world = mock(PackWorld.class, withSettings().extraInterfaces(ObjectHost.Source.class));
|
||||
when(((ObjectHost.Source) world).objects()).thenReturn(host);
|
||||
world = mock(PackWorld.class);
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
||||
@@ -74,7 +74,7 @@ import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.stage.Pipeline;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
@@ -338,6 +338,11 @@ public final class ApiChunk implements GenerationContext {
|
||||
return new ChunkMantle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return type == MatterMantle.class ? Optional.of(type.cast(new ChunkMantle())) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Hunk<T> hunk(Class<T> type) {
|
||||
@@ -488,8 +493,8 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new CarvedLayer();
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return carved.contains(new BlockPosition(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -534,55 +539,21 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
}
|
||||
|
||||
private final class CarvedLayer implements MantleLayer<Boolean> {
|
||||
@Override
|
||||
public Boolean get(int x, int y, int z) {
|
||||
return carved.contains(new BlockPosition(x, y, z)) ? Boolean.TRUE : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, Boolean value) {
|
||||
throw new UnsupportedOperationException("Caverns are read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("Caverns are read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
|
||||
List<BlockPosition> positions = new ArrayList<>(carved);
|
||||
positions.sort(VISIT_ORDER);
|
||||
for (BlockPosition position : positions) {
|
||||
if (area.contains(position.x(), position.y(), position.z())) {
|
||||
visitor.accept(position.x(), position.y(), position.z(), Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException("Caverns are read-only");
|
||||
}
|
||||
}
|
||||
|
||||
/** A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. */
|
||||
/** A world without floating islands: its floating host answers no surface biome, so no column has an island. */
|
||||
private final class World implements PackWorld, IrisSeed.Source, FloatingHost.Source, ObjectHost.Source {
|
||||
/**
|
||||
* A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. It has
|
||||
* no floating islands: its floating host answers no surface biome, so no column has an island.
|
||||
*/
|
||||
private final class World implements PackWorld {
|
||||
private final Resources resources = new Resources();
|
||||
private final Map<Class<?>, Object> states = new HashMap<>();
|
||||
private final IrisSeeds seeds = seed -> SEED + seed.ordinal();
|
||||
private final FloatingHost floating = mock(FloatingHost.class);
|
||||
private final ObjectHost objects = mock(ObjectHost.class);
|
||||
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHost objects() {
|
||||
return objects;
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
Object offered = type == IrisSeeds.class ? seeds : type == FloatingHost.class ? floating : type == ObjectHost.class ? objects : null;
|
||||
return Optional.ofNullable(offered).map(type::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -620,15 +591,6 @@ public final class ApiChunk implements GenerationContext {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
return SEED + seed.ordinal();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Resources implements PackResources {
|
||||
@@ -670,12 +632,12 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
||||
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceId> ids(Class<?> type) {
|
||||
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,19 +57,19 @@ public class CaveBiomeBandsTest {
|
||||
public void aPositionInsideAnEnabledBandGetsTheBandsBiomeKey() {
|
||||
CaveBiomeBands bands = new CaveBiomeBands();
|
||||
|
||||
assertEquals("world Y -54 is in the band from -64 to 0", Optional.of("band/shallow"), bands.overriddenBiome(world, 5, 10, 5));
|
||||
assertEquals("the band's end is in it", Optional.of("band/shallow"), bands.overriddenBiome(world, 5, 64, 5));
|
||||
assertEquals("world Y -54 is in the band from -64 to 0", Optional.of(CarveTestWorld.id("band/shallow")), bands.overriddenBiome(world, 5, 10, 5));
|
||||
assertEquals("the band's end is in it", Optional.of(CarveTestWorld.id("band/shallow")), bands.overriddenBiome(world, 5, 64, 5));
|
||||
assertEquals("above it", Optional.empty(), bands.overriddenBiome(world, 5, 65, 5));
|
||||
assertEquals("a disabled band overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 200 - MIN_HEIGHT - 50, 5));
|
||||
assertEquals("a band whose biome the pack lacks overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 305 - MIN_HEIGHT, 5));
|
||||
assertEquals("the key is trimmed as the pack is asked for it", Optional.of("band/padded"), bands.overriddenBiome(world, 5, 550 - MIN_HEIGHT, 5));
|
||||
assertEquals("the key is trimmed as the pack is asked for it", Optional.of(CarveTestWorld.id("band/padded")), bands.overriddenBiome(world, 5, 550 - MIN_HEIGHT, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBiomeKeyHasTheMinimumDepthItsSettingsDeclareAndZeroWhenTheKeyIsUnknown() {
|
||||
CaveBiomeBands bands = new CaveBiomeBands();
|
||||
|
||||
assertEquals(30, bands.minDepthBelowSurface(world, "band/shallow"));
|
||||
assertEquals(0, bands.minDepthBelowSurface(world, "band/unknown"));
|
||||
assertEquals(30, bands.minDepthBelowSurface(world, CarveTestWorld.id("band/shallow")));
|
||||
assertEquals(0, bands.minDepthBelowSurface(world, CarveTestWorld.id("band/unknown")));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
@@ -16,6 +16,7 @@ import com.volmit.stage.ChunkStageContext;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -25,7 +26,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
/** A column whose biome declares no floating child biomes gets no island: nothing is written or decorated. */
|
||||
public class FloatingIslandsTest {
|
||||
@@ -60,9 +60,10 @@ public class FloatingIslandsTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static PackWorld world(FloatingHost host) {
|
||||
PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(FloatingHost.Source.class, ObjectHost.Source.class, IrisSeed.Source.class));
|
||||
when(((FloatingHost.Source) world).floating()).thenReturn(host);
|
||||
when(((ObjectHost.Source) world).objects()).thenReturn(mock(ObjectHost.class));
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.extension(FloatingHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(mock(ObjectHost.class)));
|
||||
when(world.extension(IrisSeeds.class)).thenReturn(Optional.of(seed -> 0L));
|
||||
when(world.resources()).thenReturn(mock(PackResources.class));
|
||||
PackSettings nothingDeclared = mock(PackSettings.class);
|
||||
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
|
||||
|
||||
+6
-10
@@ -423,11 +423,9 @@ public class IrisObjectPlacementRegressionTest {
|
||||
/** Looks up the pack's oak through the placement's resources. */
|
||||
private static final class FindModule implements IrisModule {
|
||||
private static final PlacementStage<Void> FIND = Stage.placement("test:find/oak");
|
||||
private final java.io.File packFolder;
|
||||
private final List<Object> found;
|
||||
|
||||
private FindModule(java.io.File packFolder, List<Object> found) {
|
||||
this.packFolder = packFolder;
|
||||
private FindModule(List<Object> found) {
|
||||
this.found = found;
|
||||
}
|
||||
|
||||
@@ -439,14 +437,14 @@ public class IrisObjectPlacementRegressionTest {
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(FIND).requires(IrisStages.Blocks.COMPLETE).run(context ->
|
||||
found.add(context.world().resources().find(PackResourceFixture.oakKey(packFolder)).orElseThrow()));
|
||||
found.add(PackResourceFixture.oak(context.world().resources())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPasteWithoutAnEngineFindsThePacksResourcesThroughItsWorld() throws IOException {
|
||||
List<Object> found = new ArrayList<>();
|
||||
usePack(List.of(new FindModule(folder.getRoot(), found)));
|
||||
usePack(List.of(new FindModule(found)));
|
||||
PackResourceFixture.serve(data);
|
||||
|
||||
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
||||
@@ -511,11 +509,9 @@ public class IrisObjectPlacementRegressionTest {
|
||||
/** Lays the pack's oak on its side, a quarter turn about X, through the placement's object transformer. */
|
||||
private static final class TurnModule implements IrisModule {
|
||||
private static final PlacementStage<Void> TURN = Stage.placement("test:turn/oak");
|
||||
private final java.io.File packFolder;
|
||||
private final List<GeneratedObject> turned;
|
||||
|
||||
private TurnModule(java.io.File packFolder, List<GeneratedObject> turned) {
|
||||
this.packFolder = packFolder;
|
||||
private TurnModule(List<GeneratedObject> turned) {
|
||||
this.turned = turned;
|
||||
}
|
||||
|
||||
@@ -527,7 +523,7 @@ public class IrisObjectPlacementRegressionTest {
|
||||
@Override
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.stages().define(TURN).requires(IrisStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
|
||||
context.world().resources().require(PackResourceFixture.oakKey(packFolder)),
|
||||
PackResourceFixture.oak(context.world().resources()),
|
||||
new ObjectTransform(90, 0, 0, 1, 1, 1, false, false, false))));
|
||||
}
|
||||
}
|
||||
@@ -535,7 +531,7 @@ public class IrisObjectPlacementRegressionTest {
|
||||
@Test
|
||||
public void aPlacementStageTurnsAnObjectThroughTheObjectTransformer() throws IOException {
|
||||
List<GeneratedObject> turned = new ArrayList<>();
|
||||
usePack(List.of(new TurnModule(folder.getRoot(), turned)));
|
||||
usePack(List.of(new TurnModule(turned)));
|
||||
PackResourceFixture.serve(data);
|
||||
|
||||
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.engine.object.terrain.carving;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
@@ -259,7 +261,7 @@ public class CarvingResolverParityTest {
|
||||
return parent;
|
||||
}
|
||||
|
||||
long seed = world.seed(art.arcane.iris.builtin.IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
||||
long seed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
||||
LegacyCarvingChoice selected = legacyChildrenGenerator(parent, seed).fitRarity(options, worldX, worldZ);
|
||||
if (selected == null || selected.entry == null) {
|
||||
return parent;
|
||||
|
||||
+7
@@ -9,6 +9,8 @@ import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.PackResourceFixture;
|
||||
import com.google.gson.Gson;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
@@ -17,6 +19,7 @@ import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.IrisFeature;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,11 +62,13 @@ public class IrisDimensionReachableBiomesTest {
|
||||
IrisBiome disabledDeep = biome("disabled-deep");
|
||||
IrisBiome unused = biome("unused");
|
||||
|
||||
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(regionLoader.load("reachable")).thenReturn(reachable);
|
||||
when(biomeLoader.load("parent")).thenReturn(parent);
|
||||
when(biomeLoader.load("child")).thenReturn(child);
|
||||
@@ -106,11 +111,13 @@ public class IrisDimensionReachableBiomesTest {
|
||||
IrisBiome d = biome("d", floatingChildren(floating("b")))
|
||||
.setChildren(new KList<>("a"));
|
||||
|
||||
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(regionLoader.load("reachable")).thenReturn(reachable);
|
||||
when(biomeLoader.load("a")).thenReturn(a);
|
||||
when(biomeLoader.load("b")).thenReturn(b);
|
||||
|
||||
+5
@@ -24,12 +24,15 @@ import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.PackResourceFixture;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.IrisFeature;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -51,9 +54,11 @@ public class IrisRegionBiomeTreeTest {
|
||||
IrisBiome mushroom = biome("carving/mushroom", new CarvingBiomeSettings("carving/nested"));
|
||||
IrisBiome nested = biome("carving/nested");
|
||||
|
||||
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(biomes.load("plains")).thenReturn(plains);
|
||||
when(biomes.load("meadow")).thenReturn(meadow);
|
||||
when(biomes.load("carving/mushroom")).thenReturn(mushroom);
|
||||
|
||||
@@ -35,9 +35,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -92,13 +92,13 @@ public class AmbientEffectingTest {
|
||||
List<AmbientEffects.Effect> due = new AmbientEffecting().due(world, AT);
|
||||
|
||||
assertEquals(1, due.size());
|
||||
AmbientEffects.Sound sound = due.getFirst().sound();
|
||||
AmbientEffects.Sound sound = due.getFirst().sound().orElseThrow();
|
||||
assertEquals("ambient.cave", sound.key());
|
||||
assertTrue(Math.abs(sound.offsetX()) <= 4 && Math.abs(sound.offsetY()) <= 4 && Math.abs(sound.offsetZ()) <= 4);
|
||||
assertEquals(2F, sound.volume(), 0);
|
||||
assertEquals(0.5F, sound.pitch(), 0);
|
||||
assertEquals(new AmbientEffects.Potion("luck", 1, 100), due.getFirst().potion());
|
||||
assertNull(due.getFirst().particles());
|
||||
assertEquals(Optional.of(new AmbientEffects.Potion("luck", 1, 100)), due.getFirst().potion());
|
||||
assertTrue(due.getFirst().particles().isEmpty());
|
||||
assertTrue(due.getFirst().commands().isEmpty());
|
||||
}
|
||||
|
||||
@@ -109,18 +109,19 @@ public class AmbientEffectingTest {
|
||||
|
||||
AmbientEffects.Effect effect = new AmbientEffecting().due(world, AT).getFirst();
|
||||
|
||||
assertEquals("flame", effect.particles().key());
|
||||
assertEquals(5, effect.particles().forward(), 0);
|
||||
assertEquals(0, effect.particles().sideways(), 0);
|
||||
assertEquals(0.5, effect.particles().altX(), 0);
|
||||
assertEquals(0.25, effect.particles().extra(), 0);
|
||||
assertEquals(2, effect.particles().count());
|
||||
AmbientEffects.Particles particles = effect.particles().orElseThrow();
|
||||
assertEquals("flame", particles.key());
|
||||
assertEquals(5, particles.forward(), 0);
|
||||
assertEquals(0, particles.sideways(), 0);
|
||||
assertEquals(0.5, particles.altX(), 0);
|
||||
assertEquals(0.25, particles.extra(), 0);
|
||||
assertEquals(2, particles.count());
|
||||
assertEquals(1, effect.commands().size());
|
||||
assertEquals(List.of("say hi {x}"), effect.commands().getFirst().command().commands());
|
||||
assertEquals(3, effect.commands().getFirst().command().delay());
|
||||
assertEquals(2, effect.commands().getFirst().offsetX(), 0);
|
||||
assertNull(effect.sound());
|
||||
assertNull(effect.potion());
|
||||
assertTrue(effect.sound().isEmpty());
|
||||
assertTrue(effect.potion().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,6 +25,8 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -38,6 +40,8 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* What an entity of the pack becomes when it is made from a fixed stream, hashed. The number was taken before the entity
|
||||
* classes became settings of the spawn module; a change in it changes the equipment, attributes and passengers worlds spawn.
|
||||
* It was retaken once when absent values became {@code Optional}s and loot tables ids: the spec printed the old way (empty
|
||||
* texts as {@code ""}, other absent values as {@code null}, tables by key) still hashed to the old number, -819231818.
|
||||
*/
|
||||
public class EntityResolutionPinTest {
|
||||
private static final long STREAM_SEED = 4321L;
|
||||
@@ -67,8 +71,11 @@ public class EntityResolutionPinTest {
|
||||
Optional<Sky> sky = Optional.of(new Sky(0L, false, false));
|
||||
EntityDefinition entity = new Gson().fromJson(ENTITY, EntityDefinition.class);
|
||||
|
||||
EntitySpec spec = new EntityResolution(new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
||||
PackResources resources = mock(PackResources.class);
|
||||
when(resources.idOf(anyString())).thenAnswer(invocation -> new ResourceId("test", invocation.getArgument(0)));
|
||||
|
||||
assertEquals(-819231818, spec.toString().hashCode());
|
||||
EntitySpec spec = new EntityResolution(resources, new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
||||
|
||||
assertEquals(1441930785, spec.toString().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class EntitySpawningTest {
|
||||
|
||||
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow();
|
||||
|
||||
assertEquals(List.of("zombies"), rule.spawners());
|
||||
assertEquals("a spawner the pack lacks is left out", List.of(world.resources().idOf("zombies")), rule.spawners());
|
||||
assertTrue(rule.emptyAbove());
|
||||
assertFalse(rule.removeOnChange());
|
||||
}
|
||||
@@ -123,16 +123,16 @@ public class EntitySpawningTest {
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
|
||||
EntitySpawns.Plan plan = new EntitySpawning()
|
||||
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "camp/zombies", false))
|
||||
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("camp/zombies"), false))
|
||||
.orElseThrow();
|
||||
|
||||
assertEquals("camp/zombies", plan.spawner());
|
||||
assertEquals(world.resources().idOf("camp/zombies"), plan.spawner());
|
||||
assertTrue("an exhaustion chance above 1 always uses the marker up", plan.exhaustsMarker());
|
||||
assertEquals(2, plan.attempts().size());
|
||||
for (EntitySpawns.Attempt attempt : plan.attempts()) {
|
||||
assertEquals(new BlockPosition(40, 71, -12), attempt.at());
|
||||
assertFalse(attempt.checkSurface());
|
||||
assertEquals("minecraft:zombie", attempt.entity().type());
|
||||
assertEquals(Optional.of("minecraft:zombie"), attempt.entity().type());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class EntitySpawningTest {
|
||||
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
|
||||
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
|
||||
|
||||
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "empty", false));
|
||||
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("empty"), false));
|
||||
|
||||
assertTrue(plan.isEmpty());
|
||||
}
|
||||
@@ -150,11 +150,11 @@ public class EntitySpawningTest {
|
||||
fixture.resource(SpawnResources.ENTITIES, "cow", TestSettings.of(EntityDefinition.class,
|
||||
"{\"type\": \"minecraft:cow\", \"customName\": \"&6Bessie\", \"baby\": true}"));
|
||||
|
||||
EntitySpec spec = new EntitySpawning().entity(world, "cow").orElseThrow();
|
||||
EntitySpec spec = new EntitySpawning().entity(world, world.resources().idOf("cow")).orElseThrow();
|
||||
|
||||
assertEquals("minecraft:cow", spec.type());
|
||||
assertEquals("&6Bessie", spec.customName());
|
||||
assertEquals(Optional.of("minecraft:cow"), spec.type());
|
||||
assertEquals(Optional.of("&6Bessie"), spec.customName());
|
||||
assertTrue(spec.flags().baby());
|
||||
assertTrue(new EntitySpawning().entity(world, "nothing").isEmpty());
|
||||
assertTrue(new EntitySpawning().entity(world, world.resources().idOf("nothing")).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class SpawnerGateTest {
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
||||
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +105,7 @@ public class SpawnerGateTest {
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
|
||||
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), LiveWorld.of(new EngineGeneration(engine).world()), 0, 0));
|
||||
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow(), 0, 0));
|
||||
}
|
||||
|
||||
private static Spawner spawner(String json) {
|
||||
|
||||
@@ -65,10 +65,5 @@ public final class TestLayerBlocks {
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
@@ -39,7 +39,7 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** A world of a pack's resources whose dimension declares the given settings and whose complex and terrain seeds are given, for tests of the terrain's support classes. */
|
||||
public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
||||
public final class TestPackWorld implements PackWorld {
|
||||
private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld");
|
||||
|
||||
private final PackResources resources;
|
||||
@@ -83,11 +83,6 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed which) {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
@@ -109,7 +104,8 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return this;
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
IrisSeeds everySeedIsTheWorlds = which -> seed;
|
||||
return type == IrisSeeds.class ? Optional.of(type.cast(everySeedIsTheWorlds)) : Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user