mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Host side for ported terrain, decorant and deposit: caverns layer, surface kind, image-map ground blocks, bottom world Y, the upper dimension, biomes' own settings, vanilla biome, ore variants, COMPLEX seed; deposit leaves the compiled-in list
This commit is contained in:
1 parent
48e328baef
commit
15a7250ffe
20 files changed
+769
-156
No files matched your search
@@ -20,12 +20,15 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Module settings at world columns, for one engine: the dimension's entry, then the entry of the column's
|
||||
@@ -37,23 +40,45 @@ final class ChunkModuleSettings implements FeatureSettings {
|
||||
private static final String REGION = "region";
|
||||
private static final String BIOME = "biome";
|
||||
|
||||
private final Engine engine;
|
||||
/** The registrants whose settings stack at a column. */
|
||||
interface Levels {
|
||||
IrisRegistrant dimension();
|
||||
|
||||
IrisRegistrant region(int worldX, int worldZ);
|
||||
|
||||
IrisRegistrant surfaceBiome(int worldX, int worldZ);
|
||||
|
||||
/** The biome a {@code BiomeSample} names by {@code id}, or null when the dimension has no such biome. */
|
||||
IrisBiome biome(ResourceId id);
|
||||
}
|
||||
|
||||
private final Levels levels;
|
||||
private final PackResourceIds ids;
|
||||
|
||||
ChunkModuleSettings(Engine engine, PackResourceIds ids) {
|
||||
this.engine = engine;
|
||||
this(new EngineLevels(engine), ids);
|
||||
}
|
||||
|
||||
ChunkModuleSettings(Levels levels, PackResourceIds ids) {
|
||||
this.levels = levels;
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
|
||||
List<Entry<F>> entries = new ArrayList<>(Target.values().length);
|
||||
addEntry(entries, featureType, Target.DIMENSION, DIMENSION, engine.getDimension());
|
||||
addEntry(entries, featureType, Target.REGION, REGION, engine.getRegion(worldX, worldZ));
|
||||
addEntry(entries, featureType, Target.BIOME, BIOME, engine.getSurfaceBiome(worldX, worldZ));
|
||||
addEntry(entries, featureType, Target.DIMENSION, DIMENSION, levels.dimension());
|
||||
addEntry(entries, featureType, Target.REGION, REGION, levels.region(worldX, worldZ));
|
||||
addEntry(entries, featureType, Target.BIOME, BIOME, levels.surfaceBiome(worldX, worldZ));
|
||||
return entries.isEmpty() ? List.of() : List.copyOf(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> Optional<F> declaredBy(ResourceId biome, Class<F> featureType) {
|
||||
IrisBiome declared = levels.biome(biome);
|
||||
return declared == null ? Optional.empty() : declared.getModuleSettings().find(featureType);
|
||||
}
|
||||
|
||||
private <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Target level, String kind,
|
||||
IrisRegistrant owner) {
|
||||
if (owner == null) {
|
||||
@@ -62,4 +87,27 @@ final class ChunkModuleSettings implements FeatureSettings {
|
||||
owner.getModuleSettings().find(featureType)
|
||||
.ifPresent(value -> entries.add(new Entry<>(level, ids.of(kind, owner.getLoadKey()), value)));
|
||||
}
|
||||
|
||||
/** The dimension, region and surface biome the engine generates a column with. */
|
||||
private record EngineLevels(Engine engine) implements Levels {
|
||||
@Override
|
||||
public IrisRegistrant dimension() {
|
||||
return engine.getDimension();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisRegistrant region(int worldX, int worldZ) {
|
||||
return engine.getRegion(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisRegistrant surfaceBiome(int worldX, int worldZ) {
|
||||
return engine.getSurfaceBiome(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisBiome biome(ResourceId id) {
|
||||
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(id).orElse(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,12 @@ final class IrisBlockRegistry implements BlockRegistry {
|
||||
return specs.computeIfAbsent(spec, IrisValues::blockData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState oreFor(BlockState rock, BlockState ore) {
|
||||
PlatformBlockState suited = IrisPlatforms.get().registries().deepSlateOre(platformState(rock), platformState(ore));
|
||||
return BlockState.parse(PlatformBlockStates.namespaced(suited.key()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTrait(BlockState state, BlockTrait trait) {
|
||||
PlatformBlockState platform = platformState(state);
|
||||
|
||||
@@ -59,7 +59,7 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = new BlockStateHunk(blocks, states);
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, TERRAIN_MARGIN_BLOCKS);
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, TERRAIN_MARGIN_BLOCKS, states);
|
||||
this.settings = new ChunkModuleSettings(engine, ids);
|
||||
BlockBox chunk = ApiHeights.columns(engine, originX, originZ, originX + CHUNK_WIDTH, originZ + CHUNK_WIDTH);
|
||||
this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states));
|
||||
|
||||
@@ -26,7 +26,6 @@ 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;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
@@ -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:deposit");
|
||||
/** 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"};
|
||||
@@ -88,7 +87,7 @@ public final class IrisModuleHost {
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
|
||||
new FloatingModule(), new DepositModule(), new DecorantModule(), new LootModule(), new SpawnModule());
|
||||
new FloatingModule(), new DecorantModule(), new LootModule(), new SpawnModule());
|
||||
}
|
||||
|
||||
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
|
||||
|
||||
@@ -95,6 +95,11 @@ final class IrisModuleMantle implements Mantle {
|
||||
return plannedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new MantleCaverns(bounds, chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
if (openEdit != null) {
|
||||
@@ -240,6 +245,12 @@ final class IrisModuleMantle implements Mantle {
|
||||
return plannedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
requireOpen();
|
||||
return new MantleCaverns(bounds, chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException("Mantle edits cannot be nested; write through this edit");
|
||||
|
||||
@@ -192,8 +192,15 @@ public final class IrisPackResources implements PackResources {
|
||||
return new Kind<>(ids, files::keys, (id, key) -> files.read(key));
|
||||
}
|
||||
|
||||
/** Iris's own biome that {@code id}, as a {@code BiomeSample} gives it, names; for host code that reads what the biome declares. */
|
||||
Optional<IrisBiome> irisBiome(ResourceId id) {
|
||||
String key = irisKinds.get(PackBiome.class).keyOf(id);
|
||||
return key == null ? Optional.empty() : Optional.ofNullable(data.getBiomeLoader().load(key));
|
||||
}
|
||||
|
||||
private PackBiome biomeOf(ResourceId id, IrisBiome biome) {
|
||||
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), biome.getRarity(), idsOf(biome.getChildren()));
|
||||
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
|
||||
biome.getRarity(), idsOf(biome.getChildren()));
|
||||
}
|
||||
|
||||
private PackRegion regionOf(ResourceId id, IrisRegion region) {
|
||||
@@ -229,6 +236,11 @@ public final class IrisPackResources implements PackResources {
|
||||
});
|
||||
}
|
||||
|
||||
/** The pack key that has {@code id}, or null. */
|
||||
String keyOf(ResourceId id) {
|
||||
return keysById().get(id);
|
||||
}
|
||||
|
||||
Optional<T> find(ResourceId id) {
|
||||
T cached = built.get(id);
|
||||
if (cached != null) {
|
||||
|
||||
@@ -105,6 +105,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
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();
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.BlockView;
|
||||
import com.volmit.world.TerrainSample;
|
||||
@@ -72,6 +73,16 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
throw withoutEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKind surfaceKind(int worldX, int worldZ) {
|
||||
throw withoutEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
throw withoutEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
throw withoutEngine();
|
||||
|
||||
@@ -20,11 +20,17 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UpperDimensionContext;
|
||||
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.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.UpperDimension;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
@@ -41,18 +47,29 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
private final Engine engine;
|
||||
private final PackResourceIds ids;
|
||||
private final BlockBox bounds;
|
||||
private final PlatformBlockStates states;
|
||||
|
||||
/** The chunk at {@code originX}, {@code originZ} widened by {@code reachBlocks}, over the full world height. */
|
||||
IrisTerrainSampler(Engine engine, PackResourceIds ids, int originX, int originZ, int reachBlocks) {
|
||||
this(engine, ids, originX, originZ, reachBlocks, new PlatformBlockStates(B::getState));
|
||||
}
|
||||
|
||||
/** The chunk at {@code originX}, {@code originZ} widened by {@code reachBlocks}, whose blocks convert with {@code states}. */
|
||||
IrisTerrainSampler(Engine engine, PackResourceIds ids, int originX, int originZ, int reachBlocks, PlatformBlockStates states) {
|
||||
this(engine, ids, originX - reachBlocks, originZ - reachBlocks,
|
||||
originX + CHUNK_WIDTH_BLOCKS + reachBlocks, originZ + CHUNK_WIDTH_BLOCKS + reachBlocks);
|
||||
originX + CHUNK_WIDTH_BLOCKS + reachBlocks, originZ + CHUNK_WIDTH_BLOCKS + reachBlocks, states);
|
||||
}
|
||||
|
||||
/** Columns from the minima, inclusive, to the maxima, exclusive, over the full world height. */
|
||||
IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ) {
|
||||
this(engine, ids, minX, minZ, maxX, maxZ, new PlatformBlockStates(B::getState));
|
||||
}
|
||||
|
||||
private IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ, PlatformBlockStates states) {
|
||||
this.engine = engine;
|
||||
this.ids = ids;
|
||||
this.bounds = ApiHeights.columns(engine, minX, minZ, maxX, maxZ);
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +121,38 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
return OptionalInt.of(Math.max(upper.getUpperSurfaceY(worldX, worldZ), surfaceY + engine.getDimension().getUpperDimensionGap()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKind surfaceKind(int worldX, int worldZ) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
return kindOf(engine.getSurfaceBiome(worldX, worldZ).getInferredType());
|
||||
}
|
||||
|
||||
static BiomeKind kindOf(InferredType type) {
|
||||
return switch (type) {
|
||||
case LAND -> BiomeKind.LAND;
|
||||
case SEA -> BiomeKind.SEA;
|
||||
case SHORE -> BiomeKind.SHORE;
|
||||
case CAVE -> BiomeKind.CAVE;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockState> surfaceBlock(int worldX, int worldZ) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
return Optional.ofNullable(engine.getComplex().getImageMapRuntime().sampleSurfaceBlock(worldX, worldZ)).map(states::toApi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return engine.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UpperDimension> upperDimension() {
|
||||
UpperDimensionContext upper = engine.getUpperContext();
|
||||
return upper == null ? Optional.empty() : Optional.of(new IrisUpperDimension(engine, upper, new PackResourceIds(upper.getData().getDataFolder()), states));
|
||||
}
|
||||
|
||||
private void requireInside(int worldX, int y, int worldZ) {
|
||||
if (!bounds.contains(worldX, y, worldZ)) {
|
||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the sampled area " + bounds);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
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.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.UpperDimension;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** The dimension Iris stacks above the one it generates, as IrisApi's {@link UpperDimension}: its own dimension, region and biome streams. */
|
||||
final class IrisUpperDimension implements UpperDimension {
|
||||
private final UpperDimensionContext upper;
|
||||
private final PackResources resources;
|
||||
private final PlatformBlockStates states;
|
||||
private final ChunkModuleSettings settings;
|
||||
|
||||
IrisUpperDimension(Engine engine, UpperDimensionContext upper, PackResourceIds ids, PlatformBlockStates states) {
|
||||
this.upper = upper;
|
||||
this.resources = upper.getData().getPackResources();
|
||||
this.states = states;
|
||||
this.settings = new ChunkModuleSettings(new UpperLevels(upper, engine), ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThisDimension() {
|
||||
return upper.isSelfReferencing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return upper.getDimension().getLoadKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureSettings settings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockState> surfaceBlock(int worldX, int worldZ) {
|
||||
return Optional.ofNullable(upper.getSurfaceBlock(worldX, worldZ)).map(states::toApi);
|
||||
}
|
||||
|
||||
private record UpperLevels(UpperDimensionContext upper, Engine engine) implements ChunkModuleSettings.Levels {
|
||||
@Override
|
||||
public IrisRegistrant dimension() {
|
||||
return upper.getDimension();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisRegistrant region(int worldX, int worldZ) {
|
||||
return upper.getUpperRegion(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisRegistrant surfaceBiome(int worldX, int worldZ) {
|
||||
return upper.getUpperBiome(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisBiome biome(ResourceId id) {
|
||||
return ((IrisPackResources) upper.getData().getPackResources()).irisBiome(id).orElse(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#caverns()}: where the cave
|
||||
* planner marked a cavern in the mantle's cavern slice, whatever the cavern holds (air, fluid, lava). Stages only read them.
|
||||
*/
|
||||
final class MantleCaverns implements MantleLayer<Boolean> {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int SECTION_SHIFT = 4;
|
||||
private static final int LOCAL_MASK = 15;
|
||||
private static final String READ_ONLY = "Stages read the caverns; the cave planner writes them";
|
||||
private static final Comparator<Position> VISIT_ORDER = Comparator.comparingInt(Position::x)
|
||||
.thenComparingInt(Position::y).thenComparingInt(Position::z);
|
||||
|
||||
private final BlockBox bounds;
|
||||
private final IrisModuleMantle.Chunks chunks;
|
||||
|
||||
MantleCaverns(BlockBox bounds, IrisModuleMantle.Chunks chunks) {
|
||||
this.bounds = bounds;
|
||||
this.chunks = chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(int x, int y, int z) {
|
||||
requireInside(x, y, z);
|
||||
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z) ? Boolean.TRUE : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
|
||||
Objects.requireNonNull(visitor, "visitor");
|
||||
requireInside(area);
|
||||
for (Position carved : carvedIn(area)) {
|
||||
visitor.accept(carved.x(), carved.y(), carved.z(), Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, Boolean value) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
/** The carved positions in {@code area}, ordered by x, then y, then z, as {@link MantleLayer#visit} promises. */
|
||||
private List<Position> carvedIn(BlockBox area) {
|
||||
List<Position> carved = new ArrayList<>();
|
||||
for (int chunkX = area.minX() >> CHUNK_SHIFT; chunkX <= (area.maxX() - 1) >> CHUNK_SHIFT; chunkX++) {
|
||||
for (int chunkZ = area.minZ() >> CHUNK_SHIFT; chunkZ <= (area.maxZ() - 1) >> CHUNK_SHIFT; chunkZ++) {
|
||||
collect(chunkX, chunkZ, area, carved);
|
||||
}
|
||||
}
|
||||
carved.sort(VISIT_ORDER);
|
||||
return carved;
|
||||
}
|
||||
|
||||
private void collect(int chunkX, int chunkZ, BlockBox area, List<Position> carved) {
|
||||
int originX = chunkX << CHUNK_SHIFT;
|
||||
int originZ = chunkZ << CHUNK_SHIFT;
|
||||
requireChunk(chunkX, chunkZ).iterate(MatterCavern.class, (localX, y, localZ, cavern) -> {
|
||||
int x = originX + localX;
|
||||
int z = originZ + localZ;
|
||||
if (cavern != null && area.contains(x, y, z)) {
|
||||
carved.add(new Position(x, y, z));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean cavernAt(MantleChunk<Matter> chunk, int x, int y, int z) {
|
||||
int section = y >> SECTION_SHIFT;
|
||||
if (!chunk.exists(section)) {
|
||||
return false;
|
||||
}
|
||||
Matter matter = chunk.get(section);
|
||||
if (matter == null || !matter.hasSlice(MatterCavern.class)) {
|
||||
return false;
|
||||
}
|
||||
return matter.<MatterCavern>getSlice(MatterCavern.class).get(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK) != null;
|
||||
}
|
||||
|
||||
private MantleChunk<Matter> requireChunk(int chunkX, int chunkZ) {
|
||||
MantleChunk<Matter> chunk = chunks.chunk(chunkX, chunkZ);
|
||||
if (chunk == null) {
|
||||
throw new IllegalStateException("Mantle chunk " + chunkX + ", " + chunkZ + " is inside " + bounds + " but was not prepared");
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void requireInside(int x, int y, int z) {
|
||||
if (!bounds.contains(x, y, z)) {
|
||||
throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the mantle this invocation prepared, " + bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireInside(BlockBox area) {
|
||||
Objects.requireNonNull(area, "area");
|
||||
if (!bounds.contains(area)) {
|
||||
throw new IndexOutOfBoundsException("Area " + area + " is not inside the mantle this invocation prepared, " + bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private record Position(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,11 @@ final class PlacementMantle implements Mantle, AutoCloseable {
|
||||
return new StoredRange<>(placement.blocks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new StoredRange<>(placement.caverns());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException("The placement owns the mantle edit; write through layer()");
|
||||
|
||||
@@ -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:deposit/ores", EngineMetrics::getDeposit);
|
||||
|
||||
private final EngineMetrics metrics;
|
||||
|
||||
|
||||
Reference in new issue
Block a user