Skip to content

Conversation

@UnlimitedBytes
Copy link
Contributor

Summary

  • Fix ensureFullStatusChangeWithWriteLock using hasWriteLock instead of isCurrentlyTickingRegion to prevent infinite deferral loop
  • Fix foojay-resolver-convention for Gradle 9 compatibility
  • Improve task scheduling for player respawn

Details

The main fix addresses an issue where entities were not receiving onTickingStart callbacks because ensureFullStatusChangeWithWriteLock() was checking isCurrentlyTickingRegion() which only returns true inside the tick loop. Tasks scheduled via ShreddedPaper.runSync() run on the thread pool with a write lock but NOT inside the tick loop, causing the check to always fail and creating an infinite deferral loop.

The fix changes the check to use hasWriteLock() which correctly identifies when the thread has proper synchronization to modify chunk status.

Test plan

  • Tested breaking blocks in various regions
  • Tested item pickups
  • Tested falling sand becoming blocks
  • Verified no more infinite loop in logs

@UnlimitedBytes UnlimitedBytes force-pushed the ver/1.21.11 branch 2 times, most recently from 5de4441 to 867545a Compare January 5, 2026 19:52
@UnlimitedBytes UnlimitedBytes changed the title Fix entity ticking and other improvements [DRAFT] [DO NOT MERGE YET] Fix entity ticking and other improvements Jan 5, 2026
Apply scoreboard thread-safety as source patches instead of feature patch
Apply raid thread-safety as source patches instead of feature patch
Apply redstone torch thread-safety as source patch instead of feature patch
Apply entity activation optimization as source patch instead of feature patch
Apply item gravity optimization as source patch instead of feature patch
Execute scheduled tasks on the player's task scheduler during tick (e.g., packet handlers)
Sync patch context and naming conventions with upstream
These 12 patches have been verified as already integrated into the 1.21.11 codebase:

- 0026-Run-unsupported-plugins-in-sync (fully integrated)
- 0027-Thread-safe-AreaMap (superseded by Moonrise architecture)
- 0028-Threaded-chunk-changes-broadcasting (fully integrated)
- 0039-Thread-safe-redstoneUpdateInfos (fully integrated)
- 0040-Thread-safe-chunksBeingWorkedOn (superseded by Moonrise)
- 0048-Synchronize-playersSentChunkTo (fully integrated)
- 0056-Don-t-allow-actions-outside-of-our-region (fully integrated)
- 0061-Optimization-Use-lazyExecute-if-we-aren-t-flushing (fully integrated)
- 0069-Optimization-Load-chunk-before-joining-player (fully integrated)
- 0071-Fix-Concurrent-modification-when-removing-player (fully integrated)
- X0016-EntityLookup-accessibleEntities (fully integrated)
- X0055-Moving-into-another-region (fully integrated)
These patches cannot be applied to 1.21.11:

- X0017-World-gen: Marked as obsolete, functionality refactored
- X0019-Multithreaded-WeakSeqLock: Target class (WeakSeqLock) doesn't exist in 1.21.11
- X0036-Entity-retirement-debug-log: Debug/experimental patch, no longer needed
- 0058-Fix-EntityRemoveEventTest: Depends on Pufferfish optimization that doesn't exist
Adds thread safety checks to CraftServer.createWorld() to ensure worlds
are only loaded from the global scheduler tick thread, not from async
or region tick threads.
Adds thread safety checks to CraftChunk, CraftWorld, and CraftBlock to
ensure chunk and block operations are only performed from the correct
region tick thread:
- CraftChunk.getHandle(): Check region ownership
- CraftWorld.getChunkAt(): Check region ownership
- CraftBlock: getNMS(), getData(), getType(), setBlockState() ensure
  tick thread for block position
Most changes from the original patch were already applied. This ports
the remaining null safety check for this.server in PaperEventManager
callEvent() to prevent NPE during early initialization.
Adds ReentrantLock-based thread safety to TrackedEntity's seenBy set
operations in ChunkMap to prevent ConcurrentModificationException when
multiple threads access entity tracking data.
Adds tracker update frequency optimization and maximum trackers per entity limit.
Adds thread synchronization for command block output updates.
Adds event calls for packet broadcasting in ChunkMap, ServerLevel, and PlayerList.
Adds asynchronous writing for player save data to improve performance.
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