Batch 6 part 4a: purpose seeds and the running world for the built-ins

Finding 40, first step. IrisPackWorld answers seed(purpose) through
IrisWorldSeeds (iris:seed/* map to SeedManager's legacy seeds, any other
id to WorldRandom.purposeSeed) and running() with IrisRunningWorld (the
engine's layout over the whole world, chunk-stage settings, highest
block, cave floors, sky, platform loot tables, studio as debug), built
on first use. IrisObjectHost loses the layout and settings lookups the
API now answers and gains placedLoot; spawner cooldowns are offered as
SpawnCooldowns. Tests follow; generation output is unchanged (goldens,
pins and probes pass as they were).
This commit is contained in:
piexel committed 2026-10-24 10:09:25 +02:00
1 parent 711fdd078a
commit df10a90117
34 files changed
+541 -484

No files matched your search

@@ -54,8 +54,8 @@ import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* Iris's answers to {@code iris:floating}: biomes by the engine's streams and loader, sky biomes into the engine's mantle,
* and floating objects placed by Iris's own object placement into the mantle chunk being generated.
* Iris's answers to {@code iris:floating}: a biome's terrain height by its generators, sky biomes into the engine's
* mantle, and floating objects placed by Iris's own object placement into the mantle chunk being generated.
*/
final class IrisFloatingHost implements FloatingHost {
private static final IrisObjectRotation NO_ROTATION = IrisObjectRotation.of(0, 0, 0);
@@ -63,25 +63,11 @@ final class IrisFloatingHost implements FloatingHost {
private final Engine engine;
private final ModuleLog log;
private final PackResourceIds ids;
private final Map<Double, IrisObjectScale> shrinkScales = new ConcurrentHashMap<>();
IrisFloatingHost(Engine engine, ModuleLog log) {
this.engine = engine;
this.log = log;
this.ids = new PackResourceIds(engine.getData().getDataFolder());
}
@Override
public ResourceId surfaceBiome(int worldX, int worldZ) {
IrisBiome biome = engine.getSurfaceBiome(worldX, worldZ);
return biome == null ? null : ids.of(biome.getLoadKey());
}
@Override
public Optional<ResourceId> biome(String key) {
IrisBiome biome = engine.getData().getBiomeLoader().load(key);
return biome == null ? Optional.empty() : Optional.of(ids.of(biome.getLoadKey()));
}
@Override
@@ -1,155 +0,0 @@
/*
* 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.builtin.LiveWorld;
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.framework.PlacedObject;
import art.arcane.iris.engine.object.world.biome.InferredType;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformWorld;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
import com.volmit.IrisFeature;
import com.volmit.resource.ResourceId;
import com.volmit.geometry.BlockPosition;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
* An engine as {@link LiveWorld} shows it to the built-in services: the engine's own answers for a block, turned into pack
* resource ids and values.
*/
final class IrisLiveWorld implements LiveWorld {
private final Engine engine;
private final IrisPackResources resources;
private final SpawnCooldowns cooldowns;
private volatile Set<String> platformLootTables;
IrisLiveWorld(Engine engine, IrisPackResources resources) {
this.engine = engine;
this.resources = resources;
this.cooldowns = new EngineSpawnCooldowns(engine);
}
@Override
public int bottomY() {
return engine.getMinHeight();
}
@Override
public ResourceId surfaceBiome(int x, int z) {
return idOf(engine.getSurfaceBiome(x, z));
}
@Override
public ResourceId caveBiome(int x, int y, int z) {
IrisBiome cave = engine.getCaveBiome(x, y, z);
return cave == null ? surfaceBiome(x, z) : idOf(cave);
}
@Override
public BiomeKind surfaceKind(int x, int z) {
InferredType type = engine.getSurfaceBiome(x, z).getInferredType();
return BiomeKind.valueOf(type.name());
}
@Override
public double terrainHeight(int x, int z) {
return engine.getComplex().getHeightStream().get(x, z);
}
@Override
public int highestBlock(int x, int z, boolean ignoreFluid) {
return engine.getHeight(x, z, ignoreFluid);
}
@Override
public <F extends IrisFeature> Optional<F> settings(Class<F> type, Level level, int x, int y, int z) {
IrisRegistrant owner = switch (level) {
case DIMENSION -> engine.getDimension();
case REGION -> engine.getRegion(x, z);
case SURFACE_BIOME -> engine.getSurfaceBiome(x, z);
case BIOME -> engine.getBiome(x, y, z);
case CAVE_BIOME -> engine.getCaveBiome(x, y, z);
};
return owner == null ? Optional.empty() : owner.getModuleSettings().find(type);
}
@Override
public Optional<Sky> sky() {
PlatformWorld world = engine.getWorld().platformWorld();
if (world == null) {
return Optional.empty();
}
return Optional.of(new Sky(world.getTime(), world.isStorming(), world.isThundering()));
}
@Override
public boolean studio() {
return engine.isStudio();
}
@Override
public Set<String> platformLootTables() {
Set<String> known = platformLootTables;
if (known == null) {
known = Set.copyOf(IrisPlatforms.get().registries().lootTableKeys());
platformLootTables = known;
}
return known;
}
@Override
public List<BlockPosition> caveFloors(int chunkX, int chunkZ) {
if (J.isFolia()) {
return List.of();
}
int bottom = engine.getMinHeight();
return engine.getMantle().findMarkers(chunkX, chunkZ, MarkerMatter.CAVE_FLOOR).stream()
.map(floor -> new BlockPosition(floor.getX(), floor.getY() - bottom, floor.getZ()))
.toList();
}
@Override
public Optional<ObjectLoots> objectLoots(int x, int y, int z) {
PlacedObject placed = engine.getObjectPlacement(x, y, z);
IrisObjectPlacement placement = placed == null ? null : placed.getPlacement();
if (placement == null) {
return Optional.empty();
}
return Optional.of(new ObjectLoots(placement.getLoot(), placement.getVanillaLoot(), placement.isOverrideGlobalLoot()));
}
@Override
public SpawnCooldowns spawnCooldowns() {
return cooldowns;
}
private ResourceId idOf(IrisBiome biome) {
return resources.idOf(biome.getLoadKey());
}
}
@@ -18,23 +18,19 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
import art.arcane.iris.builtin.objects.ObjectBuilder;
import art.arcane.iris.builtin.objects.ObjectChunk;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ObjectSink;
import art.arcane.iris.builtin.objects.ObjectSize;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralPlacement;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.engine.UpperDimensionContext;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.PlacedObject;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.placement.ObjectPlacements;
import art.arcane.iris.engine.object.prefab.IrisObject;
@@ -44,36 +40,29 @@ import art.arcane.iris.util.project.noise.CNG;
import art.arcane.iris.util.project.noise.NoiseType;
import art.arcane.volmlib.util.cache.CacheKey;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.config.Level;
import com.volmit.generation.InvocationContext;
import com.volmit.IrisFeature;
import com.volmit.ModuleLog;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.ResourceId;
import com.volmit.config.Level;
import com.volmit.generation.InvocationContext;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
/**
* What {@code iris:objects} asks of Iris, answered from the world's engine: the pack's objects, how Iris scales and places
* them, and the layout around a world position.
* What {@code iris:objects} asks of Iris's object system, answered from the world's engine: the pack's objects, how Iris
* scales, picks and places them, and the loot of what it placed.
*/
final class IrisObjectHost implements ObjectHost {
private final Engine engine;
private final ModuleLog log;
private volatile PackResourceIds ids;
private final Map<ProceduralObjectSettings, List<ProceduralPlacement>> procedural = new ConcurrentHashMap<>();
private final Map<ProceduralPlacement, IrisObjectPlacement> proceduralOptions = new ConcurrentHashMap<>();
private volatile Map<ResourceId, String> biomeKeys;
private volatile Map<ResourceId, String> regionKeys;
IrisObjectHost(Engine engine, ModuleLog log) {
this.engine = engine;
@@ -94,22 +83,6 @@ final class IrisObjectHost implements ObjectHost {
return IrisSettings.get().getGeneral().isDebug();
}
@Override
public int caveLavaHeight() {
return engine.getDimension().getModuleSettings().find(CaveLavaHeightSettings.class).map(CaveLavaHeightSettings::height)
.orElse(CaveLavaHeightSettings.DEFAULT_HEIGHT);
}
@Override
public int fluidHeight() {
return engine.getDimension().getFluidHeight();
}
@Override
public FeatureSettings columnSettings() {
return new ChunkModuleSettings(engine, ids());
}
@Override
public RNG chunkRandom(int chunkX, int chunkZ) {
long seed = CacheKey.key(chunkX, chunkZ) + engine.getSeedManager().getMantle();
@@ -161,12 +134,6 @@ final class IrisObjectHost implements ObjectHost {
host.getDensity(rng, 0, 0, engine.getData());
}
@Override
public List<ProceduralPlacement> procedural(ProceduralObjectSettings settings,
Function<ProceduralObjectSettings, List<ProceduralPlacement>> resolve) {
return procedural.computeIfAbsent(settings, resolve);
}
@Override
public ObjectBuilder builder() {
return new IrisObjectBuilder(engine.getData());
@@ -177,20 +144,6 @@ final class IrisObjectHost implements ObjectHost {
return proceduralOptions.computeIfAbsent(placement, ProceduralOptions::of);
}
@Override
public Optional<UpperObjects> upperObjects(int worldX, int worldZ) {
UpperDimensionContext upper = engine.getUpperContext();
if (upper == null) {
return Optional.empty();
}
IrisBiome biome = upper.getUpperBiome(worldX, worldZ);
IrisRegion region = upper.getUpperRegion(worldX, worldZ);
return Optional.of(new UpperObjects(
biome == null ? null : biome.getModuleSettings().find(ObjectSettings.class).orElse(null),
region == null ? null : region.getModuleSettings().find(ObjectSettings.class).orElse(null),
biome == null ? null : biome.getLoadKey(), region == null ? null : region.getLoadKey()));
}
@Override
public int placeInto(PlaceableObject object, int x, int y, int z, ObjectPlacement placement, ObjectSink sink, RNG rng) {
IrisData data = engine.getData();
@@ -198,38 +151,13 @@ final class IrisObjectHost implements ObjectHost {
}
@Override
public ResourceId regionAt(int worldX, int worldZ) {
return ids().of(engine.getRegion(worldX, worldZ).getLoadKey());
}
@Override
public ResourceId surfaceBiomeAt(int worldX, int worldZ) {
return ids().of(engine.getSurfaceBiome(worldX, worldZ).getLoadKey());
}
@Override
public ResourceId biomeAt(int worldX, int y, int worldZ) {
return ids().of(engine.getBiome(worldX, y, worldZ).getLoadKey());
}
@Override
public <F extends IrisFeature> Optional<F> biomeDeclaration(ResourceId biome, Class<F> type) {
String key = biomeKeys().get(biome);
if (key == null) {
public Optional<ObjectLoots> placedLoot(int x, int y, int z) {
PlacedObject placed = engine.getObjectPlacement(x, y, z);
IrisObjectPlacement placement = placed == null ? null : placed.getPlacement();
if (placement == null) {
return Optional.empty();
}
IrisBiome loaded = engine.getData().getBiomeLoader().load(key);
return loaded == null ? Optional.empty() : loaded.getModuleSettings().find(type);
}
@Override
public <F extends IrisFeature> Optional<F> regionDeclaration(ResourceId region, Class<F> type) {
String key = regionKeys().get(region);
if (key == null) {
return Optional.empty();
}
IrisRegion loaded = engine.getData().getRegionLoader().load(key);
return loaded == null ? Optional.empty() : loaded.getModuleSettings().find(type);
return Optional.of(new ObjectLoots(placement.getLoot(), placement.getVanillaLoot(), placement.isOverrideGlobalLoot()));
}
@Override
@@ -244,40 +172,14 @@ final class IrisObjectHost implements ObjectHost {
return found;
}
private static <F extends IrisFeature> void addDeclaration(List<Declaration<F>> found, Level level, IrisRegistrant owner, Class<F> type) {
private <F extends IrisFeature> void addDeclaration(List<Declaration<F>> found, Level level, IrisRegistrant owner, Class<F> type) {
if (owner == null) {
return;
}
owner.getModuleSettings().find(type).ifPresent(settings -> found.add(new Declaration<>(level, owner.getLoadKey(), settings)));
owner.getModuleSettings().find(type).ifPresent(settings -> found.add(new Declaration<>(level, ids().of(owner.getLoadKey()), settings)));
}
private IrisObjectPlacement hostPlacement(ObjectPlacement placement) {
return ObjectPlacements.host(placement, engine.getData());
}
private Map<ResourceId, String> biomeKeys() {
Map<ResourceId, String> keys = biomeKeys;
if (keys == null) {
keys = indexOf(engine.getData().getBiomeLoader());
biomeKeys = keys;
}
return keys;
}
private Map<ResourceId, String> regionKeys() {
Map<ResourceId, String> keys = regionKeys;
if (keys == null) {
keys = indexOf(engine.getData().getRegionLoader());
regionKeys = keys;
}
return keys;
}
private Map<ResourceId, String> indexOf(ResourceLoader<?> loader) {
Map<ResourceId, String> index = new HashMap<>();
for (String key : loader.getPossibleKeys()) {
index.putIfAbsent(ids().of(key), key);
}
return Map.copyOf(index);
}
}
@@ -19,7 +19,6 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.builtin.structure.StructureHost;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.engine.framework.Engine;
@@ -75,9 +74,6 @@ public final class IrisPackSettings implements PackSettings {
if (type == ObjectHost.class) {
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
}
if (type == FloatingHost.class) {
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
}
if (type == StructureHost.class) {
return new IrisStructureHost(engine, IrisApiLogger.hostLog());
}
@@ -18,18 +18,17 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.builtin.IrisSeeds;
import art.arcane.iris.builtin.LiveWorld;
import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.builtin.structure.StructureHost;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
import art.arcane.iris.builtin.structure.StructureHost;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
import com.volmit.host.WorldStates;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import com.volmit.world.RunningWorld;
import java.util.Optional;
import java.util.function.Function;
@@ -37,15 +36,16 @@ import java.util.function.Function;
* One Iris world as modules see it: an engine runtime generating with one snapshot of its pack's resources, and the
* state modules keep for it. {@link ModuleWorlds} makes one when the runtime is built and a new one whenever the
* pack's resources reload under it. Iris's built-in modules reach what they need of Iris through its
* {@linkplain #extension extensions}: the world's seeds, its live view and the object, floating and structure hosts.
* {@linkplain #extension extensions}: the spawners' cooldowns Iris saves with the world and the object, floating and
* structure hosts.
*/
public final class IrisPackWorld implements PackWorld {
private final Engine engine;
private final IrisPackResources resources;
private final WorldStates states;
private final ModuleLog log;
private final LiveWorld liveWorld;
private final IrisSeeds seeds;
private final SpawnCooldowns spawnCooldowns;
private volatile RunningWorld running;
private volatile IrisObjectHost objectHost;
private volatile IrisFloatingHost floatingHost;
private volatile IrisStructureHost structureHost;
@@ -55,8 +55,7 @@ public final class IrisPackWorld implements PackWorld {
this.resources = engine.getData().getPackResources();
this.states = new WorldStates();
this.log = IrisApiLogger.hostLog();
this.liveWorld = new IrisLiveWorld(engine, resources);
this.seeds = this::seedOf;
this.spawnCooldowns = new EngineSpawnCooldowns(engine);
}
/** The engine generating this world. */
@@ -69,6 +68,11 @@ public final class IrisPackWorld implements PackWorld {
return engine.getSeedManager().getSeed();
}
@Override
public long seed(ResourceId purpose) {
return IrisWorldSeeds.seed(engine.getSeedManager(), purpose);
}
@Override
public IrisPackResources resources() {
return resources;
@@ -84,6 +88,16 @@ public final class IrisPackWorld implements PackWorld {
return new IrisPackSettings(engine);
}
@Override
public Optional<RunningWorld> running() {
RunningWorld known = running;
if (known == null) {
known = new IrisRunningWorld(engine);
running = known;
}
return Optional.of(known);
}
@Override
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
return states.state(type, () -> create.apply(this));
@@ -104,11 +118,8 @@ public final class IrisPackWorld implements PackWorld {
if (type == Engine.class) {
return engine;
}
if (type == IrisSeeds.class) {
return seeds;
}
if (type == LiveWorld.class) {
return liveWorld;
if (type == SpawnCooldowns.class) {
return spawnCooldowns;
}
if (type == ObjectHost.class) {
return objects();
@@ -122,23 +133,6 @@ public final class IrisPackWorld implements PackWorld {
return null;
}
private long seedOf(IrisSeed seed) {
SeedManager seeds = engine.getSeedManager();
return switch (seed) {
case BIOME -> seeds.getBiome();
case CARVE -> seeds.getCarve();
case COMPLEX -> seeds.getComplex();
case COMPONENT -> seeds.getComponent();
case DECORATOR -> seeds.getDecorator();
case DEPOSIT -> seeds.getDeposit();
case ENTITY -> seeds.getEntity();
case LOOT -> seeds.getLoot();
case MANTLE -> seeds.getMantle();
case POST -> seeds.getPost();
case TERRAIN -> seeds.getTerrain();
};
}
private ObjectHost objects() {
IrisObjectHost host = objectHost;
if (host == null) {
@@ -0,0 +1,117 @@
/*
* 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.Engine;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformWorld;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
import com.volmit.config.FeatureSettings;
import com.volmit.geometry.BlockPosition;
import com.volmit.resource.ResourceId;
import com.volmit.world.RunningWorld;
import com.volmit.world.TerrainSampler;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* An engine as {@link RunningWorld} shows it to services and lifecycle hooks: its terrain streams over the whole world,
* the settings at a column as chunk stages see them, and the engine's own answers about what is placed now.
*/
final class IrisRunningWorld implements RunningWorld {
/** The farthest a Minecraft world reaches from its centre along X or Z, its largest world border. */
private static final int WORLD_LIMIT_BLOCKS = 30_000_000;
private final Engine engine;
private volatile TerrainSampler layout;
private volatile FeatureSettings settings;
private volatile Set<ResourceId> platformLootTables;
IrisRunningWorld(Engine engine) {
this.engine = engine;
}
@Override
public TerrainSampler layout() {
TerrainSampler known = layout;
if (known == null) {
known = new IrisTerrainSampler(engine, packIds(), -WORLD_LIMIT_BLOCKS, -WORLD_LIMIT_BLOCKS, WORLD_LIMIT_BLOCKS, WORLD_LIMIT_BLOCKS);
layout = known;
}
return known;
}
@Override
public FeatureSettings settings() {
FeatureSettings known = settings;
if (known == null) {
known = new ChunkModuleSettings(engine, packIds());
settings = known;
}
return known;
}
private PackResourceIds packIds() {
return new PackResourceIds(engine.getData().getDataFolder());
}
@Override
public int highestBlock(int worldX, int worldZ, boolean ignoreFluid) {
return engine.getHeight(worldX, worldZ, ignoreFluid);
}
@Override
public List<BlockPosition> caveFloors(int chunkX, int chunkZ) {
if (J.isFolia()) {
return List.of();
}
int bottom = engine.getMinHeight();
return engine.getMantle().findMarkers(chunkX, chunkZ, MarkerMatter.CAVE_FLOOR).stream()
.map(floor -> new BlockPosition(floor.getX(), floor.getY() - bottom, floor.getZ()))
.toList();
}
@Override
public Optional<Sky> sky() {
PlatformWorld world = engine.getWorld().platformWorld();
if (world == null) {
return Optional.empty();
}
return Optional.of(new Sky(world.getTime(), world.isStorming(), world.isThundering()));
}
@Override
public Set<ResourceId> platformLootTables() {
Set<ResourceId> known = platformLootTables;
if (known == null) {
known = IrisPlatforms.get().registries().lootTableKeys().stream().map(ResourceId::parse).collect(Collectors.toUnmodifiableSet());
platformLootTables = known;
}
return known;
}
@Override
public boolean debug() {
return engine.isStudio();
}
}
@@ -0,0 +1,36 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.random.WorldRandom;
import com.volmit.resource.ResourceId;
import java.util.Map;
import java.util.function.ToLongFunction;
/**
* How Iris answers {@link com.volmit.world.PackWorld#seed(ResourceId)}: the built-in modules' {@link IrisSeedPurposes}
* get the seeds Iris's worlds always used for those features, every other purpose the API's rule.
*/
final class IrisWorldSeeds {
private static final Map<ResourceId, ToLongFunction<SeedManager>> LEGACY_SEEDS = Map.ofEntries(
Map.entry(IrisSeedPurposes.BIOME, SeedManager::getBiome),
Map.entry(IrisSeedPurposes.CARVE, SeedManager::getCarve),
Map.entry(IrisSeedPurposes.COMPLEX, SeedManager::getComplex),
Map.entry(IrisSeedPurposes.COMPONENT, SeedManager::getComponent),
Map.entry(IrisSeedPurposes.DECORATOR, SeedManager::getDecorator),
Map.entry(IrisSeedPurposes.DEPOSIT, SeedManager::getDeposit),
Map.entry(IrisSeedPurposes.ENTITY, SeedManager::getEntity),
Map.entry(IrisSeedPurposes.LOOT, SeedManager::getLoot),
Map.entry(IrisSeedPurposes.MANTLE, SeedManager::getMantle),
Map.entry(IrisSeedPurposes.POST, SeedManager::getPost),
Map.entry(IrisSeedPurposes.TERRAIN, SeedManager::getTerrain));
private IrisWorldSeeds() {
}
static long seed(SeedManager seeds, ResourceId purpose) {
ToLongFunction<SeedManager> legacy = LEGACY_SEEDS.get(purpose);
return legacy != null ? legacy.applyAsLong(seeds) : WorldRandom.purposeSeed(seeds.getSeed(), purpose);
}
}
@@ -18,12 +18,16 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
import com.volmit.host.WorldStates;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import com.volmit.world.RunningWorld;
import java.util.Optional;
import java.util.function.Function;
/**
@@ -32,14 +36,14 @@ import java.util.function.Function;
* dimension, so its bottom is Y 0, and no lifecycle hook runs for it. Closing it closes the state modules kept.
*/
final class ToolWorld implements PackWorld, AutoCloseable {
private final long seed;
private final SeedManager seeds;
private final PackResources resources;
private final PackSettings settings;
private final WorldStates states;
private final ModuleLog log;
ToolWorld(long seed, PackResources resources, PackSettings settings) {
this.seed = seed;
this.seeds = new SeedManager(seed);
this.resources = resources;
this.settings = settings;
this.states = new WorldStates();
@@ -48,7 +52,12 @@ final class ToolWorld implements PackWorld, AutoCloseable {
@Override
public long seed() {
return seed;
return seeds.getSeed();
}
@Override
public long seed(ResourceId purpose) {
return IrisWorldSeeds.seed(seeds, purpose);
}
@Override
@@ -67,6 +76,12 @@ final class ToolWorld implements PackWorld, AutoCloseable {
return 0;
}
/** Nothing runs a tool's world. */
@Override
public Optional<RunningWorld> running() {
return Optional.empty();
}
@Override
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
return states.state(type, () -> create.apply(this));