mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +00:00
Merge feat/structure-jigsaw-modules into port/v3-features
Structure placement and jigsaw now live in the built-in modules jar, on top of the port's weighted picking, studio tooling
and procedural object work.
api/CONTRACTS.md keeps both sides' rows: the weighted entries and the studio bake and scene creation types from the port,
and VanillaStructureContext.world, Argument.reading, PlatformStructures, tool worlds and the services lookup from the
structure move.
PackModuleResourceKindTest installs the built-in modules jar into its castle pack, as the structure move requires, and
writes the dimension and region lists as weighted entries, as the port requires.
StructurePlacing takes the structure move's version. Its int sentinel for a sampled height is replaced by an explicit
sampledHeight flag that calls ObjectRun.automatic, and explicit pieces pass their world Y minus the world's minimum, so an
explicit world Y below zero stays a height (e3dd61c17).
StructureOutputPinTest.everyScenarioPlacesThePinnedStructures is re-baselined for the underground scenario's writes hash
only (9176f55f60410c117cdd9d5e to 1025f82c04539d4881a0e92b): pieces at world Y -1 are now placed there instead of on the
surface. The start count, the piece hash and every other scenario are unchanged.
This commit is contained in:
commit
2889274291
514 files changed
+29979
-15110
No files matched your search
@@ -13,7 +13,8 @@ import java.util.TreeSet;
|
||||
* {@code com.volmitx}. The host side of IrisApi, {@code com.volmit.host}, lies inside the API's
|
||||
* root package but is never exposed: it loads and runs modules, and no module may reach it. The
|
||||
* platform packages of the tooling api, {@code com.volmit.tooling.<platform>}, are never exposed either:
|
||||
* only a tooling part may use them. The neutral {@code com.volmit.tooling} stays exposed.
|
||||
* only a tooling part may use them. The neutral {@code com.volmit.tooling} stays exposed, and so does the world api for
|
||||
* tools, {@code com.volmit.tooling.world}, which every platform implements.
|
||||
*/
|
||||
final class ExposedPackages {
|
||||
/** The root package of the Iris API. Module classes must not use it. */
|
||||
@@ -22,6 +23,9 @@ final class ExposedPackages {
|
||||
static final String HOST_PACKAGE = ExposedPackages.class.getPackageName();
|
||||
/** The neutral tooling api. Each platform's own api is a subpackage of it, such as {@code com.volmit.tooling.bukkit}. */
|
||||
static final String TOOLING_PACKAGE = API_PACKAGE + ".tooling";
|
||||
/** The world api for tools, which every platform implements; it is neutral, so modules see it. */
|
||||
static final String TOOL_WORLD_PACKAGE = TOOLING_PACKAGE + ".world";
|
||||
private static final PackageName TOOL_WORLD = new PackageName(TOOL_WORLD_PACKAGE);
|
||||
private static final PackageName API = new PackageName(API_PACKAGE);
|
||||
private static final PackageName HOST = new PackageName(HOST_PACKAGE);
|
||||
private static final PackageName TOOLING = new PackageName(TOOLING_PACKAGE);
|
||||
@@ -77,9 +81,12 @@ final class ExposedPackages {
|
||||
return !HOST.contains(dottedName) && packages.stream().anyMatch(name -> name.contains(dottedName));
|
||||
}
|
||||
|
||||
/** Whether the package lies below {@code com.volmit.tooling}, where each platform's api has its package. */
|
||||
/** Whether the package lies below {@code com.volmit.tooling}, where each platform's api has its package. The
|
||||
* platform-neutral world api for tools, {@code com.volmit.tooling.world}, lies there too but is not a platform's.
|
||||
*/
|
||||
private static boolean isToolingPlatformPackage(String packageName) {
|
||||
return TOOLING.contains(packageName);
|
||||
boolean isToolWorldApi = packageName.equals(TOOL_WORLD_PACKAGE) || TOOL_WORLD.contains(packageName);
|
||||
return TOOLING.contains(packageName) && !isToolWorldApi;
|
||||
}
|
||||
|
||||
/** What precedes the last separator: the package of a class name, or the directory of a resource path. */
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
@@ -36,6 +38,11 @@ final class ModuleWorld implements PackWorld {
|
||||
return world.seed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
return world.seed(purpose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return world.resources();
|
||||
@@ -72,6 +79,11 @@ final class ModuleWorld implements PackWorld {
|
||||
return world.extension(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return world.services(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return log;
|
||||
|
||||
@@ -42,6 +42,8 @@ class ExposedPackagesTest {
|
||||
assertTrue(exposed.exposes("com.volmit.tooling.Command$Builder"));
|
||||
assertFalse(exposed.exposes("com.volmit.tooling.bukkit.BukkitToolPart"));
|
||||
assertFalse(exposed.exposes("com.volmit.tooling.modded.deep.ModdedToolPart"));
|
||||
assertTrue(exposed.exposes("com.volmit.tooling.world.ToolWorld"), "the world api for tools is neutral");
|
||||
assertFalse(exposed.exposes("com.volmit.tooling.worldly.BukkitToolPart"));
|
||||
assertTrue(exposed.exposes("com.volmit.toolingx.Other"));
|
||||
assertTrue(exposed.exposes("com.volmit.tool.bukkit.Other"));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.Pipeline;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.support.TestContexts;
|
||||
@@ -73,6 +74,18 @@ class ExtensionsTest {
|
||||
assertEquals(Optional.of(new WorldOffer("iris")), view.extension(WorldOffer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aModulesViewOfAWorldAnswersTheSeedPurposesTheHostAnswers() {
|
||||
var world = new OfferingWorld(new WorldOffer("iris"));
|
||||
PackWorld view = ModuleWorld.of(world, ModuleLogs.discarding());
|
||||
|
||||
assertEquals(HOST_SEED, view.seed(HOST_SEED_PURPOSE), "the host decides the seed of a purpose it knows");
|
||||
assertEquals(world.seed(ResourceId.parse("test:other")), view.seed(ResourceId.parse("test:other")));
|
||||
}
|
||||
|
||||
private static final ResourceId HOST_SEED_PURPOSE = ResourceId.parse("test:host-seed");
|
||||
private static final long HOST_SEED = 31337L;
|
||||
|
||||
private static final class OfferingWorld implements PackWorld {
|
||||
private final WorldStates states = new WorldStates();
|
||||
private final WorldOffer offer;
|
||||
@@ -82,12 +95,14 @@ class ExtensionsTest {
|
||||
}
|
||||
|
||||
public long seed() { return TestContexts.SEED; }
|
||||
@Override public long seed(ResourceId purpose) { return purpose.equals(HOST_SEED_PURPOSE) ? HOST_SEED : PackWorld.super.seed(purpose); }
|
||||
public PackResources resources() { throw new AssertionError("Unused resources"); }
|
||||
public PackSettings settings() { throw new AssertionError("Unused settings"); }
|
||||
public int minWorldY() { return 0; }
|
||||
public Optional<RunningWorld> running() { return Optional.empty(); }
|
||||
public Placements placements() { throw new AssertionError("Unused placements"); }
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) { return states.state(type, () -> create.apply(this)); }
|
||||
public <S> List<S> services(Class<S> service) { return List.of(); }
|
||||
public ModuleLog log() { return ModuleLogs.discarding(); }
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleSetup;
|
||||
import com.volmit.service.Providers;
|
||||
import com.volmit.service.Service;
|
||||
import com.volmit.support.TestWorld;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** A module asks another module's service through the world: {@code PackWorld.services}, which the validation context and
|
||||
* the tool pack answer the same way.
|
||||
*/
|
||||
class PackWorldServicesTest {
|
||||
@Service(Providers.ALL)
|
||||
interface Greeting { String greet(); }
|
||||
@Service(Providers.ONE)
|
||||
interface Clock { long now(); }
|
||||
interface NotAService { void run(); }
|
||||
|
||||
private static void registerAs(ModuleRegistry registry, String moduleId, Consumer<FeatureRegistry> registrations) {
|
||||
ModuleSetups.run(DiscoveredModule.builtIn(new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of(moduleId, "Test module " + moduleId, "1"); }
|
||||
public void setup(ModuleSetup setup) { registrations.accept(setup.registry()); }
|
||||
}), new StageGraphBuilder(), registry);
|
||||
}
|
||||
|
||||
private static FeatureCatalog catalogOf(Greeting zeta, Greeting alphaFirst, Greeting alphaSecond) {
|
||||
var registry = new ModuleRegistry();
|
||||
registerAs(registry, "test:zeta", services -> services.registerService(Greeting.class, zeta));
|
||||
registerAs(registry, "test:alpha", services -> {
|
||||
services.registerService(Greeting.class, alphaFirst);
|
||||
services.registerService(Greeting.class, alphaSecond);
|
||||
});
|
||||
return registry.freeze();
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorldAnswersWithTheProvidersOfItsPacksModulesInModuleIdOrder() {
|
||||
Greeting zeta = () -> "zeta";
|
||||
Greeting alphaFirst = () -> "alpha 1";
|
||||
Greeting alphaSecond = () -> "alpha 2";
|
||||
try (var world = new TestWorld(catalogOf(zeta, alphaFirst, alphaSecond))) {
|
||||
assertEquals(List.of(alphaFirst, alphaSecond, zeta), world.services(Greeting.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aServiceNobodyProvidesHasNoProviders() {
|
||||
try (var world = new TestWorld(catalogOf(() -> "zeta", () -> "alpha 1", () -> "alpha 2"))) {
|
||||
assertEquals(List.of(), world.services(Clock.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInterfaceThatIsNotAServiceIsRefused() {
|
||||
try (var world = new TestWorld(catalogOf(() -> "zeta", () -> "alpha 1", () -> "alpha 2"))) {
|
||||
assertThrows(IllegalArgumentException.class, () -> world.services(NotAService.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void theViewAModuleGetsOfAWorldAnswersLikeTheWorld() {
|
||||
Greeting zeta = () -> "zeta";
|
||||
Greeting alphaFirst = () -> "alpha 1";
|
||||
Greeting alphaSecond = () -> "alpha 2";
|
||||
var catalog = catalogOf(zeta, alphaFirst, alphaSecond);
|
||||
try (var world = new TestWorld(catalog)) {
|
||||
PackWorld view = catalog.registrations(Greeting.class).getFirst().scope(world);
|
||||
|
||||
assertNotSame(world, view);
|
||||
assertEquals(world.services(Greeting.class), view.services(Greeting.class));
|
||||
assertEquals(List.of(alphaFirst, alphaSecond, zeta), view.services(Greeting.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,38 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** A world for tests: the test seed, no resources, no declared settings, and a real state store. */
|
||||
/** A world for tests: the test seed, no resources, no declared settings, a real state store, and the service providers of
|
||||
* a catalog when it is given one.
|
||||
*/
|
||||
public final class TestWorld implements PackWorld, AutoCloseable {
|
||||
private final WorldStates states;
|
||||
private final ModuleLog log;
|
||||
private final FeatureCatalog catalog;
|
||||
|
||||
public TestWorld() {
|
||||
this(new WorldStates(), ModuleLogs.discarding());
|
||||
this(null);
|
||||
}
|
||||
|
||||
private TestWorld(WorldStates states, ModuleLog log) {
|
||||
/** A world whose services are those {@code catalog} holds. */
|
||||
public TestWorld(FeatureCatalog catalog) {
|
||||
this(new WorldStates(), ModuleLogs.discarding(), catalog);
|
||||
}
|
||||
|
||||
private TestWorld(WorldStates states, ModuleLog log, FeatureCatalog catalog) {
|
||||
this.states = states;
|
||||
this.log = log;
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,6 +81,11 @@ public final class TestWorld implements PackWorld, AutoCloseable {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return catalog == null ? List.of() : catalog.services(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return log;
|
||||
|
||||
Reference in new issue
Block a user