Skip to content

Commit 45297a9

Browse files
committed
Protect sub-levels splitting producing sub-levels with zero mass
1 parent 85eb0f0 commit 45297a9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

common/src/main/java/dev/ryanhcode/sable/sublevel/plot/heat/SubLevelHeatMapManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import dev.ryanhcode.sable.SableConfig;
44
import dev.ryanhcode.sable.api.SubLevelAssemblyHelper;
5+
import dev.ryanhcode.sable.api.sublevel.SubLevelContainer;
56
import dev.ryanhcode.sable.companion.math.BoundingBox3i;
67
import dev.ryanhcode.sable.companion.math.BoundingBox3ic;
78
import dev.ryanhcode.sable.sublevel.ServerSubLevel;
89
import dev.ryanhcode.sable.sublevel.plot.HeatDataChunkSection;
910
import dev.ryanhcode.sable.sublevel.plot.LevelPlot;
1011
import dev.ryanhcode.sable.sublevel.plot.PlotChunkHolder;
12+
import dev.ryanhcode.sable.sublevel.storage.SubLevelRemovalReason;
1113
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
1214
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
1315
import it.unimi.dsi.fastutil.ints.IntArrayList;
@@ -237,7 +239,15 @@ private void split() {
237239
listener.addBlocks(level, bounds, blocks);
238240
}
239241

240-
SubLevelAssemblyHelper.assembleBlocks((ServerLevel) level, blocks.get(0), blocks, bounds);
242+
final ServerSubLevel subLevel = SubLevelAssemblyHelper.assembleBlocks((ServerLevel) level, blocks.get(0), blocks, bounds);
243+
244+
// Protect against split sub-levels that have zero mass.
245+
if (subLevel.getMassTracker().getCenterOfMass() == null || subLevel.getMassTracker().getMass() <= 0.0) {
246+
subLevel.getPlot().destroyAllBlocks();
247+
248+
final SubLevelContainer container = Objects.requireNonNull(SubLevelContainer.getContainer(level));
249+
container.removeSubLevel(subLevel, SubLevelRemovalReason.REMOVED);
250+
}
241251
}
242252
}
243253

0 commit comments

Comments
 (0)