Fix empty fork

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-14 01:32:54 +02:00
parent 3371de9556
commit 821063addf
2 changed files with 21 additions and 1 deletions

View File

@ -184,10 +184,12 @@ final class GeneratorImpl {
public void fork(@NotNull Consumer<Block.@NotNull Setter> consumer) {
DynamicFork dynamicFork = new DynamicFork();
consumer.accept(dynamicFork);
final Point startSection = dynamicFork.minSection;
if (startSection == null)
return; // No block has been placed
final int width = dynamicFork.width;
final int height = dynamicFork.height;
final int depth = dynamicFork.depth;
final Point startSection = dynamicFork.minSection;
final List<GenerationUnit> sections = dynamicFork.sections;
registerFork(startSection, sections, width, height, depth);
}

View File

@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@ -15,6 +16,23 @@ import static org.junit.jupiter.api.Assertions.assertNull;
@EnvTest
public class GeneratorForkConsumerIntegrationTest {
@Test
public void empty(Env env) {
var manager = env.process().instance();
var instance = manager.createInstanceContainer();
AtomicReference<Exception> failed = new AtomicReference<>();
instance.setGenerator(unit -> {
try {
unit.fork(setter -> {
});
} catch (Exception e) {
failed.set(e);
}
});
instance.loadChunk(0, 0).join();
assertNull(failed.get(), "Failed: " + failed.get());
}
@Test
public void local(Env env) {
var manager = env.process().instance();