mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 02:34:24 +00:00
Hand IrisApi heights above the dimension's bottom: terrain bounds and the mantle bridge no longer use the world's minimum height, and a test covers a dimension that starts at -64
This commit is contained in:
1 parent
9b20fc9c91
commit
818dbef261
10 files changed
+379
-113
No files matched your search
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.volmit.mantle.BlockBox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where IrisApi's heights meet Iris's. IrisApi measures every Y from the dimension's bottom (0 is the bottom
|
||||||
|
* block), and so do Iris's engine, mantle and object placers: the platform adds the world's minimum height
|
||||||
|
* only where it touches the real world. IrisApi heights and engine heights are therefore the same numbers,
|
||||||
|
* and this class is the one place that says so and builds the bounds in them. Code that needs the real world
|
||||||
|
* Y of an IrisApi height adds {@link Engine#getMinHeight()} itself, outside the bridge.
|
||||||
|
*/
|
||||||
|
final class ApiHeights {
|
||||||
|
/** The height of the dimension's lowest block. */
|
||||||
|
static final int BOTTOM = 0;
|
||||||
|
|
||||||
|
private ApiHeights() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The columns from the minima, inclusive, to the maxima, exclusive, over the dimension's whole height. */
|
||||||
|
static BlockBox columns(Engine engine, int minX, int minZ, int maxX, int maxZ) {
|
||||||
|
return new BlockBox(minX, BOTTOM, minZ, maxX, BOTTOM + engine.getHeight(), maxZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,9 +57,8 @@ final class IrisGenerationContext implements GenerationContext {
|
|||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, CHUNK_STAGE_REACH);
|
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, CHUNK_STAGE_REACH);
|
||||||
this.settings = new ChunkModuleSettings(engine, ids);
|
this.settings = new ChunkModuleSettings(engine, ids);
|
||||||
BlockBox chunk = new BlockBox(originX, engine.getMinHeight(), originZ,
|
BlockBox chunk = ApiHeights.columns(engine, originX, originZ, originX + CHUNK_WIDTH, originZ + CHUNK_WIDTH);
|
||||||
originX + CHUNK_WIDTH, engine.getMinHeight() + engine.getHeight(), originZ + CHUNK_WIDTH);
|
this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers);
|
||||||
this.mantle = new IrisModuleMantle(chunk, engine.getMinHeight(), mantleChunks, mantleLayers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,11 +66,6 @@ final class IrisGenerationContext implements GenerationContext {
|
|||||||
return originX;
|
return originX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int originY() {
|
|
||||||
return engine.getMinHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int originZ() {
|
public int originZ() {
|
||||||
return originZ;
|
return originZ;
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
|||||||
this.originZ = chunkZ << CHUNK_SHIFT;
|
this.originZ = chunkZ << CHUNK_SHIFT;
|
||||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, reachBlocks);
|
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, reachBlocks);
|
||||||
this.settings = new ChunkModuleSettings(engine, ids);
|
this.settings = new ChunkModuleSettings(engine, ids);
|
||||||
BlockBox reach = new BlockBox(originX - reachBlocks, engine.getMinHeight(), originZ - reachBlocks,
|
BlockBox reach = ApiHeights.columns(engine, originX - reachBlocks, originZ - reachBlocks,
|
||||||
originX + CHUNK_WIDTH + reachBlocks, engine.getMinHeight() + engine.getHeight(), originZ + CHUNK_WIDTH + reachBlocks);
|
originX + CHUNK_WIDTH + reachBlocks, originZ + CHUNK_WIDTH + reachBlocks);
|
||||||
this.mantle = new IrisModuleMantle(reach, engine.getMinHeight(), chunks, layers);
|
this.mantle = new IrisModuleMantle(reach, chunks, layers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ import java.util.function.UnaryOperator;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iris's mantle as IrisApi's {@link Mantle}, in world coordinates, over the chunks one invocation may touch.
|
* Iris's mantle as IrisApi's {@link Mantle}, in world X and Z and heights above the dimension's bottom (which is
|
||||||
|
* how the mantle stores them), over the chunks one invocation may touch.
|
||||||
* Every module layer a block holds lives in one {@link ModuleLayerValues} slice, so a layer needs no slice type
|
* Every module layer a block holds lives in one {@link ModuleLayerValues} slice, so a layer needs no slice type
|
||||||
* of its own and a layer no loaded module registers survives unchanged. Only registered layers can be used.
|
* of its own and a layer no loaded module registers survives unchanged. Only registered layers can be used.
|
||||||
* Changing a block's values is atomic per mantle chunk, so stages running on neighboring chunks at once never
|
* Changing a block's values is atomic per mantle chunk, so stages running on neighboring chunks at once never
|
||||||
@@ -66,15 +67,12 @@ final class IrisModuleMantle implements Mantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final BlockBox bounds;
|
private final BlockBox bounds;
|
||||||
private final int minY;
|
|
||||||
private final Chunks chunks;
|
private final Chunks chunks;
|
||||||
private final Map<String, MantleRegistration<?>> registrations;
|
private final Map<String, MantleRegistration<?>> registrations;
|
||||||
private BufferedEdit openEdit;
|
private BufferedEdit openEdit;
|
||||||
|
|
||||||
/** @param minY the world height of the mantle's lowest block */
|
IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection<MantleRegistration<?>> registrations) {
|
||||||
IrisModuleMantle(BlockBox bounds, int minY, Chunks chunks, Collection<MantleRegistration<?>> registrations) {
|
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
this.minY = minY;
|
|
||||||
this.chunks = chunks;
|
this.chunks = chunks;
|
||||||
this.registrations = registrations.stream().collect(Collectors.toMap(registration -> registration.key().id(), Function.identity()));
|
this.registrations = registrations.stream().collect(Collectors.toMap(registration -> registration.key().id(), Function.identity()));
|
||||||
}
|
}
|
||||||
@@ -125,7 +123,7 @@ final class IrisModuleMantle implements Mantle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get(int x, int y, int z) {
|
public T get(int x, int y, int z) {
|
||||||
ModuleLayerValues values = valuesAt(chunkAt(x, y, z), x, y - minY, z);
|
ModuleLayerValues values = valuesAt(chunkAt(x, y, z), x, y, z);
|
||||||
return values == null ? null : values.get(key, codec);
|
return values == null ? null : values.get(key, codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,9 +173,8 @@ final class IrisModuleMantle implements Mantle {
|
|||||||
MantleChunk<Matter> chunk = requireChunk(chunkX, chunkZ);
|
MantleChunk<Matter> chunk = requireChunk(chunkX, chunkZ);
|
||||||
int originX = chunkX << CHUNK_SHIFT;
|
int originX = chunkX << CHUNK_SHIFT;
|
||||||
int originZ = chunkZ << CHUNK_SHIFT;
|
int originZ = chunkZ << CHUNK_SHIFT;
|
||||||
chunk.iterate(ModuleLayerValues.class, (localX, mantleY, localZ, values) -> {
|
chunk.iterate(ModuleLayerValues.class, (localX, y, localZ, values) -> {
|
||||||
int x = originX + localX;
|
int x = originX + localX;
|
||||||
int y = mantleY + minY;
|
|
||||||
int z = originZ + localZ;
|
int z = originZ + localZ;
|
||||||
if (values.has(key.id()) && area.contains(x, y, z)) {
|
if (values.has(key.id()) && area.contains(x, y, z)) {
|
||||||
stored.add(new Stored<>(x, y, z, values.get(key, codec)));
|
stored.add(new Stored<>(x, y, z, values.get(key, codec)));
|
||||||
@@ -361,12 +358,11 @@ final class IrisModuleMantle implements Mantle {
|
|||||||
/** Replaces the values of one block under the chunk's lock, so concurrent stages on neighboring chunks keep each other's layers. */
|
/** Replaces the values of one block under the chunk's lock, so concurrent stages on neighboring chunks keep each other's layers. */
|
||||||
private void change(int x, int y, int z, UnaryOperator<ModuleLayerValues> change) {
|
private void change(int x, int y, int z, UnaryOperator<ModuleLayerValues> change) {
|
||||||
MantleChunk<Matter> chunk = chunkAt(x, y, z);
|
MantleChunk<Matter> chunk = chunkAt(x, y, z);
|
||||||
int mantleY = y - minY;
|
|
||||||
synchronized (chunk) {
|
synchronized (chunk) {
|
||||||
ModuleLayerValues current = valuesAt(chunk, x, mantleY, z);
|
ModuleLayerValues current = valuesAt(chunk, x, y, z);
|
||||||
ModuleLayerValues changed = change.apply(current == null ? ModuleLayerValues.EMPTY : current);
|
ModuleLayerValues changed = change.apply(current == null ? ModuleLayerValues.EMPTY : current);
|
||||||
MatterSlice<ModuleLayerValues> slice = chunk.getOrCreate(mantleY >> SECTION_SHIFT).slice(ModuleLayerValues.class);
|
MatterSlice<ModuleLayerValues> slice = chunk.getOrCreate(y >> SECTION_SHIFT).slice(ModuleLayerValues.class);
|
||||||
slice.set(x & LOCAL_MASK, mantleY & LOCAL_MASK, z & LOCAL_MASK, changed.isEmpty() ? null : changed);
|
slice.set(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK, changed.isEmpty() ? null : changed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ final class IrisPlacementInputs implements PlacementContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeSample biome(int worldX, int worldY, int worldZ) {
|
public BiomeSample biome(int worldX, int y, int worldZ) {
|
||||||
throw withoutEngine();
|
throw withoutEngine();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ import java.util.OptionalInt;
|
|||||||
/**
|
/**
|
||||||
* Iris's terrain streams for one invocation. The streams are computed, not prepared, so the bounds are
|
* Iris's terrain streams for one invocation. The streams are computed, not prepared, so the bounds are
|
||||||
* only the area the invocation may touch: a chunk or a placement widened by the pipeline's reach, at
|
* only the area the invocation may touch: a chunk or a placement widened by the pipeline's reach, at
|
||||||
* full height.
|
* full height. Heights, in the bounds and in the samples, are above the dimension's bottom, as the engine's
|
||||||
|
* streams give them.
|
||||||
*/
|
*/
|
||||||
final class IrisTerrainSampler implements TerrainSampler {
|
final class IrisTerrainSampler implements TerrainSampler {
|
||||||
private static final int CHUNK_WIDTH_BLOCKS = 16;
|
private static final int CHUNK_WIDTH_BLOCKS = 16;
|
||||||
@@ -50,7 +51,7 @@ final class IrisTerrainSampler implements TerrainSampler {
|
|||||||
IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ) {
|
IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
this.bounds = new BlockBox(minX, engine.getMinHeight(), minZ, maxX, engine.getMinHeight() + engine.getHeight(), maxZ);
|
this.bounds = ApiHeights.columns(engine, minX, minZ, maxX, maxZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -69,19 +70,19 @@ final class IrisTerrainSampler implements TerrainSampler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeSample biome(int worldX, int worldY, int worldZ) {
|
public BiomeSample biome(int worldX, int y, int worldZ) {
|
||||||
requireInside(worldX, worldY, worldZ);
|
requireInside(worldX, y, worldZ);
|
||||||
IrisBiome surface = engine.getSurfaceBiome(worldX, worldZ);
|
IrisBiome surface = engine.getSurfaceBiome(worldX, worldZ);
|
||||||
Optional<IrisBiome> cave = Optional.ofNullable(engine.getCaveBiome(worldX, worldY, worldZ));
|
Optional<IrisBiome> cave = Optional.ofNullable(engine.getCaveBiome(worldX, y, worldZ));
|
||||||
return new BiomeSample(
|
return new BiomeSample(
|
||||||
ids.of(engine.getRegion(worldX, worldZ).getLoadKey()),
|
ids.of(engine.getRegion(worldX, worldZ).getLoadKey()),
|
||||||
ids.of(surface.getLoadKey()),
|
ids.of(surface.getLoadKey()),
|
||||||
cave.map(biome -> ids.of(biome.getLoadKey())));
|
cave.map(biome -> ids.of(biome.getLoadKey())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requireInside(int worldX, int worldY, int worldZ) {
|
private void requireInside(int worldX, int y, int worldZ) {
|
||||||
if (!bounds.contains(worldX, worldY, worldZ)) {
|
if (!bounds.contains(worldX, y, worldZ)) {
|
||||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + worldY + ", " + worldZ + " is outside the sampled area " + bounds);
|
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the sampled area " + bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,8 @@ import java.util.Collection;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mantle a placement's stages see: the engine's mantle around the placement, in the placer's coordinates
|
* The mantle a placement's stages see: the engine's mantle around the placement, with IrisApi's heights, which are
|
||||||
* (the placer's own height, where 0 is the bottom of the dimension, so a stage's mantle writes land where its
|
* the placer's own (0 is the bottom of the dimension), so a stage's mantle writes land where its block writes do. Everything a stage writes is buffered in one mantle edit of the placement: it reaches the
|
||||||
* block writes do). Everything a stage writes is buffered in one mantle edit of the placement: it reaches the
|
|
||||||
* mantle only when {@link #commit()} runs with the placement's own commit, and {@link #close()} discards it.
|
* mantle only when {@link #commit()} runs with the placement's own commit, and {@link #close()} discards it.
|
||||||
* IrisApi keeps stages from opening edits of their own: the placement owns this one.
|
* IrisApi keeps stages from opening edits of their own: the placement owns this one.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -48,9 +47,9 @@ final class PlacementMantle implements Mantle, AutoCloseable {
|
|||||||
|
|
||||||
PlacementMantle(Engine engine, BlockBox area, Collection<MantleRegistration<?>> layers) {
|
PlacementMantle(Engine engine, BlockBox area, Collection<MantleRegistration<?>> layers) {
|
||||||
this.bounds = area;
|
this.bounds = area;
|
||||||
this.storedBounds = new BlockBox(area.minX(), 0, area.minZ(), area.maxX(), engine.getHeight(), area.maxZ());
|
this.storedBounds = ApiHeights.columns(engine, area.minX(), area.minZ(), area.maxX(), area.maxZ());
|
||||||
this.chunks = new PinnedMantleChunks(engine);
|
this.chunks = new PinnedMantleChunks(engine);
|
||||||
this.placement = new IrisModuleMantle(storedBounds, 0, chunks, layers).edit();
|
this.placement = new IrisModuleMantle(storedBounds, chunks, layers).edit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ import com.volmit.block.BlockState;
|
|||||||
import com.volmit.mantle.BlockBox;
|
import com.volmit.mantle.BlockBox;
|
||||||
import com.volmit.world.BlockView;
|
import com.volmit.world.BlockView;
|
||||||
|
|
||||||
/** The blocks an Iris object placer holds before a placement's writes, within the placement area. */
|
/**
|
||||||
|
* The blocks an Iris object placer holds before a placement's writes, within the placement area. The placer's
|
||||||
|
* heights count from the dimension's bottom, like IrisApi's.
|
||||||
|
*/
|
||||||
final class PlacerBlockView implements BlockView {
|
final class PlacerBlockView implements BlockView {
|
||||||
private final IObjectPlacer placer;
|
private final IObjectPlacer placer;
|
||||||
private final BlockBox bounds;
|
private final BlockBox bounds;
|
||||||
@@ -41,10 +44,10 @@ final class PlacerBlockView implements BlockView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState get(int worldX, int worldY, int worldZ) {
|
public BlockState get(int worldX, int y, int worldZ) {
|
||||||
if (!bounds.contains(worldX, worldY, worldZ)) {
|
if (!bounds.contains(worldX, y, worldZ)) {
|
||||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + worldY + ", " + worldZ + " is outside the placement area " + bounds);
|
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the placement area " + bounds);
|
||||||
}
|
}
|
||||||
return states.toApi(placer.get(worldX, worldY, worldZ));
|
return states.toApi(placer.get(worldX, y, worldZ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
* 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.IrisData;
|
||||||
|
import art.arcane.iris.engine.IrisComplex;
|
||||||
|
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||||
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
|
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||||
|
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||||
|
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||||
|
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;
|
||||||
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
|
import art.arcane.iris.util.common.data.B;
|
||||||
|
import art.arcane.iris.util.project.hunk.Hunk;
|
||||||
|
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||||
|
import art.arcane.volmlib.util.math.RNG;
|
||||||
|
import com.volmit.FeatureRegistry;
|
||||||
|
import com.volmit.IrisModule;
|
||||||
|
import com.volmit.ModuleInfo;
|
||||||
|
import com.volmit.block.BlockState;
|
||||||
|
import com.volmit.host.LoadedPack;
|
||||||
|
import com.volmit.host.ModuleHost;
|
||||||
|
import com.volmit.mantle.BlockBox;
|
||||||
|
import com.volmit.mantle.MantleCodec;
|
||||||
|
import com.volmit.mantle.MantleKey;
|
||||||
|
import com.volmit.mantle.MantleLifetime;
|
||||||
|
import com.volmit.placement.PlacedBlock;
|
||||||
|
import com.volmit.stage.Stage;
|
||||||
|
import com.volmit.stage.StageGraph;
|
||||||
|
import com.volmit.world.BlockPosition;
|
||||||
|
import com.volmit.world.TerrainSampler;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
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.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IrisApi measures every height from the dimension's bottom, whatever the dimension's minimum height is. A
|
||||||
|
* dimension reaching down to world Y -64 is the case that tells the two apart: a chunk stage, a mantle stage and a
|
||||||
|
* placement stage each write at height 0 and must hit the bottom block of the dimension, with terrain samples and
|
||||||
|
* bounds in the same heights.
|
||||||
|
*/
|
||||||
|
public class DimensionBottomTest {
|
||||||
|
private static final int WORLD_MIN_HEIGHT = -64;
|
||||||
|
private static final int DIMENSION_HEIGHT = 64;
|
||||||
|
private static final int BOTTOM = 0;
|
||||||
|
private static final int SURFACE_HEIGHT = 10;
|
||||||
|
private static final BlockBox WHOLE_HEIGHT_OF_ONE_CHUNK = new BlockBox(0, BOTTOM, 0, 16, DIMENSION_HEIGHT, 16);
|
||||||
|
private static final BlockState STONE = BlockState.parse("minecraft:stone");
|
||||||
|
private static final MantleKey<String> MARKS = new MantleKey<>("test:bottom/mark", String.class);
|
||||||
|
private static final MantleCodec<String> TEXT = new MantleCodec<>() {
|
||||||
|
public int version() { return 1; }
|
||||||
|
public void write(DataOutput output, String value) throws IOException { output.writeUTF(value); }
|
||||||
|
public String read(DataInput input, int storedVersion) throws IOException { return input.readUTF(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
|
private final InMemoryMantle storage = new InMemoryMantle(DIMENSION_HEIGHT / 16);
|
||||||
|
private final List<BlockBox> terrainBounds = new ArrayList<>();
|
||||||
|
private final List<BlockBox> viewBounds = new ArrayList<>();
|
||||||
|
private final List<Double> surfaces = new ArrayList<>();
|
||||||
|
private Engine engine;
|
||||||
|
private IrisData data;
|
||||||
|
private LoadedPack pack;
|
||||||
|
|
||||||
|
/** Writes its mark and block at height 0 in whichever pipeline it runs, and records the heights it was shown. */
|
||||||
|
private final class BottomModule implements IrisModule {
|
||||||
|
public ModuleInfo info() { return ModuleInfo.of("test:bottom", "Bottom", "1"); }
|
||||||
|
|
||||||
|
public void install(StageGraph graph) {
|
||||||
|
graph.define(Stage.chunk("test:bottom/chunk")).run(context -> {
|
||||||
|
record(context.terrain());
|
||||||
|
viewBounds.add(context.mantle().bounds());
|
||||||
|
context.hunk(BlockState.class).set(0, BOTTOM, 0, STONE);
|
||||||
|
});
|
||||||
|
graph.define(Stage.mantle("test:bottom/mantle")).reach(0).writesMantle(MARKS).run(context -> {
|
||||||
|
record(context.terrain());
|
||||||
|
viewBounds.add(context.mantle().bounds());
|
||||||
|
context.mantle().layer(MARKS).set(context.originX(), BOTTOM, context.originZ(), "bottom");
|
||||||
|
});
|
||||||
|
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
||||||
|
record(context.terrain());
|
||||||
|
viewBounds.add(context.access().bounds());
|
||||||
|
IrisPlacement.current().anchoredAt(BOTTOM);
|
||||||
|
context.access().set(new PlacedBlock(new BlockPosition(0, BOTTOM, 0), STONE, Optional.empty()));
|
||||||
|
context.access().mantle().layer(MARKS).set(0, BOTTOM, 0, "bottom");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(FeatureRegistry registry) {
|
||||||
|
registry.registerMantle(MARKS, MantleLifetime.GENERATION, TEXT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void record(TerrainSampler terrain) {
|
||||||
|
terrainBounds.add(terrain.bounds());
|
||||||
|
surfaces.add(terrain.column(0, 0).surfaceY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void loadPackOfADimensionBelowWorldYZero() throws IOException {
|
||||||
|
UsableBlockPlatform.bind();
|
||||||
|
pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||||
|
ModuleHost.of(List.of(new BottomModule())).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||||
|
engine = mock(Engine.class);
|
||||||
|
data = mock(IrisData.class);
|
||||||
|
IrisComplex complex = mock(IrisComplex.class);
|
||||||
|
when(complex.getHeightStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> (double) SURFACE_HEIGHT));
|
||||||
|
when(complex.getSlopeStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> 0D));
|
||||||
|
when(engine.getComplex()).thenReturn(complex);
|
||||||
|
when(engine.getMinHeight()).thenReturn(WORLD_MIN_HEIGHT);
|
||||||
|
when(engine.getHeight()).thenReturn(DIMENSION_HEIGHT);
|
||||||
|
when(engine.getData()).thenReturn(data);
|
||||||
|
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||||
|
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
||||||
|
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome());
|
||||||
|
BuiltInPack.seedWorld(engine, 7L);
|
||||||
|
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||||
|
when(moduleSet.pack()).thenReturn(pack);
|
||||||
|
when(data.getModules()).thenReturn(moduleSet);
|
||||||
|
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
||||||
|
when(data.getEngine()).thenReturn(engine);
|
||||||
|
storage.bindTo(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void unload() {
|
||||||
|
pack.close();
|
||||||
|
UsableBlockPlatform.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aChunkStageWritingAtHeightZeroHitsTheBottomBlockOfTheChunk() {
|
||||||
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, DIMENSION_HEIGHT, 16);
|
||||||
|
|
||||||
|
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, false, null, B::getState);
|
||||||
|
|
||||||
|
assertEquals("minecraft:stone", blocks.get(0, BOTTOM, 0).key());
|
||||||
|
assertEquals("the chunk's block hunk starts at the bottom, not at the world's minimum height", 1, countBlocks(blocks));
|
||||||
|
assertSamplesAndBoundsAgree();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aMantleStageWritingAtHeightZeroHitsTheBottomOfTheMantle() {
|
||||||
|
ModuleMantleComponent.forPack(engine, pack, Set.of()).stream()
|
||||||
|
.filter(component -> component.stage().stage().id().toString().equals("test:bottom/mantle"))
|
||||||
|
.forEach(component -> component.generate(0, 0, storage::chunk));
|
||||||
|
|
||||||
|
assertEquals("bottom", storage.value(MARKS, TEXT, 0, BOTTOM, 0));
|
||||||
|
assertSamplesAndBoundsAgree();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aPlacementStageWritingAtHeightZeroHitsTheBottomBlockAndTheBottomOfTheMantle() {
|
||||||
|
IObjectPlacer placer = mock(IObjectPlacer.class);
|
||||||
|
when(placer.getEngine()).thenReturn(engine);
|
||||||
|
IrisObject object = new IrisObject(1, 1, 1);
|
||||||
|
object.setUnsigned(0, 0, 0, B.getState("minecraft:stone"));
|
||||||
|
|
||||||
|
ModuleObjectPlacement.place(object, 0, BOTTOM, 0, placer, new IrisObjectPlacement(), new RNG(2L), null, null, data);
|
||||||
|
|
||||||
|
verify(placer).set(eq(0), eq(BOTTOM), eq(0), any(PlatformBlockState.class));
|
||||||
|
assertEquals("bottom", storage.value(MARKS, TEXT, 0, BOTTOM, 0));
|
||||||
|
BlockBox terrain = terrainBounds.getFirst();
|
||||||
|
assertEquals(BOTTOM, terrain.minY());
|
||||||
|
assertEquals(DIMENSION_HEIGHT, terrain.maxY());
|
||||||
|
assertEquals(List.of(Double.valueOf(SURFACE_HEIGHT)), surfaces);
|
||||||
|
assertTrue("a placement may reach beyond the dimension, so its view holds at least the terrain's heights",
|
||||||
|
viewBounds.getFirst().contains(terrain));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSamplesAndBoundsAgree() {
|
||||||
|
assertEquals(List.of(WHOLE_HEIGHT_OF_ONE_CHUNK), terrainBounds);
|
||||||
|
assertEquals("the mantle view covers the same heights as the terrain", terrainBounds, viewBounds);
|
||||||
|
assertEquals("the terrain samples count from the same bottom", List.of(Double.valueOf(SURFACE_HEIGHT)), surfaces);
|
||||||
|
assertTrue(terrainBounds.getFirst().contains(0, SURFACE_HEIGHT, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int countBlocks(Hunk<PlatformBlockState> blocks) {
|
||||||
|
int count = 0;
|
||||||
|
for (int y = 0; y < blocks.getHeight(); y++) {
|
||||||
|
for (int x = 0; x < blocks.getWidth(); x++) {
|
||||||
|
for (int z = 0; z < blocks.getDepth(); z++) {
|
||||||
|
count += blocks.get(x, y, z) != null ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,8 +75,10 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class IrisModuleMantleTest {
|
public class IrisModuleMantleTest {
|
||||||
private static final int MIN_Y = -64;
|
/** A dimension whose bottom is below world Y 0: IrisApi heights must not depend on it. */
|
||||||
|
private static final int WORLD_MIN_HEIGHT = -64;
|
||||||
private static final int SECTIONS = 4;
|
private static final int SECTIONS = 4;
|
||||||
|
private static final int HEIGHT = SECTIONS * 16;
|
||||||
private static final MantleKey<String> MARKS = new MantleKey<>("iris:marks/mark", String.class);
|
private static final MantleKey<String> MARKS = new MantleKey<>("iris:marks/mark", String.class);
|
||||||
private static final MantleKey<Integer> DEPTHS = new MantleKey<>("iris:marks/depth", Integer.class);
|
private static final MantleKey<Integer> DEPTHS = new MantleKey<>("iris:marks/depth", Integer.class);
|
||||||
private static final MantleCodec<String> TEXT = new MantleCodec<>() {
|
private static final MantleCodec<String> TEXT = new MantleCodec<>() {
|
||||||
@@ -109,55 +111,55 @@ public class IrisModuleMantleTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IrisModuleMantle mantle(BlockBox bounds) {
|
private IrisModuleMantle mantle(BlockBox bounds) {
|
||||||
return new IrisModuleMantle(bounds, MIN_Y, this::chunk, LAYERS);
|
return new IrisModuleMantle(bounds, this::chunk, LAYERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void layersShareABlockAndReadInWorldCoordinatesAcrossChunks() {
|
public void layersShareABlockAndReadInWorldCoordinatesAcrossChunks() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, MIN_Y, -16, 32, 0, 32));
|
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
|
||||||
|
|
||||||
mantle.layer(MARKS).set(-1, -60, 20, "west");
|
mantle.layer(MARKS).set(-1, 4, 20, "west");
|
||||||
mantle.layer(MARKS).set(17, -1, 3, "east");
|
mantle.layer(MARKS).set(17, 63, 3, "east");
|
||||||
mantle.layer(DEPTHS).set(17, -1, 3, 9);
|
mantle.layer(DEPTHS).set(17, 63, 3, 9);
|
||||||
|
|
||||||
assertEquals("west", mantle.layer(MARKS).get(-1, -60, 20));
|
assertEquals("west", mantle.layer(MARKS).get(-1, 4, 20));
|
||||||
assertEquals("east", mantle.layer(MARKS).get(17, -1, 3));
|
assertEquals("east", mantle.layer(MARKS).get(17, 63, 3));
|
||||||
assertEquals(Integer.valueOf(9), mantle.layer(DEPTHS).get(17, -1, 3));
|
assertEquals(Integer.valueOf(9), mantle.layer(DEPTHS).get(17, 63, 3));
|
||||||
mantle.layer(MARKS).remove(17, -1, 3);
|
mantle.layer(MARKS).remove(17, 63, 3);
|
||||||
assertNull(mantle.layer(MARKS).get(17, -1, 3));
|
assertNull(mantle.layer(MARKS).get(17, 63, 3));
|
||||||
assertEquals(Integer.valueOf(9), mantle.layer(DEPTHS).get(17, -1, 3));
|
assertEquals(Integer.valueOf(9), mantle.layer(DEPTHS).get(17, 63, 3));
|
||||||
assertEquals("another invocation sees the same mantle", Integer.valueOf(9),
|
assertEquals("another invocation sees the same mantle", Integer.valueOf(9),
|
||||||
mantle(new BlockBox(16, MIN_Y, 0, 32, 0, 16)).layer(DEPTHS).get(17, -1, 3));
|
mantle(new BlockBox(16, 0, 0, 32, HEIGHT, 16)).layer(DEPTHS).get(17, 63, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void visitsInXThenYThenZOrderAndClearsOnlyItsArea() {
|
public void visitsInXThenYThenZOrderAndClearsOnlyItsArea() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, MIN_Y, -16, 32, 0, 32));
|
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
|
||||||
mantle.layer(MARKS).set(20, -50, 0, "c");
|
mantle.layer(MARKS).set(20, 14, 0, "c");
|
||||||
mantle.layer(MARKS).set(-3, -10, 5, "a");
|
mantle.layer(MARKS).set(-3, 54, 5, "a");
|
||||||
mantle.layer(MARKS).set(20, -60, 9, "b");
|
mantle.layer(MARKS).set(20, 4, 9, "b");
|
||||||
mantle.layer(DEPTHS).set(0, -20, 0, 1);
|
mantle.layer(DEPTHS).set(0, 44, 0, 1);
|
||||||
List<String> visited = new ArrayList<>();
|
List<String> visited = new ArrayList<>();
|
||||||
|
|
||||||
mantle.layer(MARKS).visit(new BlockBox(-16, MIN_Y, -16, 32, 0, 32), (x, y, z, value) -> visited.add(value + "@" + x + "," + y + "," + z));
|
mantle.layer(MARKS).visit(new BlockBox(-16, 0, -16, 32, HEIGHT, 32), (x, y, z, value) -> visited.add(value + "@" + x + "," + y + "," + z));
|
||||||
mantle.layer(MARKS).clear(new BlockBox(16, MIN_Y, -16, 32, 0, 32));
|
mantle.layer(MARKS).clear(new BlockBox(16, 0, -16, 32, HEIGHT, 32));
|
||||||
|
|
||||||
assertEquals(List.of("a@-3,-10,5", "b@20,-60,9", "c@20,-50,0"), visited);
|
assertEquals(List.of("a@-3,54,5", "b@20,4,9", "c@20,14,0"), visited);
|
||||||
assertNull(mantle.layer(MARKS).get(20, -50, 0));
|
assertNull(mantle.layer(MARKS).get(20, 14, 0));
|
||||||
assertEquals("a", mantle.layer(MARKS).get(-3, -10, 5));
|
assertEquals("a", mantle.layer(MARKS).get(-3, 54, 5));
|
||||||
assertEquals(Integer.valueOf(1), mantle.layer(DEPTHS).get(0, -20, 0));
|
assertEquals(Integer.valueOf(1), mantle.layer(DEPTHS).get(0, 44, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refusesLayersNobodyRegisteredWrongTypesAndBlocksOutsideItsBounds() {
|
public void refusesLayersNobodyRegisteredWrongTypesAndBlocksOutsideItsBounds() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(0, MIN_Y, 0, 16, 0, 16));
|
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||||
|
|
||||||
IllegalArgumentException unregistered = assertThrows(IllegalArgumentException.class,
|
IllegalArgumentException unregistered = assertThrows(IllegalArgumentException.class,
|
||||||
() -> mantle.layer(new MantleKey<>("iris:marks/other", String.class)));
|
() -> mantle.layer(new MantleKey<>("iris:marks/other", String.class)));
|
||||||
assertEquals("Mantle layer iris:marks/other is not registered by any module of the pack", unregistered.getMessage());
|
assertEquals("Mantle layer iris:marks/other is not registered by any module of the pack", unregistered.getMessage());
|
||||||
assertThrows(IllegalArgumentException.class, () -> mantle.layer(new MantleKey<>("iris:marks/mark", Integer.class)));
|
assertThrows(IllegalArgumentException.class, () -> mantle.layer(new MantleKey<>("iris:marks/mark", Integer.class)));
|
||||||
assertThrows(IndexOutOfBoundsException.class, () -> mantle.layer(MARKS).set(16, -60, 0, "out"));
|
assertThrows(IndexOutOfBoundsException.class, () -> mantle.layer(MARKS).set(16, 4, 0, "out"));
|
||||||
assertThrows(IndexOutOfBoundsException.class, () -> mantle.layer(MARKS).visit(new BlockBox(0, MIN_Y, 0, 17, 0, 16), (x, y, z, v) -> { }));
|
assertThrows(IndexOutOfBoundsException.class, () -> mantle.layer(MARKS).visit(new BlockBox(0, 0, 0, 17, HEIGHT, 16), (x, y, z, v) -> { }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -173,88 +175,88 @@ public class IrisModuleMantleTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void anEditBuffersChangesAcrossLayersUntilItCommits() {
|
public void anEditBuffersChangesAcrossLayersUntilItCommits() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, MIN_Y, -16, 32, 0, 32));
|
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
|
||||||
mantle.layer(MARKS).set(1, -60, 1, "stored");
|
mantle.layer(MARKS).set(1, 4, 1, "stored");
|
||||||
mantle.layer(MARKS).set(2, -60, 1, "removed");
|
mantle.layer(MARKS).set(2, 4, 1, "removed");
|
||||||
List<String> visited = new ArrayList<>();
|
List<String> visited = new ArrayList<>();
|
||||||
|
|
||||||
try (MantleEdit edit = mantle.edit()) {
|
try (MantleEdit edit = mantle.edit()) {
|
||||||
edit.layer(MARKS).set(20, -50, 0, "added");
|
edit.layer(MARKS).set(20, 14, 0, "added");
|
||||||
edit.layer(MARKS).remove(2, -60, 1);
|
edit.layer(MARKS).remove(2, 4, 1);
|
||||||
edit.layer(DEPTHS).set(20, -50, 0, 3);
|
edit.layer(DEPTHS).set(20, 14, 0, 3);
|
||||||
edit.layer(MARKS).visit(new BlockBox(-16, MIN_Y, -16, 32, 0, 32), (x, y, z, value) -> visited.add(value + "@" + x));
|
edit.layer(MARKS).visit(new BlockBox(-16, 0, -16, 32, HEIGHT, 32), (x, y, z, value) -> visited.add(value + "@" + x));
|
||||||
|
|
||||||
assertEquals("added", edit.layer(MARKS).get(20, -50, 0));
|
assertEquals("added", edit.layer(MARKS).get(20, 14, 0));
|
||||||
assertNull(edit.layer(MARKS).get(2, -60, 1));
|
assertNull(edit.layer(MARKS).get(2, 4, 1));
|
||||||
assertNull("the mantle is unchanged until the commit", mantle.layer(MARKS).get(20, -50, 0));
|
assertNull("the mantle is unchanged until the commit", mantle.layer(MARKS).get(20, 14, 0));
|
||||||
assertEquals("removed", mantle.layer(MARKS).get(2, -60, 1));
|
assertEquals("removed", mantle.layer(MARKS).get(2, 4, 1));
|
||||||
edit.commit();
|
edit.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(List.of("stored@1", "added@20"), visited);
|
assertEquals(List.of("stored@1", "added@20"), visited);
|
||||||
assertEquals("added", mantle.layer(MARKS).get(20, -50, 0));
|
assertEquals("added", mantle.layer(MARKS).get(20, 14, 0));
|
||||||
assertEquals(Integer.valueOf(3), mantle.layer(DEPTHS).get(20, -50, 0));
|
assertEquals(Integer.valueOf(3), mantle.layer(DEPTHS).get(20, 14, 0));
|
||||||
assertNull(mantle.layer(MARKS).get(2, -60, 1));
|
assertNull(mantle.layer(MARKS).get(2, 4, 1));
|
||||||
assertEquals("stored", mantle.layer(MARKS).get(1, -60, 1));
|
assertEquals("stored", mantle.layer(MARKS).get(1, 4, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aClosedEditChangesNothingAndAnOpenEditKeepsTheMantleReadOnly() {
|
public void aClosedEditChangesNothingAndAnOpenEditKeepsTheMantleReadOnly() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(0, MIN_Y, 0, 16, 0, 16));
|
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||||
MantleEdit edit = mantle.edit();
|
MantleEdit edit = mantle.edit();
|
||||||
MantleLayer<String> marks = edit.layer(MARKS);
|
MantleLayer<String> marks = edit.layer(MARKS);
|
||||||
marks.set(1, -60, 1, "discarded");
|
marks.set(1, 4, 1, "discarded");
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(0, -60, 0, "direct"));
|
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(0, 4, 0, "direct"));
|
||||||
assertThrows(IllegalStateException.class, mantle::edit);
|
assertThrows(IllegalStateException.class, mantle::edit);
|
||||||
assertThrows(UnsupportedOperationException.class, edit::edit);
|
assertThrows(UnsupportedOperationException.class, edit::edit);
|
||||||
assertThrows(IndexOutOfBoundsException.class, () -> marks.set(16, -60, 0, "out"));
|
assertThrows(IndexOutOfBoundsException.class, () -> marks.set(16, 4, 0, "out"));
|
||||||
edit.close();
|
edit.close();
|
||||||
edit.close();
|
edit.close();
|
||||||
|
|
||||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
assertNull(mantle.layer(MARKS).get(1, 4, 1));
|
||||||
IllegalStateException closed = assertThrows(IllegalStateException.class, () -> marks.get(1, -60, 1));
|
IllegalStateException closed = assertThrows(IllegalStateException.class, () -> marks.get(1, 4, 1));
|
||||||
assertEquals("This mantle edit is closed; open a new one with edit()", closed.getMessage());
|
assertEquals("This mantle edit is closed; open a new one with edit()", closed.getMessage());
|
||||||
assertThrows(IllegalStateException.class, edit::commit);
|
assertThrows(IllegalStateException.class, edit::commit);
|
||||||
mantle.layer(MARKS).set(0, -60, 0, "direct");
|
mantle.layer(MARKS).set(0, 4, 0, "direct");
|
||||||
mantle.edit().commit();
|
mantle.edit().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
|
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
|
||||||
IrisModuleMantle mantle = new IrisModuleMantle(new BlockBox(0, MIN_Y, 0, 32, 0, 16), MIN_Y,
|
IrisModuleMantle mantle = new IrisModuleMantle(new BlockBox(0, 0, 0, 32, HEIGHT, 16),
|
||||||
(chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS);
|
(chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS);
|
||||||
MantleEdit edit = mantle.edit();
|
MantleEdit edit = mantle.edit();
|
||||||
edit.layer(MARKS).set(1, -60, 1, "first");
|
edit.layer(MARKS).set(1, 4, 1, "first");
|
||||||
edit.layer(MARKS).set(20, -60, 1, "unprepared");
|
edit.layer(MARKS).set(20, 4, 1, "unprepared");
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, edit::commit);
|
assertThrows(IllegalStateException.class, edit::commit);
|
||||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
assertNull(mantle.layer(MARKS).get(1, 4, 1));
|
||||||
assertThrows(IllegalStateException.class, edit::commit);
|
assertThrows(IllegalStateException.class, edit::commit);
|
||||||
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(2, -60, 1, "still open"));
|
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(2, 4, 1, "still open"));
|
||||||
edit.close();
|
edit.close();
|
||||||
mantle.layer(MARKS).set(2, -60, 1, "after close");
|
mantle.layer(MARKS).set(2, 4, 1, "after close");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cleanupRemovesGenerationLayersAndKeepsPersistentAndUnknownOnes() throws IOException {
|
public void cleanupRemovesGenerationLayersAndKeepsPersistentAndUnknownOnes() throws IOException {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(0, MIN_Y, 0, 16, 0, 16));
|
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||||
mantle.layer(MARKS).set(1, -60, 1, "short-lived");
|
mantle.layer(MARKS).set(1, 4, 1, "short-lived");
|
||||||
mantle.layer(DEPTHS).set(1, -60, 1, 7);
|
mantle.layer(DEPTHS).set(1, 4, 1, 7);
|
||||||
mantle.layer(MARKS).set(2, -10, 3, "alone");
|
mantle.layer(MARKS).set(2, 54, 3, "alone");
|
||||||
MantleKey<String> unknown = new MantleKey<>("iris:gone/layer", String.class);
|
MantleKey<String> unknown = new MantleKey<>("iris:gone/layer", String.class);
|
||||||
ModuleLayerValues fromDisk = ModuleLayerValues.read(input(bytes(ModuleLayerValues.EMPTY.with(unknown, TEXT, "kept")
|
ModuleLayerValues fromDisk = ModuleLayerValues.read(input(bytes(ModuleLayerValues.EMPTY.with(unknown, TEXT, "kept")
|
||||||
.with(MARKS, TEXT, "old"))));
|
.with(MARKS, TEXT, "old"))));
|
||||||
chunk(0, 0).getOrCreate((-30 - MIN_Y) >> 4).slice(ModuleLayerValues.class).set(4, (-30 - MIN_Y) & 15, 4, fromDisk);
|
chunk(0, 0).getOrCreate(34 >> 4).slice(ModuleLayerValues.class).set(4, 34 & 15, 4, fromDisk);
|
||||||
|
|
||||||
GenerationLayers.of(LAYERS).removeFrom(chunk(0, 0));
|
GenerationLayers.of(LAYERS).removeFrom(chunk(0, 0));
|
||||||
|
|
||||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
assertNull(mantle.layer(MARKS).get(1, 4, 1));
|
||||||
assertEquals(Integer.valueOf(7), mantle.layer(DEPTHS).get(1, -60, 1));
|
assertEquals(Integer.valueOf(7), mantle.layer(DEPTHS).get(1, 4, 1));
|
||||||
assertNull("a block left without values holds nothing", chunk(0, 0).get((-10 - MIN_Y) >> 4)
|
assertNull("a block left without values holds nothing", chunk(0, 0).get(54 >> 4)
|
||||||
.<ModuleLayerValues>slice(ModuleLayerValues.class).get(2, (-10 - MIN_Y) & 15, 3));
|
.<ModuleLayerValues>slice(ModuleLayerValues.class).get(2, 54 & 15, 3));
|
||||||
assertNull(mantle.layer(MARKS).get(4, -30, 4));
|
assertNull(mantle.layer(MARKS).get(4, 34, 4));
|
||||||
ModuleLayerValues left = chunk(0, 0).get((-30 - MIN_Y) >> 4).<ModuleLayerValues>slice(ModuleLayerValues.class).get(4, (-30 - MIN_Y) & 15, 4);
|
ModuleLayerValues left = chunk(0, 0).get(34 >> 4).<ModuleLayerValues>slice(ModuleLayerValues.class).get(4, 34 & 15, 4);
|
||||||
assertEquals("a layer no module registers stays", "kept", left.get(unknown, TEXT));
|
assertEquals("a layer no module registers stays", "kept", left.get(unknown, TEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +267,7 @@ public class IrisModuleMantleTest {
|
|||||||
public ModuleInfo info() { return ModuleInfo.of("iris:veins", "Veins", "1"); }
|
public ModuleInfo info() { return ModuleInfo.of("iris:veins", "Veins", "1"); }
|
||||||
public void install(StageGraph graph) {
|
public void install(StageGraph graph) {
|
||||||
graph.define(Stage.mantle("iris:veins/plan")).reach(16).writesMantle(planned)
|
graph.define(Stage.mantle("iris:veins/plan")).reach(16).writesMantle(planned)
|
||||||
.run(context -> context.mantle().layer(planned).set(context.originX() + 20, -30, context.originZ() + 3, "vein"));
|
.run(context -> context.mantle().layer(planned).set(context.originX() + 20, 34, context.originZ() + 3, "vein"));
|
||||||
}
|
}
|
||||||
public void register(FeatureRegistry registry) { registry.registerMantle(planned, MantleLifetime.GENERATION, TEXT); }
|
public void register(FeatureRegistry registry) { registry.registerMantle(planned, MantleLifetime.GENERATION, TEXT); }
|
||||||
};
|
};
|
||||||
@@ -278,15 +280,15 @@ public class IrisModuleMantleTest {
|
|||||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||||
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
||||||
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome());
|
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome());
|
||||||
when(engine.getMinHeight()).thenReturn(MIN_Y);
|
when(engine.getMinHeight()).thenReturn(WORLD_MIN_HEIGHT);
|
||||||
when(engine.getHeight()).thenReturn(SECTIONS * 16);
|
when(engine.getHeight()).thenReturn(SECTIONS * 16);
|
||||||
|
|
||||||
try (LoadedPack pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
try (LoadedPack pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||||
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
|
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
|
||||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk);
|
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk);
|
||||||
|
|
||||||
IrisModuleMantle neighbor = new IrisModuleMantle(new BlockBox(16, MIN_Y, 0, 32, 0, 16), MIN_Y, this::chunk, pack.catalog().mantle());
|
IrisModuleMantle neighbor = new IrisModuleMantle(new BlockBox(16, 0, 0, 32, HEIGHT, 16), this::chunk, pack.catalog().mantle());
|
||||||
assertEquals("vein", neighbor.layer(planned).get(20, -30, 3));
|
assertEquals("vein", neighbor.layer(planned).get(20, 34, 3));
|
||||||
}
|
}
|
||||||
assertTrue(chunks.containsKey(1L << 32));
|
assertTrue(chunks.containsKey(1L << 32));
|
||||||
}
|
}
|
||||||
@@ -311,7 +313,7 @@ public class IrisModuleMantleTest {
|
|||||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||||
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
||||||
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome());
|
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome());
|
||||||
when(engine.getMinHeight()).thenReturn(MIN_Y);
|
when(engine.getMinHeight()).thenReturn(WORLD_MIN_HEIGHT);
|
||||||
when(engine.getHeight()).thenReturn(SECTIONS * 16);
|
when(engine.getHeight()).thenReturn(SECTIONS * 16);
|
||||||
|
|
||||||
try (LoadedPack pack = LoadedPack.load(folder.newFolder("finder-pack").toPath(),
|
try (LoadedPack pack = LoadedPack.load(folder.newFolder("finder-pack").toPath(),
|
||||||
|
|||||||
Reference in new issue
Block a user