From 5cba07a155f123a06d789d13c9a9367cb36e070b Mon Sep 17 00:00:00 2001 From: Alex Guha <33240894+Alex-Guha@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:51:09 -0700 Subject: [PATCH 1/3] fix: merged floods can still be split apart When the root of a sublevel is broken, floods that meet do not necessarily tell each other who they've already met. If we have floods A, B, and C: 1) A can meet B 2) C can meet A 3) B only knows about A, not C. So at the end, we get two separate sublevels, in this example. --- .../sublevel/plot/heat/SubLevelHeatMapManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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..a51904b73 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)) { From 5dcc53e8439e221ac64add93468118d0140b709e Mon Sep 17 00:00:00 2001 From: Alex Guha <33240894+Alex-Guha@users.noreply.github.com> Date: Thu, 3 Dec 2026 22:33:32 -0700 Subject: [PATCH 2/3] fix: blocks that are gone still get counted in floods, causing sublevels to get remade This can happen when a block the flood already reached breaks before the split runs, or when blocks are broken in the same tick as a load, before the first fill finishes. --- .../sable/sublevel/plot/heat/SubLevelHeatMapManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 a51904b73..04902f988 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 @@ -203,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)); From f92db19ea28cd9e429b8fa2949edb946698d5a8c Mon Sep 17 00:00:00 2001 From: Alex Guha <33240894+Alex-Guha@users.noreply.github.com> Date: Thu, 3 Dec 2026 22:50:43 -0700 Subject: [PATCH 3/3] fix: solidCount can be wrong after a split rebuildHeatmapFrom reset the count and then the part that split off also gets subtracted, and so the count thinks the ship is smaller than it is. Later, if/when the root breaks, the check fails and the ship is rebuilt as a new sublevel. --- .../sable/sublevel/plot/heat/SubLevelHeatMapManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 04902f988..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 @@ -273,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) {