Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ private boolean step() {
if (this.subLevelSplits.containsKey(p2.asLong())) {
final int otherIndex = this.splitIndexMap.getInt(this.subLevelSplits.get(p2.asLong()));
if (currentIndex != otherIndex) {
// two different floodfills have collided, sacrifice the index mapping of the other one
this.splitIndexMap.set(this.subLevelSplits.get(p2.asLong()), currentIndex);
// two different floodfills have collided, sacrifice the index mapping of the other one.

// Redirect every index that resolves to the other flood, not only the one stored at p2.
// Blocks of that flood can carry an older index that already pointed to it, and would
// otherwise stay behind and be split off as their own sub-level.
for (int i = 0; i < this.splitIndexMap.size(); i++) {
if (this.splitIndexMap.getInt(i) == otherIndex) {
this.splitIndexMap.set(i, currentIndex);
}
}
}
}
if (this.heatMapContains(p2)) {
Expand Down Expand Up @@ -195,6 +203,15 @@ private boolean step() {
}

private void split() {
// A position can be cleared into a flood and then become air before the split runs.
// Counting it would make a group look bigger than the blocks it still has,
// so the whole-sublevel checks below fail against solidCount and the whole sublevel gets remade
for (final Iterator<Long> it = this.subLevelSplits.keySet().iterator(); it.hasNext(); ) {
if (!this.isSolidAt(BlockPos.of(it.next()))) {
it.remove();
}
}

final Int2ObjectMap<List<BlockPos>> newSubLevelBlocks = new Int2ObjectOpenHashMap<>();
for (final long l : this.subLevelSplits.keySet()) {
final int splitIndex = this.splitIndexMap.get(this.subLevelSplits.get(l));
Expand Down Expand Up @@ -256,14 +273,18 @@ private void rebuildHeatmapFrom(final List<BlockPos> blocks) {

this.initialized = false;
this.splitComplete = false;
this.solidCount = 0;

this.newStarts.clear();
this.floodfill.clear();
this.removed.clear();

blocks.forEach(this::heatMapRemove);

// Only the heat is rebuilt, the blocks stay, so keep the count. The groups split off after this
// still subtract their blocks when they move out, so resetting it here would count them out twice.
final int solidCount = this.solidCount;
blocks.forEach(this::onSolidAdded);
this.solidCount = solidCount;
}

private boolean isSolidAt(final BlockPos blockPos) {
Expand Down