Skip to content

fix: don't publish the motion of an abandoned sub-level collision pass - #1685

Open
Vonix-Network wants to merge 1 commit into
ryanhcode:mainfrom
Vonix-Network:fix/sub-level-collision-bounds-guard
Open

Vonix-Network wants to merge 1 commit into
ryanhcode:mainfrom
Vonix-Network:fix/sub-level-collision-bounds-guard

Conversation

@Vonix-Network

Copy link
Copy Markdown

What this fixes

An oversized sub-level collision pass is skipped, but the motion that made it oversized is still returned to the caller — which then hands vanilla block collision a swept AABB spanning millions of blocks. The collision iterator never finishes and the server tick never completes. continue protects Sable's own loop and nothing else.

Root cause

SubLevelEntityCollision.collide builds the region it will walk in five steps:

  1. take the entity's box swept from where it was to where it is going (fullContextBounds);
  2. inverse-transform it into the sub-level's frame at its previous pose → localBounds;
  3. inverse-transform it again at its current pose → localBounds2;
  4. union the two;
  5. walk every block position in the union, up to four times over.

Steps 2 and 3 are the same entity, in the same tick, seen from two frames a substep apart. Each half is therefore roughly the size of the entity. When the two poses are far apart, though, the union spans the gap between them, and its volume stops describing either the ship or the entity.

The existing guard catches that:

if (localBounds.volume() > 500 * 500 * 500) {
    Sable.LOGGER.info("Enormous local sub-level collision bounds, quitting.");
    continue;
}

The continue skips the block walk — but collisionInfo.motion is left untouched. Back in Entity.collide, sable$collideRedirect returns that CollisionInfo, and the caller does what vanilla always does with a motion: aabb.expandTowards(motion). So the enormous motion is turned straight back into an enormous swept AABB and handed to Level.getBlockCollisions / BlockCollisions. For a motion of this magnitude that iterator is effectively unbounded, and the tick never returns.

