diff --git a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/heat/SubLevelHeatMapManager.java b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/heat/SubLevelHeatMapManager.java index 6816fda13..2a44ce695 100644 --- a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/heat/SubLevelHeatMapManager.java +++ b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/heat/SubLevelHeatMapManager.java @@ -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)) { @@ -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 it = this.subLevelSplits.keySet().iterator(); it.hasNext(); ) { + if (!this.isSolidAt(BlockPos.of(it.next()))) { + it.remove(); + } + } + final Int2ObjectMap> newSubLevelBlocks = new Int2ObjectOpenHashMap<>(); for (final long l : this.subLevelSplits.keySet()) { final int splitIndex = this.splitIndexMap.get(this.subLevelSplits.get(l)); @@ -256,14 +273,18 @@ private void rebuildHeatmapFrom(final List 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) {