mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Host side of the carve port: NoiseSampler signed and scaled, minHeight, cave biome of a block, MatterMantle over the invocation's mantle, CaveDressing over layers, decorators and palettes, carve leaves the compiled-in list
This commit is contained in:
1 parent
48e328baef
commit
d15c3480ab
14 files changed
+309
-12
No files matched your search
@@ -38,6 +38,16 @@ final class BlockStateHunk implements Hunk<BlockState> {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
/** Iris's own hunk behind this view, which the built-ins that decorate with Iris's decorators write to. */
|
||||
art.arcane.iris.util.project.hunk.Hunk<PlatformBlockState> platform() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** The conversions this chunk's views share. */
|
||||
PlatformBlockStates states() {
|
||||
return states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return blocks.getWidth();
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.CaveDressing;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
import art.arcane.iris.engine.decorator.IrisCeilingDecorator;
|
||||
import art.arcane.iris.engine.decorator.IrisSurfaceDecorator;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.terrain.BiomeLayers;
|
||||
import art.arcane.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link CaveDressing} over Iris's biome layers, decorators and terrain palettes: what the carve module asks of the features that
|
||||
* are not modules yet, in IrisApi's types. Transitional, like the interface.
|
||||
*/
|
||||
final class IrisCaveDressing implements CaveDressing {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final BiomeLayers layers;
|
||||
private final BiomeDecorators decorators;
|
||||
private final TerrainPalettes palettes;
|
||||
private final IrisSurfaceDecorator surfaceDecorator;
|
||||
private final IrisCeilingDecorator ceilingDecorator;
|
||||
|
||||
IrisCaveDressing(Engine engine, IrisPackResources resources, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
this.resources = resources;
|
||||
this.layers = BiomeLayers.of(engine, log);
|
||||
this.decorators = BiomeDecorators.of(engine);
|
||||
this.palettes = TerrainPalettes.of(engine);
|
||||
this.surfaceDecorator = new IrisSurfaceDecorator(engine);
|
||||
this.ceilingDecorator = new IrisCeilingDecorator(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fluidPresentAt(int x, int z) {
|
||||
return B.isFluid(palettes.fluidAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState fluidAt(Hunk<BlockState> chunk, int x, int z) {
|
||||
return nullable(states(chunk), palettes.fluidAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState wall(Hunk<BlockState> chunk, ResourceId biome, RNG rng, int x, int y, int z) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return null;
|
||||
}
|
||||
return nullable(states(chunk), layers.wall(irisBiome).get(rng, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> floorLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int floorY) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return List.of();
|
||||
}
|
||||
return toApi(chunk, layers.generateLayers(irisBiome, engine.getDimension(), x, z, rng, depth, floorY, engine.getData(), engine.getComplex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> ceilingLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int ceilingY) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return List.of();
|
||||
}
|
||||
return toApi(chunk, layers.generateCeilingLayers(irisBiome, engine.getDimension(), x, z, rng, depth, ceilingY, engine.getData(), engine.getComplex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDecorators(ResourceId biome, DecorationPart part) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
return irisBiome != null && decorators.hasDecorators(irisBiome, part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateFloor(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return;
|
||||
}
|
||||
surfaceDecorator.decorate(localX, localZ, x, x, x, z, z, z, platform(chunk), irisBiome, InferredType.CAVE, floorY, airThickness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateCeiling(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return;
|
||||
}
|
||||
ceilingDecorator.decorate(localX, localZ, x, x, x, z, z, z, platform(chunk), irisBiome, InferredType.CAVE, ceilingY, airThickness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState deepSlateOre(Hunk<BlockState> chunk, BlockState existing, BlockState layer) {
|
||||
PlatformBlockStates states = states(chunk);
|
||||
return states.toApi(B.toDeepSlateOre(states.toPlatform(existing), states.toPlatform(layer)));
|
||||
}
|
||||
|
||||
private List<BlockState> toApi(Hunk<BlockState> chunk, List<PlatformBlockState> blocks) {
|
||||
PlatformBlockStates states = states(chunk);
|
||||
List<BlockState> converted = new ArrayList<>(blocks.size());
|
||||
for (PlatformBlockState block : blocks) {
|
||||
converted.add(nullable(states, block));
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
/** A state or null where the layer gave none; IrisApi's conversion reads null as air. */
|
||||
private static BlockState nullable(PlatformBlockStates states, PlatformBlockState block) {
|
||||
return block == null ? null : states.toApi(block);
|
||||
}
|
||||
|
||||
private static PlatformBlockStates states(Hunk<BlockState> chunk) {
|
||||
return hunk(chunk).states();
|
||||
}
|
||||
|
||||
private static art.arcane.iris.util.project.hunk.Hunk<PlatformBlockState> platform(Hunk<BlockState> chunk) {
|
||||
return hunk(chunk).platform();
|
||||
}
|
||||
|
||||
private static BlockStateHunk hunk(Hunk<BlockState> chunk) {
|
||||
if (chunk instanceof BlockStateHunk hunk) {
|
||||
return hunk;
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules dress the chunks Iris hands to them, not " + chunk);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@ import java.util.Collection;
|
||||
final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
/** Mantle stages see the terrain at least this far around their chunk, as chunk stages do (IrisApi's promise). */
|
||||
private static final int TERRAIN_MARGIN_BLOCKS = 16;
|
||||
|
||||
private final Engine engine;
|
||||
private final int originX;
|
||||
@@ -54,7 +56,7 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
this.engine = engine;
|
||||
this.originX = chunkX << CHUNK_SHIFT;
|
||||
this.originZ = chunkZ << CHUNK_SHIFT;
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, reachBlocks);
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, Math.max(reachBlocks, TERRAIN_MARGIN_BLOCKS));
|
||||
this.settings = new ChunkModuleSettings(engine, ids);
|
||||
BlockBox reach = ApiHeights.columns(engine, originX - reachBlocks, originZ - reachBlocks,
|
||||
originX + CHUNK_WIDTH + reachBlocks, originZ + CHUNK_WIDTH + reachBlocks);
|
||||
|
||||
@@ -25,7 +25,6 @@ import art.arcane.iris.engine.loot.LootModule;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.engine.spawn.SpawnModule;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
import art.arcane.iris.engine.modifier.DepositModule;
|
||||
import art.arcane.iris.engine.modifier.FloatingModule;
|
||||
import art.arcane.iris.engine.object.placement.PlacementModules;
|
||||
@@ -63,7 +62,7 @@ public final class IrisModuleHost {
|
||||
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
|
||||
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:carve");
|
||||
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
@@ -87,7 +86,7 @@ public final class IrisModuleHost {
|
||||
}
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
|
||||
return List.of(new TerrainModule(), new ObjectModule(), new StructureModule(),
|
||||
new FloatingModule(), new DepositModule(), new DecorantModule(), new LootModule(), new SpawnModule());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.MantleRegistration;
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.mantle.MantleCodec;
|
||||
@@ -53,7 +54,7 @@ import java.util.stream.Collectors;
|
||||
* lose each other's layers. {@link #edit()} buffers changes across layers until they are committed; while an
|
||||
* edit is open, the view itself only reads.
|
||||
*/
|
||||
final class IrisModuleMantle implements Mantle {
|
||||
final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int SECTION_SHIFT = 4;
|
||||
private static final int LOCAL_MASK = 15;
|
||||
@@ -65,6 +66,11 @@ final class IrisModuleMantle implements Mantle {
|
||||
/** The mantle chunk at chunk coordinates, or null when it is outside what the invocation prepared. */
|
||||
interface Chunks {
|
||||
MantleChunk<Matter> chunk(int chunkX, int chunkZ);
|
||||
|
||||
/** The chunk if the world holds it in memory, whether or not the invocation reaches it; never loads one. */
|
||||
default MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final BlockBox bounds;
|
||||
@@ -85,6 +91,16 @@ final class IrisModuleMantle implements Mantle {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return chunks.chunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return chunks.loadedChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MantleLayer<T> layer(MantleKey<T> key) {
|
||||
return new Layer<>(key, codecOf(key));
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Builds the noise of IrisApi noise styles with Iris's own generators: each style becomes the
|
||||
@@ -36,6 +37,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* built generators.
|
||||
*/
|
||||
final class IrisNoiseFactory implements NoiseFactory {
|
||||
private static final double NO_EXTRA_SCALE = 1D;
|
||||
|
||||
private final IrisData data;
|
||||
private final Map<NoiseStyle, IrisGeneratorStyle> styles = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -47,14 +50,17 @@ final class IrisNoiseFactory implements NoiseFactory {
|
||||
public NoiseSampler sampler(NoiseStyle style, long seed) {
|
||||
IrisGeneratorStyle iris = styles.computeIfAbsent(style, IrisValues::generatorStyle);
|
||||
try {
|
||||
return new CngSampler(iris.create(new RNG(seed), data));
|
||||
return new CngSampler(iris.create(new RNG(seed), data), () -> iris.createNoCache(new RNG(seed), data), NO_EXTRA_SCALE);
|
||||
} catch (RuntimeException failure) {
|
||||
throw new IllegalArgumentException("Cannot build the noise of " + style + ": " + failure.getMessage(), failure);
|
||||
}
|
||||
}
|
||||
|
||||
/** Iris's noise as an IrisApi sampler; CNG is safe for the concurrent reads generation makes. */
|
||||
private record CngSampler(CNG noise) implements NoiseSampler {
|
||||
/**
|
||||
* Iris's noise as an IrisApi sampler; CNG is safe for the concurrent reads generation makes. {@code fresh} builds the same
|
||||
* generator again, unshared, for {@link #scaled}: scaling a generator changes it, and this one is shared.
|
||||
*/
|
||||
private record CngSampler(CNG noise, Supplier<CNG> fresh, double extraScale) implements NoiseSampler {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
return noise.noise(worldX, worldZ);
|
||||
@@ -64,5 +70,23 @@ final class IrisNoiseFactory implements NoiseFactory {
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
return noise.noise(worldX, y, worldZ);
|
||||
}
|
||||
|
||||
/** CNG's own signed read, which answers a repeated read of the same coordinates from a per-thread memo. */
|
||||
@Override
|
||||
public double signed(double worldX, double worldZ) {
|
||||
return noise.noiseFastSigned2D(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double signed(double worldX, double y, double worldZ) {
|
||||
return noise.noiseFastSigned3D(worldX, y, worldZ);
|
||||
}
|
||||
|
||||
/** The generator with {@code factor} baked into its scale, as {@code create(...).bake().scale(factor).bake()} always gave. */
|
||||
@Override
|
||||
public NoiseSampler scaled(double factor) {
|
||||
double total = extraScale * factor;
|
||||
return new CngSampler(fresh.get().bake().scale(total).bake(), fresh, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,14 @@ public final class IrisPackResources implements PackResources {
|
||||
return kindOf(type).ids();
|
||||
}
|
||||
|
||||
/** The biome of the pack with this id as Iris's own class, for the built-ins that decorate with it; null when the pack has none. */
|
||||
public IrisBiome irisBiome(ResourceId id) {
|
||||
String key = kindOf(PackBiome.class).keyOf(id);
|
||||
return key == null ? null : data.getBiomeLoader().load(key);
|
||||
}
|
||||
|
||||
/** The id of the resource the pack names by {@code packKey}, such as {@code overworld:castle/keep} for {@code castle/keep}. */
|
||||
@Override
|
||||
public ResourceId idOf(String packKey) {
|
||||
return ids.of(packKey);
|
||||
}
|
||||
@@ -246,6 +253,11 @@ public final class IrisPackResources implements PackResources {
|
||||
return Optional.of(raced != null ? raced : made);
|
||||
}
|
||||
|
||||
/** The key of the resource with this id; null when the pack has none. */
|
||||
String keyOf(ResourceId id) {
|
||||
return keysById().get(id);
|
||||
}
|
||||
|
||||
List<ResourceId> ids() {
|
||||
return keysById().keySet().stream().sorted().toList();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
@@ -35,7 +36,7 @@ import java.util.function.Function;
|
||||
* pack's resources reload under it. Iris's built-in modules reach the engine through {@link #of(PackWorld)}, as built-in
|
||||
* reaches do through {@link IrisPackSettings#of}.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, CaveDressing.Source {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final WorldStates states;
|
||||
@@ -78,6 +79,11 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minHeight() {
|
||||
return engine.getWorld().minHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return new IrisPackSettings(engine);
|
||||
@@ -99,6 +105,11 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaveDressing caveDressing() {
|
||||
return state(IrisCaveDressing.class, world -> new IrisCaveDressing(engine, resources, log));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
SeedManager seeds = engine.getSeedManager();
|
||||
|
||||
@@ -22,6 +22,7 @@ import art.arcane.iris.engine.UpperDimensionContext;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
@@ -87,6 +88,12 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
cave.map(biome -> ids.of(biome.getLoadKey())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceId> caveBiome(int worldX, int y, int worldZ) {
|
||||
requireInside(worldX, y, worldZ);
|
||||
return Optional.ofNullable(engine.getCaveBiome(worldX, y, worldZ)).map(biome -> ids.of(biome.getLoadKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
return engine.getDimension().getFluidHeight();
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -37,11 +39,16 @@ final class PackResourceIds {
|
||||
private static final String UNNAMED_PACK = "pack";
|
||||
private static final String PACK_PATH = "pack";
|
||||
|
||||
/** Stages ask per column, so each key is turned into its id once, however many invocations ask. A pack has a few thousand keys at most. */
|
||||
private static final Map<String, Map<String, ResourceId>> BY_NAMESPACE_AND_KEY = new ConcurrentHashMap<>();
|
||||
|
||||
private final String namespace;
|
||||
private final Map<String, ResourceId> byKey;
|
||||
|
||||
PackResourceIds(File packFolder) {
|
||||
String name = NOT_NAMESPACE.matcher(packFolder.getName().toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT);
|
||||
this.namespace = name.isEmpty() ? UNNAMED_PACK : name;
|
||||
this.byKey = BY_NAMESPACE_AND_KEY.computeIfAbsent(namespace, ignored -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
/** The namespace of every id this pack's resources have. */
|
||||
@@ -56,7 +63,8 @@ final class PackResourceIds {
|
||||
|
||||
/** {@code key} of a resource whose type its use makes clear, such as a biome in a biome sample. */
|
||||
ResourceId of(String key) {
|
||||
return new ResourceId(namespace, NOT_PATH.matcher(key.toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT));
|
||||
return byKey.computeIfAbsent(key,
|
||||
known -> new ResourceId(namespace, NOT_PATH.matcher(known.toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT)));
|
||||
}
|
||||
|
||||
/** {@code key} of a resource of {@code type}, such as {@code overworld:biome/desert/dunes}. */
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
/**
|
||||
@@ -27,6 +29,10 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
* released once the chunk's stages are done.
|
||||
*/
|
||||
final class PinnedMantleChunk implements IrisModuleMantle.Chunks, AutoCloseable {
|
||||
/** A tectonic plate holds 32 by 32 chunks. */
|
||||
private static final int PLATE_SHIFT = 5;
|
||||
private static final int PLATE_MASK = (1 << PLATE_SHIFT) - 1;
|
||||
|
||||
private final Engine engine;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
@@ -49,6 +55,16 @@ final class PinnedMantleChunk implements IrisModuleMantle.Chunks, AutoCloseable
|
||||
return pinned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int x, int z) {
|
||||
Mantle<Matter> mantle = engine.getMantle().getMantle();
|
||||
TectonicPlate<Matter> plate = mantle.getLoadedRegions().get(Mantle.key(x >> PLATE_SHIFT, z >> PLATE_SHIFT));
|
||||
if (plate == null || plate.isClosed()) {
|
||||
return null;
|
||||
}
|
||||
return plate.get(x & PLATE_MASK, z & PLATE_MASK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (pinned != null) {
|
||||
|
||||
@@ -35,7 +35,8 @@ final class StageMetrics implements StageTimings {
|
||||
private static final double NANOS_PER_MILLISECOND = 1_000_000D;
|
||||
private static final Map<String, Function<EngineMetrics, AtomicRollingSequence>> NAMED = Map.of(
|
||||
"iris:post/smooth", EngineMetrics::getPost,
|
||||
"iris:perfection/surface", EngineMetrics::getPerfection);
|
||||
"iris:perfection/surface", EngineMetrics::getPerfection,
|
||||
"iris:carve/apply", EngineMetrics::getCave);
|
||||
|
||||
private final EngineMetrics metrics;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
import art.arcane.iris.engine.modifier.MatterModule;
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.modifier.PostModule;
|
||||
@@ -51,7 +52,7 @@ public final class BuiltInPack {
|
||||
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
|
||||
*/
|
||||
public static List<IrisModule> jarModules() {
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new CarveModule());
|
||||
}
|
||||
|
||||
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
|
||||
|
||||
@@ -128,6 +128,36 @@ public class IrisValuesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signedNoiseIsTheSignedFastReadOfTheIrisGeneratorsNoise() {
|
||||
String json = "{\"style\": \"SIMPLEX\", \"zoom\": 4, \"exponent\": 1.5, \"fracture\": {\"style\": \"PERLIN\", \"zoom\": 2, \"multiplier\": 3}}";
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
CNG iris = new Gson().fromJson(json, IrisGeneratorStyle.class).create(new RNG(1337), data);
|
||||
NoiseSampler sampler = new IrisNoiseFactory(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 1337);
|
||||
|
||||
for (double[] column : COLUMNS) {
|
||||
assertEquals(iris.noiseFastSigned2D(column[0], column[1]), sampler.signed(column[0], column[1]), 0);
|
||||
assertEquals(iris.noiseFastSigned3D(column[0], 64, column[1]), sampler.signed(column[0], 64, column[1]), 0);
|
||||
assertEquals(iris.noiseFastSigned3D(column[0], 64, column[1]), sampler.signed(column[0], 64, column[1]), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scaledNoiseIsTheGeneratorWithTheScaleBakedIn() {
|
||||
String json = "{\"style\": \"CELLULAR_IRIS_DOUBLE\", \"zoom\": 1}";
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
double scale = 1.5D;
|
||||
CNG baked = new Gson().fromJson(json, IrisGeneratorStyle.class).createNoCache(new RNG(4242), data).bake().scale(scale).bake();
|
||||
NoiseSampler plain = new IrisNoiseFactory(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 4242);
|
||||
NoiseSampler scaled = plain.scaled(scale);
|
||||
|
||||
for (int x = -30; x <= 30; x += 3) {
|
||||
assertEquals(baked.noiseFast2D(x, 7), scaled.sample(x, 7), 0);
|
||||
}
|
||||
assertEquals("the sampler it was made from is left as it was", new Gson().fromJson(json, IrisGeneratorStyle.class)
|
||||
.createNoCache(new RNG(4242), data).noise(9, 4), plain.sample(9, 4), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStyleNameIrisDoesNotKnowIsFlat() {
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
|
||||
Reference in new issue
Block a user