mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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:
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));
|
||||
|
||||
@@ -30,6 +30,7 @@ import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.loot.BlockDropping;
|
||||
import art.arcane.iris.engine.loot.LootResources;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -88,19 +89,25 @@ public class BuiltInModulesJarServicesTest {
|
||||
when(blocks.resolve(any(BlockSpec.class))).thenAnswer(invocation -> BlockState.parse("minecraft:" + invocation.<BlockSpec>getArgument(0).block()));
|
||||
when(data.getPackResources().blocks()).thenReturn(blocks);
|
||||
when(data.getPackResources().items()).thenReturn(item -> OptionalInt.of(0));
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
IrisWorld engineWorld = mock(IrisWorld.class);
|
||||
when(engineWorld.minHeight()).thenReturn(-64);
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
IrisComplex complex = mock(IrisComplex.class, RETURNS_DEEP_STUBS);
|
||||
when(complex.getHeightStream().get(X, Z)).thenReturn(64D);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getLoot()).thenReturn(5L);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
biome = bare(IrisBiome.class);
|
||||
dimension = bare(IrisDimension.class);
|
||||
biome = bare(IrisBiome.class, "biome");
|
||||
tables.biome(biome);
|
||||
dimension = bare(IrisDimension.class, "dimension");
|
||||
when(engine.getBiome(X, Y, Z)).thenReturn(biome);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(biome);
|
||||
IrisRegion region = bare(IrisRegion.class);
|
||||
IrisRegion region = bare(IrisRegion.class, "region");
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
world = new EngineGeneration(engine).world();
|
||||
@@ -148,8 +155,9 @@ public class BuiltInModulesJarServicesTest {
|
||||
.copyingJarsTo(folder.newFolder().toPath()));
|
||||
}
|
||||
|
||||
private static <T extends IrisRegistrant> T bare(Class<T> type) {
|
||||
private static <T extends IrisRegistrant> T bare(Class<T> type, String key) {
|
||||
T owner = mock(type);
|
||||
when(owner.getLoadKey()).thenReturn(key);
|
||||
when(owner.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
return owner;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
@@ -39,11 +38,13 @@ import com.volmit.geometry.BlockFace;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -149,10 +150,19 @@ public final class CarveTestWorld implements PackWorld {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
return IrisSeedPurposes.CARVE.equals(purpose) ? carveSeed : WorldRandom.purposeSeed(carveSeed, purpose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
+62
-47
@@ -18,19 +18,16 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.BiomeKind;
|
||||
import art.arcane.iris.builtin.LiveWorld.Level;
|
||||
import art.arcane.iris.builtin.LiveWorld.ObjectLoots;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost.ObjectLoots;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
@@ -40,11 +37,17 @@ import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.RunningWorld.Sky;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -59,15 +62,17 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** What the built-in services ask a running world: the engine's answers for a block, as values. */
|
||||
public class IrisLiveWorldTest {
|
||||
/** What services ask a running Iris world: the engine's layout, settings and platform state, its spawners' cooldowns and the loot of its objects. */
|
||||
public class IrisRunningWorldTest {
|
||||
private static final int X = 10;
|
||||
private static final int Y = 70;
|
||||
private static final int Z = -20;
|
||||
private static final int BOTTOM = -64;
|
||||
private static final int HEIGHT = 384;
|
||||
|
||||
private Engine engine;
|
||||
private LiveWorld live;
|
||||
private PackWorld world;
|
||||
private RunningWorld running;
|
||||
|
||||
@BeforeClass
|
||||
public static void bindPlatform() {
|
||||
@@ -84,64 +89,65 @@ public class IrisLiveWorldTest {
|
||||
engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getMinHeight()).thenReturn(BOTTOM);
|
||||
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||
when(engine.getHeight()).thenReturn(HEIGHT);
|
||||
world = new EngineGeneration(engine).world();
|
||||
running = world.running().orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyLevelReadsTheSettingsOfItsOwnerAtTheBlock() {
|
||||
public void theSettingsAtAColumnAreTheDimensionsTheRegionsAndTheSurfaceBiomes() {
|
||||
IrisDimension dimension = owner(IrisDimension.class, "dimension");
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
IrisRegion region = owner(IrisRegion.class, "region");
|
||||
IrisBiome surface = owner(IrisBiome.class, "surface");
|
||||
IrisBiome here = owner(IrisBiome.class, "here");
|
||||
IrisBiome cave = owner(IrisBiome.class, "cave");
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
when(engine.getBiome(X, Y, Z)).thenReturn(here);
|
||||
when(engine.getCaveBiome(X, Y, Z)).thenReturn(cave);
|
||||
|
||||
assertEquals(List.of("dimension", "region", "surface", "here", "cave"), List.of(
|
||||
tableAt(Level.DIMENSION), tableAt(Level.REGION), tableAt(Level.SURFACE_BIOME), tableAt(Level.BIOME), tableAt(Level.CAVE_BIOME)));
|
||||
SettingsStack<LootSettings> column = running.settings().at(LootSettings.class, X, Z);
|
||||
|
||||
assertEquals(List.of("dimension", "region", "surface"), List.of(tableOf(column, Level.DIMENSION), tableOf(column, Level.REGION),
|
||||
tableOf(column, Level.BIOME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLevelWithoutSettingsOrOwnerHasNone() {
|
||||
IrisRegion bare = mock(IrisRegion.class);
|
||||
when(bare.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
when(engine.getRegion(X, Z)).thenReturn(bare);
|
||||
|
||||
assertTrue(live.settings(LootSettings.class, Level.REGION, X, Y, Z).isEmpty());
|
||||
assertTrue(live.settings(LootSettings.class, Level.BIOME, X, Y, Z).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomesAreAskedByTheIdsThePackGivesThem() {
|
||||
public void theLayoutCoversTheWholeWorldWithBiomesByTheIdsThePackGivesThem() {
|
||||
IrisBiome surface = mock(IrisBiome.class);
|
||||
when(surface.getLoadKey()).thenReturn("Plains/Meadow");
|
||||
when(surface.getInferredType()).thenReturn(InferredType.SHORE);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
when(engine.getCaveBiome(X, Y, Z)).thenReturn(null);
|
||||
when(engine.getCaveBiome(X, Y, Z)).thenReturn(surface);
|
||||
|
||||
assertEquals(engine.getData().getPackResources().idOf("Plains/Meadow"), live.surfaceBiome(X, Z));
|
||||
assertEquals(live.surfaceBiome(X, Z), live.caveBiome(X, Y, Z));
|
||||
assertEquals(BiomeKind.SHORE, live.surfaceKind(X, Z));
|
||||
assertEquals(BOTTOM, live.bottomY());
|
||||
assertEquals(engine.getData().getPackResources().idOf("Plains/Meadow"), running.layout().surfaceBiome(X, Z));
|
||||
assertEquals(Optional.of(running.layout().surfaceBiome(X, Z)), running.layout().caveBiome(X, Y, Z));
|
||||
assertEquals(BiomeKind.SHORE, running.layout().surfaceKind(X, Z));
|
||||
assertTrue("far columns are in the layout", running.layout().bounds().contains(-29_999_999, 0, 29_999_999));
|
||||
assertEquals(HEIGHT, running.layout().bounds().maxY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theHighestBlockIsTheEnginesHeightNow() {
|
||||
when(engine.getHeight(X, Z, true)).thenReturn(60);
|
||||
when(engine.getHeight(X, Z, false)).thenReturn(63);
|
||||
|
||||
assertEquals(60, running.highestBlock(X, Z, true));
|
||||
assertEquals(63, running.highestBlock(X, Z, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSkyIsTheWorldsTimeAndWeatherOnceThereIsAPlatformWorld() {
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
assertEquals(Optional.empty(), live.sky());
|
||||
IrisWorld platformLess = mock(IrisWorld.class);
|
||||
when(engine.getWorld()).thenReturn(platformLess);
|
||||
assertEquals(Optional.empty(), running.sky());
|
||||
|
||||
PlatformWorld platform = mock(PlatformWorld.class);
|
||||
when(platform.getTime()).thenReturn(18000L);
|
||||
when(platform.isThundering()).thenReturn(true);
|
||||
when(world.platformWorld()).thenReturn(platform);
|
||||
when(platformLess.platformWorld()).thenReturn(platform);
|
||||
|
||||
assertEquals(Optional.of(new Sky(18000L, false, true)), live.sky());
|
||||
assertEquals(Optional.of(new Sky(18000L, false, true)), running.sky());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,7 +157,14 @@ public class IrisLiveWorldTest {
|
||||
when(mantle.findMarkers(2, 3, art.arcane.volmlib.util.matter.slices.MarkerMatter.CAVE_FLOOR))
|
||||
.thenReturn(new KList<>(new IrisPosition(40, 0, 50), new IrisPosition(41, 30, 51)));
|
||||
|
||||
assertEquals(List.of(new BlockPosition(40, 64, 50), new BlockPosition(41, 94, 51)), live.caveFloors(2, 3));
|
||||
assertEquals(List.of(new BlockPosition(40, 64, 50), new BlockPosition(41, 94, 51)), running.caveFloors(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStudioWorldIsADebugWorld() {
|
||||
when(engine.isStudio()).thenReturn(true);
|
||||
|
||||
assertTrue(running.debug());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,23 +174,24 @@ public class IrisLiveWorldTest {
|
||||
placement.setOverrideGlobalLoot(true);
|
||||
when(engine.getObjectPlacement(X, Y, Z)).thenReturn(new PlacedObject(placement, null, 1, X, Z));
|
||||
when(engine.getObjectPlacement(X + 1, Y, Z)).thenReturn(new PlacedObject(null, null, 1, X + 1, Z));
|
||||
ObjectHost objects = world.extension(ObjectHost.class).orElseThrow();
|
||||
|
||||
ObjectLoots loots = live.objectLoots(X, Y, Z).orElseThrow();
|
||||
ObjectLoots loots = objects.placedLoot(X, Y, Z).orElseThrow();
|
||||
|
||||
assertEquals(1, loots.packTables().size());
|
||||
assertEquals("chest", loots.packTables().getFirst().name());
|
||||
assertTrue(loots.platformTables().isEmpty());
|
||||
assertTrue(loots.overridesGlobalLoot());
|
||||
assertTrue(loots.defined());
|
||||
assertTrue(live.objectLoots(X + 1, Y, Z).isEmpty());
|
||||
assertTrue(live.objectLoots(X + 2, Y, Z).isEmpty());
|
||||
assertTrue(objects.placedLoot(X + 1, Y, Z).isEmpty());
|
||||
assertTrue(objects.placedLoot(X + 2, Y, Z).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spawnCooldownsCountPerWorldAndPerChunkAndForgetWhatRanOut() {
|
||||
IrisEngineData saved = new IrisEngineData();
|
||||
when(engine.getEngineData()).thenReturn(saved);
|
||||
SpawnCooldowns cooldowns = live.spawnCooldowns();
|
||||
SpawnCooldowns cooldowns = world.extension(SpawnCooldowns.class).orElseThrow();
|
||||
|
||||
assertTrue(cooldowns.canSpawn("wolves", 600_000L));
|
||||
cooldowns.spawned("wolves");
|
||||
@@ -199,10 +213,11 @@ public class IrisLiveWorldTest {
|
||||
T owner = mock(type);
|
||||
LootSettings loot = TestSettings.of(LootSettings.class, "{\"tables\": [\"" + table + "\"]}");
|
||||
when(owner.getModuleSettings()).thenReturn(BuiltInPack.settings(loot));
|
||||
when(owner.getLoadKey()).thenReturn(table);
|
||||
return owner;
|
||||
}
|
||||
|
||||
private String tableAt(Level level) {
|
||||
return live.settings(LootSettings.class, level, X, Y, Z).orElseThrow().tables().getFirst();
|
||||
private static String tableOf(SettingsStack<LootSettings> column, Level level) {
|
||||
return column.level(level).orElseThrow().tables().getFirst();
|
||||
}
|
||||
}
|
||||
+40
-20
@@ -18,27 +18,57 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** An Iris world gives the built-ins Iris's own seeds. */
|
||||
public class IrisWorldFacadesTest {
|
||||
/** An Iris world answers Iris's seed purposes with its legacy seeds and every other purpose by the API's rule. */
|
||||
public class IrisWorldSeedsTest {
|
||||
private static final long WORLD_SEED = 42L;
|
||||
|
||||
@Test
|
||||
public void everyIrisSeedIsTheSeedManagersSeedOfThatName() {
|
||||
public void everyIrisSeedPurposeIsTheSeedManagersSeedOfThatName() {
|
||||
Map<ResourceId, Long> expected = new LinkedHashMap<>();
|
||||
expected.put(IrisSeedPurposes.BIOME, 1L);
|
||||
expected.put(IrisSeedPurposes.CARVE, 2L);
|
||||
expected.put(IrisSeedPurposes.COMPLEX, 3L);
|
||||
expected.put(IrisSeedPurposes.COMPONENT, 4L);
|
||||
expected.put(IrisSeedPurposes.DECORATOR, 5L);
|
||||
expected.put(IrisSeedPurposes.DEPOSIT, 6L);
|
||||
expected.put(IrisSeedPurposes.ENTITY, 7L);
|
||||
expected.put(IrisSeedPurposes.LOOT, 8L);
|
||||
expected.put(IrisSeedPurposes.MANTLE, 9L);
|
||||
expected.put(IrisSeedPurposes.POST, 10L);
|
||||
expected.put(IrisSeedPurposes.TERRAIN, 11L);
|
||||
PackWorld world = new IrisPackWorld(engine(numberedSeeds()));
|
||||
|
||||
expected.forEach((purpose, seed) -> assertEquals(purpose.toString(), seed.longValue(), world.seed(purpose)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anyOtherPurposeFollowsTheApisRule() {
|
||||
ResourceId patches = new ResourceId("example", "moss/patches");
|
||||
PackWorld world = new IrisPackWorld(engine(numberedSeeds()));
|
||||
|
||||
assertEquals(WorldRandom.purposeSeed(WORLD_SEED, patches), world.seed(patches));
|
||||
}
|
||||
|
||||
private static SeedManager numberedSeeds() {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getSeed()).thenReturn(WORLD_SEED);
|
||||
when(seeds.getBiome()).thenReturn(1L);
|
||||
when(seeds.getCarve()).thenReturn(2L);
|
||||
when(seeds.getComplex()).thenReturn(3L);
|
||||
@@ -50,24 +80,14 @@ public class IrisWorldFacadesTest {
|
||||
when(seeds.getMantle()).thenReturn(9L);
|
||||
when(seeds.getPost()).thenReturn(10L);
|
||||
when(seeds.getTerrain()).thenReturn(11L);
|
||||
Engine engine = engine(new IrisDimension());
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
PackWorld world = new IrisPackWorld(engine);
|
||||
Map<IrisSeed, Long> expected = new EnumMap<>(IrisSeed.class);
|
||||
long next = 1;
|
||||
for (IrisSeed seed : IrisSeed.values()) {
|
||||
expected.put(seed, next++);
|
||||
}
|
||||
|
||||
for (IrisSeed seed : IrisSeed.values()) {
|
||||
assertEquals(seed.name(), expected.get(seed).longValue(), world.extension(IrisSeeds.class).orElseThrow().seed(seed));
|
||||
}
|
||||
return seeds;
|
||||
}
|
||||
|
||||
private static Engine engine(IrisDimension dimension) {
|
||||
private static Engine engine(SeedManager seeds) {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
@@ -132,7 +131,7 @@ public class ModuleLogTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theWorldOffersIrissOwnCodeTheEngineAndItsSeedsAsExtensions() {
|
||||
public void theWorldOffersIrissOwnCodeTheEngineAndAnswersItsSeedPurposesWithTheLegacySeeds() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
@@ -142,7 +141,7 @@ public class ModuleLogTest {
|
||||
PackWorld world = new IrisPackWorld(engine);
|
||||
|
||||
assertSame(engine, world.extension(Engine.class).orElseThrow());
|
||||
assertEquals(POST_SEED, world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.POST));
|
||||
assertEquals(POST_SEED, world.seed(IrisSeedPurposes.POST));
|
||||
assertTrue("nothing else is offered", world.extension(String.class).isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
@@ -53,6 +54,21 @@ public final class ModuleResourceFixture {
|
||||
return fixture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes {@code data} (a mock this fixture serves) a pack folder of the fixture's namespace whose registrants' module settings
|
||||
* decode, so a running world's settings at a column name its dimension, region and biomes by the ids the fixture gives.
|
||||
*/
|
||||
public static void serveColumnSettings(IrisData data) {
|
||||
when(data.getDataFolder()).thenReturn(new File(NAMESPACE));
|
||||
when(of(data).resources.settingsStacks()).thenReturn(new SettingsStacks());
|
||||
}
|
||||
|
||||
/** Makes the pack's biome of {@code biome}'s load key {@code biome}, so settings a biome id names are {@code biome}'s. */
|
||||
public ModuleResourceFixture biome(IrisBiome biome) {
|
||||
when(resources.irisBiome(idOf(biome.getLoadKey()))).thenReturn(Optional.of(biome));
|
||||
return this;
|
||||
}
|
||||
|
||||
/** The fixture {@code data} (a mock) already serves from, or a new one. */
|
||||
public static synchronized ModuleResourceFixture of(IrisData data) {
|
||||
ModuleResourceFixture served = SERVED.get(data.getPackResources());
|
||||
|
||||
@@ -32,6 +32,8 @@ public class TreeDefinitionIndexTest {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
IrisRegion region = new IrisRegion();
|
||||
IrisBiome biome = new IrisBiome();
|
||||
region.setLoadKey("forest");
|
||||
biome.setLoadKey("forest/oaks");
|
||||
|
||||
ObjectPlacement explicit = TestSettings.of(ObjectPlacement.class,
|
||||
"{\"place\":[\"custom/ancient_oak\"],\"trees\":[{\"treeTypes\":[\"TREE\"],\"sizes\":[{}]}]}");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.decorant.Decorator;
|
||||
@@ -72,7 +71,7 @@ public class BiomeDecoratorsTest {
|
||||
|
||||
@Test
|
||||
public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() {
|
||||
long decoratorSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.DECORATOR);
|
||||
long decoratorSeed = world.seed(IrisSeedPurposes.DECORATOR);
|
||||
long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed();
|
||||
long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed();
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ public class HintedLocatorTest {
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
stubReachableBiomes();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class LootEnvironmentPinTest {
|
||||
private static final int Z = 20;
|
||||
private static final int SURFACE_Y = 70;
|
||||
private static final int CAVE_Y = 40;
|
||||
private static final int WORLD_HEIGHT = 256;
|
||||
|
||||
private Engine engine;
|
||||
private IrisDimension dimension;
|
||||
@@ -63,15 +64,18 @@ public class LootEnvironmentPinTest {
|
||||
engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture fixture = ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
for (String key : List.of("a", "b", "c", "d", "e")) {
|
||||
fixture.resource(LootResources.TABLES, key, table(key));
|
||||
}
|
||||
IrisComplex complex = engine.getComplex();
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getHeight()).thenReturn(WORLD_HEIGHT);
|
||||
dimension = mock(IrisDimension.class);
|
||||
region = mock(IrisRegion.class);
|
||||
surface = biome("surface");
|
||||
cave = biome("cave");
|
||||
fixture.biome(cave);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
|
||||
@@ -266,6 +266,8 @@ public class LootResolverTest {
|
||||
}
|
||||
|
||||
private static final class ResolutionFixture {
|
||||
private static final int WORLD_HEIGHT = 256;
|
||||
|
||||
private final Engine engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
private final PackWorld world;
|
||||
|
||||
@@ -276,11 +278,13 @@ public class LootResolverTest {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture tables = ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
for (String key : List.of("dimension", "region", "surface")) {
|
||||
tables.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, "{\"name\": \"" + key + "\"}"));
|
||||
}
|
||||
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getHeight()).thenReturn(WORLD_HEIGHT);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getModuleSettings()).thenReturn(fallbackTo("dimension"));
|
||||
when(region.getModuleSettings()).thenReturn(fallbackTo("region"));
|
||||
|
||||
@@ -70,7 +70,7 @@ public class PlacementLootTest {
|
||||
when(resources.blocks()).thenReturn(blocks);
|
||||
when(blocks.find(any(String.class))).thenAnswer(invocation -> java.util.Optional.of(BlockState.parse(invocation.getArgument(0))));
|
||||
when(blocks.resolve(any(BlockSpec.class))).thenAnswer(invocation -> BlockState.parse(invocation.<BlockSpec>getArgument(0).block()));
|
||||
placement = new PlacementLoot(resources, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
||||
placement = new PlacementLoot(resources, () -> Set.of(ResourceId.parse("minecraft:chests/simple_dungeon")), LOOT_SEED, ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
private Loot.Table table(String key) {
|
||||
|
||||
@@ -1,58 +1,72 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.objects.ObjectBuilder;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_MOCKS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Object placing builds its placements' noise and its procedural objects' variants before generation asks. */
|
||||
public class ObjectWarmUpTest {
|
||||
private static final ResourceId REGION = new ResourceId("test", "region");
|
||||
private static final ResourceId BIOME = new ResourceId("test", "biome");
|
||||
|
||||
@Test
|
||||
public void everyPlacementAndProceduralObjectOfBiomesAndRegionsIsBuilt() {
|
||||
ObjectHost host = mock(ObjectHost.class);
|
||||
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));
|
||||
when(host.builder()).thenReturn(mock(ObjectBuilder.class, RETURNS_MOCKS));
|
||||
PackWorld world = worldWithStates(host);
|
||||
ObjectPlacement biomePlacement = placement();
|
||||
ObjectPlacement regionPlacement = placement();
|
||||
ProceduralObjectSettings biomeProceduralSettings = new ProceduralObjectSettings();
|
||||
ProceduralObjectSettings regionProceduralSettings = new ProceduralObjectSettings();
|
||||
ProceduralPlacement biomeTree = mock(ProceduralPlacement.class);
|
||||
ProceduralPlacement regionTree = mock(ProceduralPlacement.class);
|
||||
when(host.procedural(eq(biomeProceduralSettings), any())).thenReturn(List.of(biomeTree));
|
||||
when(host.procedural(eq(regionProceduralSettings), any())).thenReturn(List.of(regionTree));
|
||||
when(host.declarations(ObjectSettings.class)).thenReturn(List.of(
|
||||
new Declaration<>(Level.REGION, "region", objects(regionPlacement)),
|
||||
new Declaration<>(Level.BIOME, "biome", objects(biomePlacement))));
|
||||
new Declaration<>(Level.REGION, REGION, objects(regionPlacement)),
|
||||
new Declaration<>(Level.BIOME, BIOME, objects(biomePlacement))));
|
||||
when(host.declarations(ProceduralObjectSettings.class)).thenReturn(List.of(
|
||||
new Declaration<>(Level.REGION, "region", regionProceduralSettings),
|
||||
new Declaration<>(Level.BIOME, "biome", biomeProceduralSettings)));
|
||||
new Declaration<>(Level.REGION, REGION, oneTree("region-oak")),
|
||||
new Declaration<>(Level.BIOME, BIOME, oneTree("biome-oak"))));
|
||||
|
||||
new ObjectWarmUp(world).warm();
|
||||
|
||||
verify(host).warm(eq(biomePlacement), any(RNG.class));
|
||||
verify(host).warm(eq(regionPlacement), any(RNG.class));
|
||||
verify(biomeTree).variant(any(RNG.class));
|
||||
verify(regionTree).variant(any(RNG.class));
|
||||
verify(host, times(2)).builder();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static PackWorld worldWithStates(ObjectHost host) {
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
Map<Class<?>, Object> states = new HashMap<>();
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.seed(IrisSeedPurposes.COMPONENT)).thenReturn(1337L);
|
||||
when(world.state(any(), any())).thenAnswer(invocation -> states.computeIfAbsent(invocation.getArgument(0),
|
||||
ignored -> invocation.<Function<PackWorld, Object>>getArgument(1).apply(world)));
|
||||
return world;
|
||||
}
|
||||
|
||||
private static ProceduralObjectSettings oneTree(String name) {
|
||||
return TestSettings.of(ProceduralObjectSettings.class, "{\"trees\":[{\"name\":\"" + name + "\"}]}");
|
||||
}
|
||||
|
||||
private static ObjectPlacement placement() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
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.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
@@ -38,7 +37,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -77,11 +75,8 @@ public class PlacementReachTest {
|
||||
"{\"xAxis\":{\"enabled\":true,\"min\":90,\"max\":90,\"interval\":90},\"yAxis\":{\"enabled\":false}}"));
|
||||
when(procedural.translate()).thenReturn(TestSettings.of(ObjectTranslate.class, "{\"x\":3,\"y\":4}"));
|
||||
when(procedural.vacuumSettings()).thenReturn(Optional.empty());
|
||||
ObjectHost host = mock(ObjectHost.class);
|
||||
ProceduralObjectSettings settings = new ProceduralObjectSettings();
|
||||
when(host.procedural(eq(settings), any())).thenReturn(List.of(procedural));
|
||||
|
||||
assertEquals(53, new PlacementReach(host, ModuleLogs.discarding()).ofPack(declaring(ProceduralObjectSettings.class, settings)));
|
||||
assertEquals(53, PlacementReach.of(new ObjectSize(variant.width(), variant.height(), variant.depth()), procedural));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,14 +23,17 @@ import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,6 +41,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -51,19 +55,23 @@ public class TreeGrowingTest {
|
||||
new BlockPosition(10, 70, 20), new BlockPosition(10, 70, 20), ResourceId.ofPlatformKey("TREE"));
|
||||
private static final ResourceId SOURCE = ResourceId.parse("test:dimension/overworld");
|
||||
private static final ResourceId BIOME = ResourceId.parse("test:plains");
|
||||
private static final ResourceId REGION = ResourceId.parse("test:overworld");
|
||||
private static final BlockBox WORLD = new BlockBox(-1000, 0, -1000, 1000, 384, 1000);
|
||||
|
||||
private ObjectHost host;
|
||||
private FeatureSettings settings;
|
||||
private TerrainSampler layout;
|
||||
private PackWorld world;
|
||||
|
||||
@Before
|
||||
public void buildWorld() {
|
||||
host = mock(ObjectHost.class);
|
||||
settings = mock(FeatureSettings.class);
|
||||
when(host.columnSettings()).thenReturn(settings);
|
||||
layout = mock(TerrainSampler.class);
|
||||
when(layout.bounds()).thenReturn(WORLD);
|
||||
RunningWorld running = mock(RunningWorld.class);
|
||||
when(running.settings()).thenReturn(settings);
|
||||
when(running.layout()).thenReturn(layout);
|
||||
world = mock(PackWorld.class);
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(mock(ObjectHost.class)));
|
||||
when(world.running()).thenReturn(Optional.of(running));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +81,7 @@ public class TreeGrowingTest {
|
||||
Optional<SaplingGrowth.Growth> growth = new TreeGrowing().grow(world, OAK_SAPLING, mock(SaplingGrowth.Surroundings.class));
|
||||
|
||||
assertTrue(growth.isEmpty());
|
||||
verify(host, never()).biomeAt(anyInt(), anyInt(), anyInt());
|
||||
verify(layout, never()).surfaceBiome(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,13 +90,13 @@ public class TreeGrowingTest {
|
||||
when(settings.at(TreeGrowthSettings.class, 10, 20)).thenReturn(SettingsStack.of(List.of(new Entry<>(Level.DIMENSION, SOURCE, enabled))));
|
||||
ObjectSettings objects = TestSettings.with(new ObjectSettings(), "objects",
|
||||
List.of(TestSettings.of(ObjectPlacement.class, "{\"place\":[\"a\"]}")));
|
||||
when(host.biomeAt(10, 70, 20)).thenReturn(BIOME);
|
||||
when(host.regionAt(10, 20)).thenReturn(REGION);
|
||||
when(host.biomeDeclaration(eq(BIOME), eq(ObjectSettings.class))).thenReturn(Optional.of(objects));
|
||||
when(host.regionDeclaration(eq(REGION), eq(ObjectSettings.class))).thenReturn(Optional.empty());
|
||||
when(layout.surfaceBiome(10, 20)).thenReturn(BIOME);
|
||||
when(settings.declaredBy(eq(BIOME), eq(ObjectSettings.class))).thenReturn(Optional.of(objects));
|
||||
when(settings.at(eq(ObjectSettings.class), anyInt(), anyInt())).thenReturn(SettingsStack.empty());
|
||||
|
||||
Optional<SaplingGrowth.Growth> growth = new TreeGrowing().grow(world, OAK_SAPLING, mock(SaplingGrowth.Surroundings.class));
|
||||
|
||||
assertTrue(growth.isEmpty());
|
||||
verify(settings).declaredBy(eq(BIOME), any());
|
||||
}
|
||||
}
|
||||
@@ -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.IrisSeeds;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
||||
@@ -80,6 +80,7 @@ import com.volmit.stage.Pipeline;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.UpperDimension;
|
||||
@@ -98,6 +99,7 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* One chunk as IrisApi shows it to a chunk stage, held in memory, so the ported built-ins are tested through the surface
|
||||
@@ -109,6 +111,10 @@ public final class ApiChunk implements GenerationContext {
|
||||
public static final int WIDTH = 16;
|
||||
public static final BlockState AIR = new BlockState("minecraft:air");
|
||||
private static final long SEED = 1337L;
|
||||
private static final List<ResourceId> IRIS_SEED_PURPOSES = List.of(IrisSeedPurposes.BIOME, IrisSeedPurposes.CARVE,
|
||||
IrisSeedPurposes.COMPLEX, IrisSeedPurposes.COMPONENT, IrisSeedPurposes.DECORATOR, IrisSeedPurposes.DEPOSIT,
|
||||
IrisSeedPurposes.ENTITY, IrisSeedPurposes.LOOT, IrisSeedPurposes.MANTLE, IrisSeedPurposes.POST,
|
||||
IrisSeedPurposes.TERRAIN);
|
||||
private static final String FLOATING_ID = "iris:floating";
|
||||
/** What every noise of the fixture's pack samples, everywhere. */
|
||||
private static final double HALF = 0.5;
|
||||
@@ -541,19 +547,26 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place among Iris's purposes. It has
|
||||
* no floating islands: its running layout answers no surface biome and its biomes declare nothing, 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);
|
||||
private final RunningWorld running = mock(RunningWorld.class);
|
||||
|
||||
World() {
|
||||
TerrainSampler noSurfaceBiomes = mock(TerrainSampler.class);
|
||||
FeatureSettings nothingDeclared = mock(FeatureSettings.class);
|
||||
when(running.layout()).thenReturn(noSurfaceBiomes);
|
||||
when(running.settings()).thenReturn(nothingDeclared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
Object offered = type == IrisSeeds.class ? seeds : type == FloatingHost.class ? floating : type == ObjectHost.class ? objects : null;
|
||||
Object offered = type == FloatingHost.class ? floating : type == ObjectHost.class ? objects : null;
|
||||
return Optional.ofNullable(offered).map(type::cast);
|
||||
}
|
||||
|
||||
@@ -562,6 +575,16 @@ public final class ApiChunk implements GenerationContext {
|
||||
return SEED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
return SEED + IRIS_SEED_PURPOSES.indexOf(purpose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.of(running);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
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;
|
||||
@@ -14,6 +13,8 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.ChunkStageContext;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -22,6 +23,7 @@ import java.util.function.Function;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -35,9 +37,9 @@ public class FloatingIslandsTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void columnsWithoutFloatingChildBiomesAreLeftAlone() {
|
||||
FloatingHost host = mock(FloatingHost.class);
|
||||
when(host.surfaceBiome(anyInt(), anyInt())).thenReturn(PLAIN_BIOME);
|
||||
PackWorld world = world(host);
|
||||
TerrainSampler layout = mock(TerrainSampler.class);
|
||||
when(layout.surfaceBiome(anyInt(), anyInt())).thenReturn(PLAIN_BIOME);
|
||||
PackWorld world = world(layout);
|
||||
Hunk<BlockState> output = mock(Hunk.class);
|
||||
when(output.height()).thenReturn(64);
|
||||
ChunkStageContext context = mock(ChunkStageContext.class, RETURNS_DEEP_STUBS);
|
||||
@@ -54,16 +56,21 @@ public class FloatingIslandsTest {
|
||||
islands.fillSolids(context);
|
||||
islands.decorateColumns(context);
|
||||
|
||||
verify(host, org.mockito.Mockito.atLeastOnce()).surfaceBiome(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15);
|
||||
verify(layout, atLeastOnce()).surfaceBiome(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15);
|
||||
verify(output, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static PackWorld world(FloatingHost host) {
|
||||
private static PackWorld world(TerrainSampler layout) {
|
||||
RunningWorld running = mock(RunningWorld.class);
|
||||
when(running.layout()).thenReturn(layout);
|
||||
FeatureSettings nothingDeclaredByBiomes = mock(FeatureSettings.class);
|
||||
when(nothingDeclaredByBiomes.declaredBy(any(), any())).thenReturn(Optional.empty());
|
||||
when(running.settings()).thenReturn(nothingDeclaredByBiomes);
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.extension(FloatingHost.class)).thenReturn(Optional.of(host));
|
||||
when(world.running()).thenReturn(Optional.of(running));
|
||||
when(world.extension(FloatingHost.class)).thenReturn(Optional.of(mock(FloatingHost.class)));
|
||||
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());
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
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.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
@@ -262,7 +261,7 @@ public class CarvingResolverParityTest {
|
||||
return parent;
|
||||
}
|
||||
|
||||
long seed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
||||
long seed = world.seed(IrisSeedPurposes.CARVE) ^ CHILD_SEED_SALT;
|
||||
LegacyCarvingChoice selected = legacyChildrenGenerator(parent, seed).fitRarity(options, worldX, worldZ);
|
||||
if (selected == null || selected.entry == null) {
|
||||
return parent;
|
||||
|
||||
+1
-1
@@ -637,7 +637,7 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
FloatingWorld world = mock(FloatingWorld.class);
|
||||
when(world.merges(parent)).thenReturn(merges);
|
||||
when(world.baseSeed()).thenReturn(baseSeed);
|
||||
when(world.minHeight()).thenReturn(0);
|
||||
when(world.minWorldY()).thenReturn(0);
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -5,7 +5,9 @@ import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackBiome;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,11 +15,15 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ResolvedFloatingChildCarvingResolutionTest {
|
||||
private static final String NAMESPACE = "ns";
|
||||
|
||||
@Test
|
||||
public void carvingBiome_loadsBiomeKeyWhenEntryIdMissing() {
|
||||
ResourceId biome = ResourceId.parse("ns:carving/mushroom");
|
||||
@@ -41,8 +47,12 @@ public class ResolvedFloatingChildCarvingResolutionTest {
|
||||
}
|
||||
|
||||
private static FloatingWorld world(List<CarvingEntry> dimensionCarving, Map<String, ResourceId> biomes) {
|
||||
FloatingHost host = mock(FloatingHost.class);
|
||||
when(host.biome(anyString())).thenAnswer(invocation -> Optional.ofNullable(biomes.get(invocation.getArgument(0, String.class))));
|
||||
return new FloatingWorld(host, null, null, 0L, 0L, 0, dimensionCarving);
|
||||
PackResources resources = mock(PackResources.class);
|
||||
when(resources.idOf(anyString())).thenAnswer(invocation -> ResourceId.ofPackKey(NAMESPACE, invocation.getArgument(0, String.class)));
|
||||
when(resources.find(eq(PackResources.BIOMES), any())).thenAnswer(invocation -> {
|
||||
ResourceId id = invocation.getArgument(1);
|
||||
return biomes.containsValue(id) ? Optional.of(new PackBiome(id, id.path(), id, 1, List.of())) : Optional.empty();
|
||||
});
|
||||
return new FloatingWorld(mock(FloatingHost.class), null, resources, null, 0L, 0L, 0, dimensionCarving);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
@@ -46,6 +47,8 @@ import static org.mockito.Mockito.when;
|
||||
/** The ambient effects due around a player: the region's, then the biome's, each when its interval and chance allow, fully decided. */
|
||||
public class AmbientEffectingTest {
|
||||
private static final BlockPosition AT = new BlockPosition(10, 70, -20);
|
||||
private static final int SURFACE_HEIGHT = 64;
|
||||
private static final int WORLD_HEIGHT = 256;
|
||||
private static final String SOUND_AND_POTION = """
|
||||
{"effects": [{"sound": "ambient.cave", "soundDistance": 4, "minPitch": 0.5, "maxPitch": 0.5, "volume": 2,
|
||||
"potionEffect": "luck", "potionStrength": 1, "potionTicksMin": 100, "potionTicksMax": 100,
|
||||
@@ -66,17 +69,25 @@ public class AmbientEffectingTest {
|
||||
@Before
|
||||
public void buildWorld() {
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture fixture = ModuleResourceFixture.serve(data);
|
||||
ModuleResourceFixture.serveColumnSettings(data);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
IrisWorld engineWorld = mock(IrisWorld.class);
|
||||
PlatformWorld platformWorld = mock(PlatformWorld.class);
|
||||
when(engineWorld.platformWorld()).thenReturn(platformWorld);
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
region = mock(IrisRegion.class);
|
||||
biome = mock(IrisBiome.class);
|
||||
when(region.getLoadKey()).thenReturn("region");
|
||||
when(biome.getLoadKey()).thenReturn("surface");
|
||||
when(region.getModuleSettings()).thenReturn(ModuleSettingsOf.none());
|
||||
when(biome.getModuleSettings()).thenReturn(ModuleSettingsOf.none());
|
||||
fixture.biome(biome);
|
||||
when(engine.getRegion(10, -20)).thenReturn(region);
|
||||
when(engine.getBiome(10, 70, -20)).thenReturn(biome);
|
||||
when(engine.getSurfaceBiome(10, -20)).thenReturn(biome);
|
||||
when(engine.getHeight(10, -20, true)).thenReturn(SURFACE_HEIGHT);
|
||||
when(engine.getHeight()).thenReturn(WORLD_HEIGHT);
|
||||
world = new EngineGeneration(engine).world();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import com.volmit.world.RunningWorld.Sky;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.ModuleLog;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
@@ -40,6 +39,7 @@ import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -92,10 +92,10 @@ public class EntitySpawningTest {
|
||||
|
||||
@Test
|
||||
public void aCaveWithoutFloorMarkersHasNowhereToSpawn() {
|
||||
LiveWorld live = mock(LiveWorld.class);
|
||||
when(live.caveFloors(2, 3)).thenReturn(List.of());
|
||||
RunningWorld running = mock(RunningWorld.class);
|
||||
when(running.caveFloors(2, 3)).thenReturn(List.of());
|
||||
|
||||
assertNull(EntitySpawning.caveSpawnPosition(live, 2, 3));
|
||||
assertNull(EntitySpawning.caveSpawnPosition(running, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.BiomeKind;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
@@ -29,6 +26,8 @@ import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.runtime.IrisEngineData;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.RunningWorld.Sky;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -39,7 +38,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/** Whether a spawner may fire: the biome kind its group wants, the world's time and weather, and its rates in the engine's data. */
|
||||
public class SpawnerGateTest {
|
||||
private LiveWorld live;
|
||||
private SpawnerGate gate;
|
||||
|
||||
@Before
|
||||
public void buildEngine() {
|
||||
@@ -51,7 +50,7 @@ public class SpawnerGateTest {
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
||||
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||
gate = SpawnerGate.of(new EngineGeneration(engine).world());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,21 +81,21 @@ public class SpawnerGateTest {
|
||||
public void aSpawnerWithoutRatesAlwaysMayFire() {
|
||||
Spawner free = spawner("{}");
|
||||
|
||||
SpawnerGate.spawned("free", free, live, 3, 4);
|
||||
gate.spawned("free", free, 3, 4);
|
||||
|
||||
assertTrue(SpawnerGate.canSpawn("free", free, live, 3, 4));
|
||||
assertTrue(gate.canSpawn("free", free, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRateHoldsTheSpawnerBackForItsIntervalPerWorldAndPerChunk() {
|
||||
Spawner limited = spawner("{\"maximumRate\": {\"amount\": 1, \"per\": {\"minutes\": 10}}, \"maximumRatePerChunk\": {\"amount\": 1, \"per\": {\"minutes\": 10}}}");
|
||||
|
||||
assertTrue(SpawnerGate.canSpawn("limited", limited, live, 3, 4));
|
||||
SpawnerGate.spawned("limited", limited, live, 3, 4);
|
||||
assertTrue(gate.canSpawn("limited", limited, 3, 4));
|
||||
gate.spawned("limited", limited, 3, 4);
|
||||
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, live, 3, 4));
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, live, 9, 9));
|
||||
assertTrue(SpawnerGate.canSpawn("other", limited, live, 9, 9));
|
||||
assertFalse(gate.canSpawn("limited", limited, 3, 4));
|
||||
assertFalse(gate.canSpawn("limited", limited, 9, 9));
|
||||
assertTrue(gate.canSpawn("other", limited, 9, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +104,7 @@ public class SpawnerGateTest {
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
|
||||
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow(), 0, 0));
|
||||
assertFalse(SpawnerGate.of(new EngineGeneration(engine).world()).canSpawn("any", spawner("{}"), 0, 0));
|
||||
}
|
||||
|
||||
private static Spawner spawner(String json) {
|
||||
|
||||
@@ -24,10 +24,13 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -51,6 +54,16 @@ public final class TestLayerBlocks {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
throw new UnsupportedOperationException("Only the pack's resources here");
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
@@ -31,6 +30,7 @@ import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -113,9 +113,18 @@ public final class TestPackWorld implements PackWorld {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(ResourceId purpose) {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RunningWorld> running() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
IrisSeeds everySeedIsTheWorlds = which -> seed;
|
||||
return type == IrisSeeds.class ? Optional.of(type.cast(everySeedIsTheWorlds)) : Optional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user