Fix fillHeight

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-08 15:08:40 +02:00
parent b8b850fca1
commit 30aa3ac8f3
2 changed files with 40 additions and 6 deletions

View File

@ -366,7 +366,7 @@ final class GeneratorImpl {
final boolean endOffset = maxMultiple != maxHeight;
if (startOffset || endOffset) {
final int firstFill = Math.min(minMultiple + 16, maxHeight);
final int lastFill = floorSection(maxHeight);
final int lastFill = startOffset ? Math.max(firstFill, floorSection(maxHeight)) : floorSection(maxHeight);
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
final int sectionX = startX + x * 16;

View File

@ -53,15 +53,49 @@ public class GeneratorIntegrationTest {
public void fillHeightNegative(Env env) {
var manager = env.process().instance();
var instance = manager.createInstanceContainer();
instance.setGenerator(unit -> {
unit.modifier().fillHeight(-64, -60, Block.STONE);
});
instance.setGenerator(unit -> unit.modifier().fillHeight(-64, -60, Block.STONE));
instance.loadChunk(0, 0).join();
for (int y = -64; y < -60; y++) {
assertEquals(Block.STONE, instance.getBlock(0, y, 0));
assertEquals(Block.STONE, instance.getBlock(0, y, 0), "y=" + y);
}
for (int y = -60; y < 100; y++) {
assertEquals(Block.AIR, instance.getBlock(0, y, 0));
assertEquals(Block.AIR, instance.getBlock(0, y, 0), "y=" + y);
}
}
@Test
public void fillHeightSingleSectionFull(Env env) {
var manager = env.process().instance();
var instance = manager.createInstanceContainer();
instance.setGenerator(unit -> unit.modifier().fillHeight(0, 16, Block.GRASS_BLOCK));
instance.loadChunk(0, 0).join();
for (int y = 0; y < 16; y++) {
assertEquals(Block.GRASS_BLOCK, instance.getBlock(0, y, 0), "y=" + y);
}
}
@Test
public void fillHeightSingleSection(Env env) {
var manager = env.process().instance();
var instance = manager.createInstanceContainer();
instance.setGenerator(unit -> unit.modifier().fillHeight(4, 5, Block.GRASS_BLOCK));
instance.loadChunk(0, 0).join();
for (int y = 0; y < 5; y++) {
assertEquals(y == 4 ? Block.GRASS_BLOCK : Block.AIR, instance.getBlock(0, y, 0), "y=" + y);
}
}
@Test
public void fillHeightOverride(Env env) {
var manager = env.process().instance();
var instance = manager.createInstanceContainer();
instance.setGenerator(unit -> {
unit.modifier().fillHeight(0, 39, Block.GRASS_BLOCK);
unit.modifier().fillHeight(39, 40, Block.STONE);
});
instance.loadChunk(0, 0).join();
for (int y = 0; y < 40; y++) {
assertEquals(y == 39 ? Block.STONE : Block.GRASS_BLOCK, instance.getBlock(0, y, 0), "y=" + y);
}
}
}