Allow zone region function to accept the Region
This allows the function to make use of relevant facets to define the
zone's region.
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.BiFunction;
import java.util.function.Function;
@API
private final List<WorldRasterizer> rasterizers = new ArrayList<>();
//TODO: add entity providers
- Function<BaseVector3i, Boolean> regionFunction;
+ private final BiFunction<BaseVector3i, Region, Boolean> regionFunction;
- public Zone(Function<BaseVector3i, Boolean> regionFunction) {
+ public Zone(BiFunction<BaseVector3i, Region, Boolean> regionFunction) {
this.regionFunction = regionFunction;
}
+ public Zone(Function<BaseVector3i, Boolean> regionFunction) {
+ this.regionFunction = (pos, region) -> regionFunction.apply(pos);
+ }
+
@Override
public void setSeed(long seed) {
facetProviders.forEach(fp -> fp.setSeed(seed));
@@ -66,7 +71,7 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) {
Map<BaseVector3i, Block> savedBlocks = new HashMap<>();
ChunkBlockIterator iterator = chunk.getBlockIterator();
while (iterator.next()) {
- if (!containsBlock(iterator.getBlockPos())) {
+ if (!containsBlock(iterator.getBlockPos(), chunkRegion)) {
Block block = chunk.getBlock(ChunkMath.calcBlockPos(iterator.getBlockPos()));
savedBlocks.put(ChunkMath.calcBlockPos(iterator.getBlockPos()), block);
}
@@ -95,7 +100,7 @@ public Zone addRasterizer(WorldRasterizer rasterizer) {
return rasterizers;
}
- public boolean containsBlock(BaseVector3i worldPos) {
- return regionFunction.apply(worldPos);
+ public boolean containsBlock(BaseVector3i worldPos, Region chunkRegion) {
+ return regionFunction.apply(worldPos, chunkRegion);
}
}
