Skip to content

Commit

Permalink
clean up worldgen code & allow access of selection by generator
Browse files Browse the repository at this point in the history
accessing a selection by generator will allow a generator to directly
access its own selection, allowing for generators that are compliant
with multi-generation so that less overhead is present
  • Loading branch information
Pixaurora committed Aug 30, 2023
1 parent e2511c0 commit 633ab3f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Binary file removed __pycache__/random.cpython-311.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package net.pixaurora.janerator.worldgen;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import net.minecraft.world.level.chunk.ChunkGenerator;
import net.pixaurora.janerator.graphing.Coordinate;
Expand All @@ -9,7 +13,7 @@
public class GeneratorLookup {
private List<ChunkGenerator> generatorMap;

private List<PlacementSelection> selections;
private Map<ChunkGenerator, PlacementSelection> selections;
private ChunkGenerator fallbackGenerator;

public GeneratorLookup(
Expand All @@ -21,8 +25,8 @@ public GeneratorLookup(
.stream()
.distinct()
.map(generator -> new PlacementSelection(generator, GraphingUtils.getIndices(this.generatorMap, generator)))
.toList();
this.fallbackGenerator = this.selections
.collect(Collectors.toMap(PlacementSelection::getUsedGenerator, Function.identity()));
this.fallbackGenerator = this.getAllSelections()
.stream()
.max((selection1, selection2) -> selection1.size() - selection2.size())
.get().getUsedGenerator();
Expand All @@ -36,8 +40,16 @@ public ChunkGenerator getAt(Coordinate coordinate) {
return this.generatorMap.get(coordinate.toListIndex());
}

public List<PlacementSelection> getAllSelections() {
return this.selections;
public Collection<PlacementSelection> getAllSelections() {
return this.selections.values();
}

public PlacementSelection getSelection(ChunkGenerator generator) {
if (! this.selections.containsKey(generator)) {
throw new RuntimeException("No selection found associated with this generator.");
}

return this.selections.get(generator);
}

public ChunkGenerator getDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

public class PlacementSelection {
private ChunkGenerator generator;
private List<Integer> placements;
private List<Coordinate> placements;

public PlacementSelection(ChunkGenerator generator, List<Coordinate> placements) {
this.generator = generator;
this.placements = placements
.stream()
.map(Coordinate::toListIndex)
.toList();
this.placements = placements;
}

public boolean contains(int x, int z) {
return this.placements.contains(
new Coordinate(x, z).toListIndex()
);
public List<Coordinate> getPlacements() {
return this.placements;
}

public ChunkGenerator getUsedGenerator() {
return this.generator;
}

public boolean contains(int x, int z) {
return this.placements.contains(
new Coordinate(x, z)
);
}

public int size() {
return this.placements.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public CompletableFuture<ChunkAccess> createBiomes(
);

return chunk;
});
},
executor
);
}

@Override
Expand Down

0 comments on commit 633ab3f

Please sign in to comment.