mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 04:41:13 +00:00
cleanup biome config loading
This commit is contained in:
@@ -3,9 +3,11 @@ package com.dfsek.terra.biome.pipeline;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.biome.pipeline.stages.SeededBuilder;
|
||||
import com.dfsek.terra.biome.pipeline.stages.Stage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomePipeline {
|
||||
private final BiomeSource source;
|
||||
@@ -40,7 +42,7 @@ public class BiomePipeline {
|
||||
|
||||
public static final class BiomePipelineBuilder {
|
||||
private final int init;
|
||||
List<Stage> stages = new GlueList<>();
|
||||
List<SeededBuilder<Stage>> stages = new GlueList<>();
|
||||
private int expand;
|
||||
|
||||
public BiomePipelineBuilder(int init) {
|
||||
@@ -48,13 +50,18 @@ public class BiomePipeline {
|
||||
expand = init;
|
||||
}
|
||||
|
||||
public BiomePipeline build(BiomeSource source) {
|
||||
return new BiomePipeline(source, stages, expand, init);
|
||||
public BiomePipeline build(BiomeSource source, long seed) {
|
||||
List<Stage> stagesBuilt = stages.stream().map(stageBuilder -> stageBuilder.build(seed)).collect(Collectors.toList());
|
||||
|
||||
for(Stage stage : stagesBuilt) {
|
||||
if(stage.isExpansion()) expand = expand * 2 - 1;
|
||||
}
|
||||
|
||||
return new BiomePipeline(source, stagesBuilt, expand, init);
|
||||
}
|
||||
|
||||
public BiomePipelineBuilder addStage(Stage stage) {
|
||||
public BiomePipelineBuilder addStage(SeededBuilder<Stage> stage) {
|
||||
stages.add(stage);
|
||||
if(stage.isExpansion()) expand = expand * 2 - 1;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.biome.pipeline.stages;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SeededBuilder<T> {
|
||||
private final Function<Long, T> builder;
|
||||
|
||||
public SeededBuilder(Function<Long, T> builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public T build(long seed) {
|
||||
return builder.apply(seed);
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ public interface Stage {
|
||||
boolean isExpansion();
|
||||
|
||||
BiomeHolder apply(BiomeHolder in);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user