This is a permanent wedge, not a slow tick: the vanilla server watchdog kills the server, and mods that replace the block-collision iterator (Lithium's ChunkAwareBlockCollisionSweeper, which has no volume cap of its own) show the same non-terminating walk with a different frame in the stack.

The change

Two hunks, one file each, no behavioural change on any path that is not already being abandoned.

Narrow the union before testing it. Only the union is ever enormous. If it exceeds the existing ceiling, fall back to localBounds2 — the current-pose box — and test that instead.

if (localBounds.expandTo(localBounds2, localBounds).volume() > SubLevelCollisionConstants.MAX_LOCAL_COLLISION_VOLUME) {
    localBounds.set(localBounds2);
}

Collision against where the sub-level actually is keeps working. What is given up is the sweep back to where it used to be, which is the tunnelling protection across a fast rotation. Trading some tunnelling for a wedged server is the right trade at this ceiling.

Stop the pass when even the current-pose box is oversized. Replace the continue with a return that zeroes the motion:

if (localBounds.volume() > SubLevelCollisionConstants.MAX_LOCAL_COLLISION_VOLUME) {
    Sable.LOGGER.info("Enormous local sub-level collision bounds, quitting.");
    collisionInfo.motion = Vec3.ZERO;
    return collisionInfo;
}

Returning the motion zeroed is the honest result rather than a workaround, because at this point nothing has happened yet:

  • collisionMotion is declared outside the loop and only accumulated inside the walk below (collisionMotion.fma(...) per substep), so it is still zero at the guard.
  • The entity position is not touched until inside the walk (sable$setPosSuperRaw for the tracking case), which is below the guard. There is no partial state to unwind.
  • The fields this path leaves unset — inheritedMotion and firstCollisions — are null-guarded by both consumers (LivingEntityMixin.sable$beforeAnimation and EntityMixin's TAIL inject), so an early return is consumed exactly like the non-intersecting early return already in the method.

The entity does not move for that pass. That is strictly better than moving by millions of blocks.

The 500^3 value is unchanged; it is now named MAX_LOCAL_COLLISION_VOLUME in SubLevelCollisionConstants, alongside the other collision tuning constants, because it is referenced twice.

Verification

  • :common:compileJava on this branch: BUILD SUCCESSFUL (Gradle 9.5.0, JDK 21, NeoForm 1.21.1-20240808.144430). Base commit 9b1a3d15 = main at time of writing.
  • git diff --name-only: exactly the two files above; 27 insertions, 3 deletions.
  • The defect and the fix were reproduced and measured against real Sable 2.0.6 on a live dedicated NeoForge 21.1.265 server, using the same swept AABB from the reports below — see the evidence links.

Evidence

Companion mod (server-side containment while this lands, and the reproduction harness): https://github.com/Vonix-Network/sable-collision-guard

  • Full diagnosis, with the log timeline, the abort bounds, and the watchdog tick growth: docs/DIAGNOSIS.md
  • A/B control — a throwaway probe that ships no fix, driving the real block-collision sweep with the real swept AABB from the incident:
  • Real-world bounds from the incident: AABB[1815.55, 67.0, -1.620864198436978E7] -> [2.1967152361004844E7, 9698766.05, -6001.80], i.e. ~2.2e7 blocks of extent, logged 4,291 times.

Related issues

I am listing #1667 and #1607 with the distinction rather than as fixes, because a maintainer should not have to check whether a four-line collision guard really closes a teleport-coordinate bug.

Scope

  • Nothing outside SubLevelEntityCollision.collide and one constant is touched.
  • No Minecraft class is modified. No other mod is accommodated.
  • The Lithium sweeper cap is not in this PR. It is the companion's second safety net — it caps the block-collision iterator itself so that any future oversized sweep is bounded even if it comes from a path this patch does not cover. It belongs in a mod that owns that iterator, not in Sable.
  • I did not change the ceiling value. Whether 500^3 is the right number is a separate question from whether an abandoned pass should publish its motion, and mixing them would make this PR harder to review.

Suggested follow-up (not done here)

fullContextBounds is built from the entity's motion before the pose union is computed, so an absurd motion also enlarges considerationBounds and the set of sub-levels tested. The pose-union narrowing above means such a pass is now abandoned cheaply, but clamping the motion on entry would avoid the work entirely. That is a behaviour change for fast-moving entities and does not belong in a bugfix PR.

@CLAassistant

CLAassistant commented Nov 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Vonix-Network
Vonix-Network force-pushed the fix/sub-level-collision-bounds-guard branch from 0c9ce21 to 42f1f30 Compare November 25, 2026 04:28
…lla collision

`SubLevelEntityCollision.collide` builds the block region it walks by inverse
transforming the entity's swept box into the sub-level's frame at its previous
pose and at its current pose, then unioning the two. When those poses are far
apart the union spans the gap between them and stops describing anything real:
the ship and the entity are both small, the gap is not.

Two changes to that point:

1. Narrow the union before testing it. Only the union is ever enormous -- each
   half is roughly the size of the entity, because that is what it is, the same
   box seen from two frames a substep apart. If the union exceeds the existing
   volume ceiling, fall back to the current-pose box. Collision against where
   the sub-level actually is keeps working; what is dropped is the sweep back to
   where it used to be, which is the tunnelling protection across a fast
   rotation.

2. When even the current-pose box exceeds the ceiling, stop the pass instead of
   only skipping the walk. The previous `continue` left `collisionInfo.motion`
   untouched, so the caller -- `Entity.collide` via `sable$collideRedirect` --
   went on to expand the entity box by that same motion and hand the result to
   vanilla block collision. For a motion of the magnitude that produced an
   enormous region in the first place, that swept AABB spans millions of blocks
   and the collision iterator never finishes, which is a permanently wedged
   server tick rather than a slow one.

   Nothing has been collided at this point: `collisionMotion` is only
   accumulated inside the walk below, and the entity position is not touched
   until inside it either. Returning the motion zeroed is therefore the honest
   result -- the entity does not move this pass.

The existing 500^3 ceiling is unchanged in value, now named in
SubLevelCollisionConstants alongside the other collision tuning constants.

Not changed: the ceiling itself, the substep loop, the per-block SAT, tracking,
stepping, and both early returns for players and for non-intersecting cases.
@Vonix-Network
Vonix-Network force-pushed the fix/sub-level-collision-bounds-guard branch from 42f1f30 to 26e44df Compare November 25, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants