mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +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.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, CHUNK_STAGE_REACH);
|
||||
this.settings = new ChunkModuleSettings(engine, ids);
|
||||
BlockBox chunk = new BlockBox(originX, engine.getMinHeight(), originZ,
|
||||
originX + CHUNK_WIDTH, engine.getMinHeight() + engine.getHeight(), originZ + CHUNK_WIDTH);
|
||||
this.mantle = new IrisModuleMantle(chunk, engine.getMinHeight(), mantleChunks, mantleLayers);
|
||||
BlockBox chunk = ApiHeights.columns(engine, originX, originZ, originX + CHUNK_WIDTH, originZ + CHUNK_WIDTH);
|
||||
this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,11 +66,6 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
return originX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int originY() {
|
||||
return engine.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int originZ() {
|
||||
return originZ;
|
||||
|
||||
@@ -53,9 +53,9 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
this.originZ = chunkZ << CHUNK_SHIFT;
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, reachBlocks);
|
||||
this.settings = new ChunkModuleSettings(engine, ids);
|
||||
BlockBox reach = new BlockBox(originX - reachBlocks, engine.getMinHeight(), originZ - reachBlocks,
|
||||
originX + CHUNK_WIDTH + reachBlocks, engine.getMinHeight() + engine.getHeight(), originZ + CHUNK_WIDTH + reachBlocks);
|
||||
this.mantle = new IrisModuleMantle(reach, engine.getMinHeight(), chunks, layers);
|
||||
BlockBox reach = ApiHeights.columns(engine, originX - reachBlocks, originZ - reachBlocks,
|
||||
originX + CHUNK_WIDTH + reachBlocks, originZ + CHUNK_WIDTH + reachBlocks);
|
||||
this.mantle = new IrisModuleMantle(reach, chunks, layers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,8 @@ import java.util.function.UnaryOperator;
|
||||
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
|
||||
* 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
|
||||
@@ -66,15 +67,12 @@ final class IrisModuleMantle implements Mantle {
|
||||
}
|
||||
|
||||
private final BlockBox bounds;
|
||||
private final int minY;
|
||||
private final Chunks chunks;
|
||||
private final Map<String, MantleRegistration<?>> registrations;
|
||||
private BufferedEdit openEdit;
|
||||
|
||||
/** @param minY the world height of the mantle's lowest block */
|
||||
IrisModuleMantle(BlockBox bounds, int minY, Chunks chunks, Collection<MantleRegistration<?>> registrations) {
|
||||
IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection<MantleRegistration<?>> registrations) {
|
||||
this.bounds = bounds;
|
||||
this.minY = minY;
|
||||
this.chunks = chunks;
|
||||
this.registrations = registrations.stream().collect(Collectors.toMap(registration -> registration.key().id(), Function.identity()));
|
||||
}
|
||||
@@ -125,7 +123,7 @@ final class IrisModuleMantle implements Mantle {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -175,9 +173,8 @@ final class IrisModuleMantle implements Mantle {
|
||||
MantleChunk<Matter> chunk = requireChunk(chunkX, chunkZ);
|
||||
int originX = chunkX << 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 y = mantleY + minY;
|
||||
int z = originZ + localZ;
|
||||
if (values.has(key.id()) && area.contains(x, y, z)) {
|
||||
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. */
|
||||
private void change(int x, int y, int z, UnaryOperator<ModuleLayerValues> change) {
|
||||
MantleChunk<Matter> chunk = chunkAt(x, y, z);
|
||||
int mantleY = y - minY;
|
||||
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);
|
||||
MatterSlice<ModuleLayerValues> slice = chunk.getOrCreate(mantleY >> SECTION_SHIFT).slice(ModuleLayerValues.class);
|
||||
slice.set(x & LOCAL_MASK, mantleY & LOCAL_MASK, z & LOCAL_MASK, changed.isEmpty() ? null : changed);
|
||||
MatterSlice<ModuleLayerValues> slice = chunk.getOrCreate(y >> SECTION_SHIFT).slice(ModuleLayerValues.class);
|
||||
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
|
||||
public BiomeSample biome(int worldX, int worldY, int worldZ) {
|
||||
public BiomeSample biome(int worldX, int y, int worldZ) {
|
||||
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
|
||||
* 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 {
|
||||
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) {
|
||||
this.engine = engine;
|
||||
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
|
||||
@@ -69,19 +70,19 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeSample biome(int worldX, int worldY, int worldZ) {
|
||||
requireInside(worldX, worldY, worldZ);
|
||||
public BiomeSample biome(int worldX, int y, int worldZ) {
|
||||
requireInside(worldX, y, 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(
|
||||
ids.of(engine.getRegion(worldX, worldZ).getLoadKey()),
|
||||
ids.of(surface.getLoadKey()),
|
||||
cave.map(biome -> ids.of(biome.getLoadKey())));
|
||||
}
|
||||
|
||||
private void requireInside(int worldX, int worldY, int worldZ) {
|
||||
if (!bounds.contains(worldX, worldY, worldZ)) {
|
||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + worldY + ", " + worldZ + " is outside the sampled area " + bounds);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,8 @@ import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The mantle a placement's stages see: the engine's mantle around the placement, in the placer's coordinates
|
||||
* (the placer's own height, where 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
|
||||
* The mantle a placement's stages see: the engine's mantle around the placement, with IrisApi's heights, which are
|
||||
* 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
|
||||
* 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.
|
||||
* <p>
|
||||
@@ -48,9 +47,9 @@ final class PlacementMantle implements Mantle, AutoCloseable {
|
||||
|
||||
PlacementMantle(Engine engine, BlockBox area, Collection<MantleRegistration<?>> layers) {
|
||||
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.placement = new IrisModuleMantle(storedBounds, 0, chunks, layers).edit();
|
||||
this.placement = new IrisModuleMantle(storedBounds, chunks, layers).edit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,10 @@ import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
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 {
|
||||
private final IObjectPlacer placer;
|
||||
private final BlockBox bounds;
|
||||
@@ -41,10 +44,10 @@ final class PlacerBlockView implements BlockView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int worldX, int worldY, int worldZ) {
|
||||
if (!bounds.contains(worldX, worldY, worldZ)) {
|
||||
throw new IndexOutOfBoundsException("Block " + worldX + ", " + worldY + ", " + worldZ + " is outside the placement area " + bounds);
|
||||
public BlockState get(int worldX, int y, int worldZ) {
|
||||
if (!bounds.contains(worldX, y, worldZ)) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user