mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Give modules a world per engine runtime and pack snapshot with lifecycle hooks, and ask them through services: IrisPackWorld and ModuleWorlds (start on publish, restart when the pack's resources reload, stop on retire), contexts' world(), ModuleServices, Engine.getObjectsAt through ObjectsAt and the Iris structure find path and structure index through StructureLocator
This commit is contained in:
1 parent
2f3ba3cebe
commit
f501e3baf7
33 files changed
+1101
-80
No files matched your search
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureLocating;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.LifecycleRegistration;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** The services and hooks Iris's built-in modules provide, which Iris core asks instead of their features. */
|
||||
public class BuiltInServicesTest {
|
||||
private static final FeatureCatalog BUILT_INS = ModuleResourceFixture.catalogOf(IrisModuleHost.builtInModules().toArray(IrisModule[]::new));
|
||||
|
||||
@Test
|
||||
public void objectsTellWhichObjectsAChunkGets() {
|
||||
assertEquals(1, BUILT_INS.services(ObjectsAt.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresAreFoundThroughTheStructureModule() {
|
||||
List<StructureLocator> locators = BUILT_INS.services(StructureLocator.class);
|
||||
assertEquals(1, locators.size());
|
||||
assertTrue(locators.getFirst() instanceof StructureLocating);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theStructureModuleHearsWhenWorldsStop() {
|
||||
assertEquals(List.of("iris:structure"), BUILT_INS.lifecycles().stream()
|
||||
.map(LifecycleRegistration::module).map(module -> module.info().id().toString()).toList());
|
||||
assertTrue(BUILT_INS.lifecycles().getFirst().lifecycle() instanceof StructureModule);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.stage.MantleStage;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -134,6 +135,7 @@ public class ChunkSettingsScanTimingTest {
|
||||
public FeatureSettings settings() { return settings; }
|
||||
public Mantle mantle() { throw new UnsupportedOperationException(); }
|
||||
public PackResources resources() { throw new UnsupportedOperationException(); }
|
||||
public PackWorld world() { throw new UnsupportedOperationException(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleRegistry;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
@@ -61,6 +62,15 @@ public final class ModuleResourceFixture {
|
||||
return registry.freeze();
|
||||
}
|
||||
|
||||
/** Makes {@code data} (a mock) load {@code modules} as its pack's modules, so services and hooks of theirs answer. */
|
||||
public static void serveModules(IrisData data, IrisModule... modules) {
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
when(pack.catalog()).thenReturn(catalogOf(modules));
|
||||
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||
when(moduleSet.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(moduleSet);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* What Iris core asks modules through services: every module's objects, and structures through the module that knows
|
||||
* them, whose heights above the dimension's bottom come back as the world's Y.
|
||||
*/
|
||||
public class ModuleServicesTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<String> searches = new ArrayList<>();
|
||||
private LoadedPack pack;
|
||||
private IrisData data;
|
||||
private Engine engine;
|
||||
|
||||
/** Places {@code object} in every chunk and finds structure {@code structure} at a fixed spot. */
|
||||
public final class ServingModule implements IrisModule {
|
||||
private final String id;
|
||||
private final String object;
|
||||
private final String structure;
|
||||
|
||||
ServingModule(String id, String object, String structure) {
|
||||
this.id = id;
|
||||
this.object = object;
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of(id, "Serving " + id, "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerService(ObjectsAt.class, (world, chunkX, chunkZ) -> Set.of(object + "@" + chunkX + "," + chunkZ));
|
||||
registry.registerService(StructureLocator.class, new StructureLocator() {
|
||||
@Override
|
||||
public Set<String> structures(PackResources resources) {
|
||||
return Set.of(structure, structure + "/unplaced");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> locatable(PackWorld world) {
|
||||
return Set.of(structure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
searches.add(id + " " + key + " " + fromX + " " + fromZ + " " + maxRadiusChunks);
|
||||
return LocateResult.found(new BlockPosition(fromX + 16, 70, fromZ));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void servePack() throws IOException {
|
||||
pack = LoadedPack.load(folder.newFolder("pack").toPath(), ModuleHost.of(List.of(
|
||||
new ServingModule("test:zeta", "rock", "castle"),
|
||||
new ServingModule("test:alpha", "tree", "tower"),
|
||||
new ServingModule("test:beta", "bush", "castle")))
|
||||
.copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
data = mock(IrisData.class);
|
||||
PackModuleSet modules = mock(PackModuleSet.class);
|
||||
when(modules.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(modules);
|
||||
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
||||
IrisPackResources resources = new IrisPackResources(data, List::of);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
engine = mock(Engine.class);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
EngineGeneration generation = new EngineGeneration(engine);
|
||||
when(engine.getGeneration()).thenReturn(generation);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectsAtCombinesEveryModulesObjectsInModuleOrder() {
|
||||
assertEquals(List.of("tree@3,-4", "bush@3,-4", "rock@3,-4"), List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureListsCombineEveryModule() {
|
||||
assertEquals(Set.of("tower", "castle"), ModuleServices.locatableStructures(engine));
|
||||
assertEquals(Set.of("tower", "tower/unplaced", "castle", "castle/unplaced"), ModuleServices.structureKeys(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStructureIsLocatedByTheFirstModuleThatCanLocateItIgnoringCase() {
|
||||
assertTrue(ModuleServices.canLocateStructure(engine, "CASTLE"));
|
||||
assertFalse(ModuleServices.canLocateStructure(engine, "castle/unplaced"));
|
||||
assertFalse(ModuleServices.canLocateStructure(engine, " "));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStructureNoModuleCanLocateIsNotFoundWithoutSearching() {
|
||||
assertEquals(ModuleServices.StructureSearch.Outcome.NOT_FOUND,
|
||||
ModuleServices.locateStructure(engine, "castle/unplaced", 0, 0, 64).outcome());
|
||||
assertEquals(List.of(), searches);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleLifecycle;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The world modules see for an engine runtime: it starts once the runtime is published, its state is the store built-in
|
||||
* stages share, it restarts with a fresh store when the pack's resources reload, and it stops with the runtime.
|
||||
*/
|
||||
public class ModuleWorldsTest {
|
||||
private static final long SEED = 1337L;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<String> calls = new ArrayList<>();
|
||||
private LoadedPack pack;
|
||||
private IrisData data;
|
||||
private Engine engine;
|
||||
private String failingHook;
|
||||
|
||||
/** What a world keeps for the recording module; closing it is recorded too. */
|
||||
public static final class Remembered implements AutoCloseable {
|
||||
private final List<String> calls;
|
||||
|
||||
Remembered(List<String> calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
calls.add("closed state");
|
||||
}
|
||||
}
|
||||
|
||||
/** Records its hooks and builds its state when a world starts. */
|
||||
public final class RecordingModule implements IrisModule, ModuleLifecycle {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("test:recording", "Recording", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerLifecycle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packLoaded(PackResources resources, PackSettings settings) {
|
||||
record("loaded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void worldStarted(PackWorld world) {
|
||||
record("started");
|
||||
world.state(Remembered.class, ignored -> new Remembered(calls));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void worldStopped(PackWorld world) {
|
||||
record("stopped");
|
||||
}
|
||||
|
||||
private void record(String hook) {
|
||||
calls.add(hook);
|
||||
if (hook.equals(failingHook)) {
|
||||
throw new IllegalStateException("cannot be " + hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void servePack() throws IOException {
|
||||
pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||
ModuleHost.of(List.of(new RecordingModule())).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
data = mock(IrisData.class);
|
||||
PackModuleSet modules = mock(PackModuleSet.class);
|
||||
when(modules.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(modules);
|
||||
File root = folder.getRoot();
|
||||
when(data.getDataFolder()).thenReturn(root);
|
||||
reloadResources();
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getSeed()).thenReturn(SEED);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theWorldStartsWithThePackSnapshotAndTheEngineSeedAndSharesItsStoreWithBuiltInStages() {
|
||||
EngineGeneration generation = generation();
|
||||
|
||||
generation.startModules();
|
||||
|
||||
IrisPackWorld world = generation.world();
|
||||
assertEquals(List.of("loaded", "started"), calls);
|
||||
assertEquals(SEED, world.seed());
|
||||
assertSame(data.getPackResources(), world.resources());
|
||||
assertSame(engine, IrisPackWorld.of(world).engine());
|
||||
Remembered built = world.state(Remembered.class, ignored -> new Remembered(calls));
|
||||
assertSame(built, generation.state(Remembered.class, ignored -> new Remembered(calls)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reloadedResourcesRestartTheWorldWithAnEmptyStoreAndCloseTheOldStateLater() {
|
||||
EngineGeneration generation = generation();
|
||||
generation.startModules();
|
||||
IrisPackWorld first = generation.world();
|
||||
Remembered firstState = first.state(Remembered.class, ignored -> new Remembered(calls));
|
||||
calls.clear();
|
||||
|
||||
reloadResources();
|
||||
generation.restartModules();
|
||||
|
||||
IrisPackWorld second = generation.world();
|
||||
assertNotSame(first, second);
|
||||
assertSame(data.getPackResources(), second.resources());
|
||||
assertEquals(List.of("stopped", "loaded", "started"), calls);
|
||||
assertNotSame(firstState, second.state(Remembered.class, ignored -> new Remembered(calls)));
|
||||
assertSame("a running invocation may still use the old world", firstState, first.state(Remembered.class, ignored -> null));
|
||||
|
||||
calls.clear();
|
||||
reloadResources();
|
||||
generation.restartModules();
|
||||
assertEquals(List.of("stopped", "closed state", "loaded", "started"), calls);
|
||||
assertThrows(IllegalStateException.class, () -> first.state(Remembered.class, ignored -> null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closingTheRuntimeStopsTheWorldAndClosesItsState() {
|
||||
EngineGeneration generation = generation();
|
||||
generation.startModules();
|
||||
IrisPackWorld world = generation.world();
|
||||
calls.clear();
|
||||
|
||||
generation.close();
|
||||
generation.close();
|
||||
|
||||
assertEquals(List.of("stopped", "closed state"), calls);
|
||||
assertThrows(IllegalStateException.class, () -> world.state(Remembered.class, ignored -> null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyWorldOfOneSnapshotStartsButThePackLoadsOnce() {
|
||||
EngineGeneration first = generation();
|
||||
EngineGeneration second = generation();
|
||||
|
||||
first.startModules();
|
||||
second.startModules();
|
||||
|
||||
assertEquals(List.of("loaded", "started", "started"), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuntimeThatStartsAfterAReloadStartsWithTheNewSnapshot() {
|
||||
EngineGeneration generation = generation();
|
||||
IrisPackWorld madeEarly = generation.world();
|
||||
|
||||
reloadResources();
|
||||
generation.startModules();
|
||||
|
||||
assertNotSame(madeEarly, generation.world());
|
||||
assertSame(data.getPackResources(), generation.world().resources());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aModuleThatFailsToStartStopsTheRuntimeFromStartingAndIsNotStoppedLater() {
|
||||
failingHook = "started";
|
||||
EngineGeneration generation = generation();
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, generation::startModules);
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("test:recording"));
|
||||
|
||||
calls.clear();
|
||||
generation.close();
|
||||
assertEquals(List.of(), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWhoseModulesFailToLoadRunsItsWorldWithoutHooks() {
|
||||
PackModuleSet broken = mock(PackModuleSet.class);
|
||||
when(broken.pack()).thenThrow(new PackModulesException(folder.getRoot(), new IllegalArgumentException("broken jar")));
|
||||
when(data.getModules()).thenReturn(broken);
|
||||
EngineGeneration generation = generation();
|
||||
|
||||
generation.startModules();
|
||||
generation.world().state(Remembered.class, ignored -> new Remembered(calls));
|
||||
generation.close();
|
||||
|
||||
assertEquals(List.of("closed state"), calls);
|
||||
}
|
||||
|
||||
private EngineGeneration generation() {
|
||||
return new EngineGeneration(engine);
|
||||
}
|
||||
|
||||
/** A new snapshot of the pack's resources, as {@link IrisData#reloadModuleResources()} makes. */
|
||||
private void reloadResources() {
|
||||
IrisPackResources resources = new IrisPackResources(data, List::of);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.core.structure;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
@@ -105,6 +106,7 @@ public class StructureIndexServiceTest {
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
PlatformStructureHooks structureHooks = mock(PlatformStructureHooks.class);
|
||||
when(data.getDataFolder()).thenReturn(pack);
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
ModuleResourceFixture.serve(data)
|
||||
.resource(StructureResources.STRUCTURES, "castle", new IrisStructure())
|
||||
.resource(StructureResources.STRUCTURES, "structure-index", new IrisStructure());
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
@@ -10,8 +12,12 @@ import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -19,8 +25,26 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Decorating reads nothing of the chunk when the dimension does not decorate, and skips biomes without decorators. */
|
||||
/**
|
||||
* Decorating reads nothing of the chunk when the dimension does not decorate, skips biomes without decorators, and is
|
||||
* kept per world in the world's state store.
|
||||
*/
|
||||
public class DecorantModuleTest {
|
||||
@Test
|
||||
public void eachWorldKeepsOneDecoratingInItsStateStore() {
|
||||
Engine engine = engine(true);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
EngineGeneration generation = new EngineGeneration(engine);
|
||||
PackWorld world = generation.world();
|
||||
|
||||
DecorantModule.Decorating decorating = DecorantModule.decorating(world);
|
||||
|
||||
assertSame(decorating, DecorantModule.decorating(world));
|
||||
assertSame("built-in stages share the store", decorating,
|
||||
generation.state(DecorantModule.Decorating.class, DecorantModule.Decorating::new));
|
||||
assertNotSame(decorating, DecorantModule.decorating(new EngineGeneration(engine).world()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDimensionThatDoesNotDecorateIsLeftAlone() {
|
||||
DecorantModule.Decorating decorating = new DecorantModule.Decorating(engine(false));
|
||||
|
||||
+13
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.IrisModuleHost;
|
||||
import art.arcane.iris.core.project.ModuleResourceSchemas;
|
||||
import art.arcane.iris.core.project.SchemaTestPlatform;
|
||||
@@ -20,6 +21,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -55,6 +57,17 @@ public class StructureResourcesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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("castle"), ModuleServices.structureKeys(data));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresPoolsAndPiecesAreReadThroughPackResources() throws Exception {
|
||||
Path pack = castlePack("castles");
|
||||
|
||||
+7
-1
@@ -4,7 +4,9 @@ import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.framework.StructureReachability;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
@@ -107,6 +109,8 @@ public class StructureHandlerTest {
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:custom_definition", custom);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:collision_definition", collision);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
@@ -178,6 +182,8 @@ public class StructureHandlerTest {
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:editable_definition", editable);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:replacement_definition", replacement);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
@@ -244,7 +250,7 @@ public class StructureHandlerTest {
|
||||
|
||||
assertEquals(1, occurrences(method, "StructureReachability.reachableKeys(activeEngine)"));
|
||||
assertEquals(0, occurrences(method, "IrisStructureLocator.locatableKeys(activeEngine)"));
|
||||
assertEquals(1, occurrences(method, "IrisStructureLocator.locatableEditableKeys(activeEngine)"));
|
||||
assertEquals(1, occurrences(method, "ModuleServices.locatableStructures(activeEngine)"));
|
||||
assertTrue(method.indexOf("if (activeEngine == null)")
|
||||
< method.indexOf("IrisPlatforms.get().structureHooks()"));
|
||||
assertFalse(method.contains("INMS"));
|
||||
|
||||
Reference in new issue
Block a user