mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Make Y the height above the dimension's bottom everywhere in the API: document it, and drop GenerationContext.originY, which is always 0 now
This commit is contained in:
1 parent
33fc9adca9
commit
09afee8ae3
26 files changed
+91
-54
No files matched your search
@@ -131,9 +131,9 @@ class ApiValuesTest {
|
||||
@Test
|
||||
void placementAlignsAnchorsAndCheckedArithmeticNeverWraps() {
|
||||
var object = new GeneratedObject(new BlockBox(-1, -1, -1, 2, 2, 2), new BlockPosition(1, 1, 1), List.of(), List.of());
|
||||
var request = new PlacementRequest(ResourceId.parse("test:placement"), object, new BlockPosition(-16, -64, -16));
|
||||
assertEquals(new BlockPosition(-16, -64, -16), request.worldPosition(object.anchor()));
|
||||
assertEquals(new BlockBox(-18, -66, -18, -15, -63, -15), request.footprint());
|
||||
var request = new PlacementRequest(ResourceId.parse("test:placement"), object, new BlockPosition(-16, 64, -16));
|
||||
assertEquals(new BlockPosition(-16, 64, -16), request.worldPosition(object.anchor()));
|
||||
assertEquals(new BlockBox(-18, 62, -18, -15, 65, -15), request.footprint());
|
||||
var overflow = new PlacementRequest(request.id(), object, new BlockPosition(Integer.MAX_VALUE, 0, 0));
|
||||
assertThrows(ArithmeticException.class, overflow::footprint);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ class ChunkPipelineTest {
|
||||
private static final int SIZE = 4;
|
||||
private static final int HEIGHT = 8;
|
||||
private static final int CHUNK = 16;
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
private static final int BOTTOM = 0;
|
||||
private static final int TOP = 384;
|
||||
private static final BlockState AIR = new BlockState("minecraft:air");
|
||||
private static final BlockState GRASS = new BlockState("minecraft:grass_block");
|
||||
private static final ResourceId DIMENSION = ResourceId.parse("pack:dimension/overworld");
|
||||
@@ -136,18 +136,18 @@ class ChunkPipelineTest {
|
||||
@Test
|
||||
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
|
||||
var vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, -60));
|
||||
var vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, 4));
|
||||
int reach = loaded.mantle().stages().getFirst().reachBlocks(new DeclaredSettings(vein));
|
||||
assertEquals(3, reach, "a 12 block vein from the centre column runs 3 blocks into the next chunk");
|
||||
var mantle = new MemoryMantle();
|
||||
var reachArea = new BlockBox(-reach, MIN_Y, -reach, CHUNK + reach, MAX_Y, CHUNK + reach);
|
||||
var reachArea = new BlockBox(-reach, BOTTOM, -reach, CHUNK + reach, TOP, CHUNK + reach);
|
||||
|
||||
new MantleRunner(loaded.mantle()).generate(VeinModule.PLAN,
|
||||
TestContexts.mantle(0, 0, ColumnSettings.everywhere(vein), mantle.within(reachArea)), TestContexts.SEED);
|
||||
assertEquals(1, mantle.get(VeinModule.ORE, 18, -60, 7), "the vein runs on into the next chunk");
|
||||
assertEquals(1, mantle.get(VeinModule.ORE, 18, 4, 7), "the vein runs on into the next chunk");
|
||||
|
||||
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR);
|
||||
var chunkArea = new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK);
|
||||
var chunkArea = new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK);
|
||||
new ChunkRunner(loaded.chunk()).generate(
|
||||
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
|
||||
assertEquals(VeinModule.ORE_BLOCK, blocks.get(7, 4, 7));
|
||||
@@ -167,7 +167,7 @@ class ChunkPipelineTest {
|
||||
};
|
||||
var builder = new StageGraphBuilder();
|
||||
builder.install(DiscoveredModule.builtIn(module));
|
||||
var inputs = TestContexts.generation(Map.of(), ColumnSettings.NONE, mantle.within(new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK)));
|
||||
var inputs = TestContexts.generation(Map.of(), ColumnSettings.NONE, mantle.within(new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK)));
|
||||
|
||||
var failure = assertThrows(UnsupportedOperationException.class,
|
||||
() -> new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(inputs, TestContexts.SEED));
|
||||
|
||||
@@ -71,10 +71,10 @@ public final class VeinModule implements IrisModule {
|
||||
|
||||
private static void place(ChunkStageContext context) {
|
||||
var blocks = context.hunk(BlockState.class);
|
||||
var chunk = new BlockBox(context.originX(), context.originY(), context.originZ(),
|
||||
context.originX() + blocks.getWidth(), context.originY() + blocks.getHeight(), context.originZ() + blocks.getDepth());
|
||||
var chunk = new BlockBox(context.originX(), 0, context.originZ(),
|
||||
context.originX() + blocks.getWidth(), blocks.getHeight(), context.originZ() + blocks.getDepth());
|
||||
context.mantle().layer(ORE).visit(chunk, (x, y, z, planned) ->
|
||||
blocks.set(x - context.originX(), y - context.originY(), z - context.originZ(), ORE_BLOCK));
|
||||
blocks.set(x - context.originX(), y, z - context.originZ(), ORE_BLOCK));
|
||||
}
|
||||
|
||||
private static final class IntegerCodec implements MantleCodec<Integer> {
|
||||
|
||||
@@ -11,8 +11,8 @@ public final class VeinSettings implements IrisFeature {
|
||||
@Desc("Blocks along X, starting at the chunk's centre column")
|
||||
private int length = 12;
|
||||
|
||||
@Desc("World height of the vein")
|
||||
private int y = -60;
|
||||
@Desc("Height of the vein above the dimension's bottom")
|
||||
private int y = 4;
|
||||
|
||||
public VeinSettings() {}
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MantleValueTest {
|
||||
@Test
|
||||
void boundsUseWorldCoordinatesAndExclusiveMaximum() {
|
||||
var box = new BlockBox(-16, -64, -16, 16, 320, 16);
|
||||
assertTrue(box.contains(-16, -64, -16));
|
||||
assertTrue(box.contains(15, 319, 15));
|
||||
void boundsUseWorldXZHeightsAboveTheBottomAndExclusiveMaximum() {
|
||||
var box = new BlockBox(-16, 0, -16, 16, 384, 16);
|
||||
assertTrue(box.contains(-16, 0, -16));
|
||||
assertTrue(box.contains(15, 383, 15));
|
||||
assertFalse(box.contains(16, 0, 0));
|
||||
assertFalse(box.contains(0, 320, 0));
|
||||
assertFalse(box.contains(0, 384, 0));
|
||||
assertFalse(box.contains(0, 0, 16));
|
||||
assertFalse(box.contains(0, -65, 0));
|
||||
assertFalse(box.contains(0, -1, 0));
|
||||
assertTrue(box.contains(box));
|
||||
assertTrue(box.contains(new BlockBox(0, 0, 0, 1, 1, 1)));
|
||||
assertFalse(box.contains(new BlockBox(-17, 0, 0, 1, 1, 1)));
|
||||
@@ -26,7 +26,7 @@ class MantleValueTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> new BlockBox(0, 1, 0, 1, 0, 1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BlockBox(0, 0, 1, 1, 1, 0));
|
||||
assertFalse(new BlockBox(0, 0, 0, 0, 0, 0).contains(0, 0, 0));
|
||||
var extremes = new BlockBox(Integer.MIN_VALUE, -64, 0, Integer.MAX_VALUE, 320, 1);
|
||||
var extremes = new BlockBox(Integer.MIN_VALUE, 0, 0, Integer.MAX_VALUE, 384, 1);
|
||||
assertTrue(extremes.contains(Integer.MIN_VALUE, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ public final class TestContexts {
|
||||
public static GenerationContext generation(Map<Class<?>, Hunk<?>> hunks, FeatureSettings settings, Mantle mantle) {
|
||||
return new GenerationContext() {
|
||||
public int originX() { return 0; }
|
||||
public int originY() { return -64; }
|
||||
public int originZ() { return 0; }
|
||||
public long worldSeed() { return SEED; }
|
||||
public PackResources resources() { throw new AssertionError("Unused resources"); }
|
||||
|
||||
Reference in new issue
Block a user