Open source
Patching the Minecraft server itself with SportPaper
Patches to SportPaper and Magnet, the Paper server forks behind Stratus, Walrus and Avicus, from faster chunk unloading to a live knockback command.
- ~25server patches
- 200+GitHub stars on SportPaper
- O(1)chunk unload removal, was linear
The problem
Competitive Minecraft networks run an old version of the game for its combat, and the stock server for that version is slow and missing APIs a network needs. The fix is to fork the server, but you can’t commit to decompiled game code directly. The changes live as an ordered stack of patches applied on top of it.
What I built
Around 25 patches across the three forks, including:
- Faster chunk unloading: the unload queue became a hash set, so removing a chunk is constant time, and the removal moved to after the chunk loads
- Worlds that keep ticking when they’re empty, when
tickEmptyWorldsis on, and start on load - A knockback command that changes the knockback settings live and can reset them, so we could tune combat without restarts
- New APIs: unregistering commands, components personalized per viewer, locale and translatable components, fast block changes, disconnect reasons, and potion effect reasons
- Crash fixes, like a
CraftChunk#getBlocksNPE and a stack overflow when adding recipes
- Upstreamfetch, remap, decompile
- Base repoinit
- git amapi, then server patches
- BuildMaven + paperclip
- Rebuildcommits back into patches
The build and two of the patches
./sportpaper build:
git submodule update; remap(mc.jar); decompile(); init()
for dir in [api, server]:
git reset --hard upstream
for patch in sorted(patches/dir): git am --3way patch
mvn install; paperclip -> server.jar
# speed up chunk unloading
unload_queue = LongOpenHashSet()
fn get_chunk_at(x, z):
chunk = load(x, z)
unload_queue.remove(key(x, z)) # O(1), and only once the chunk is there
return chunk
# always tick worlds when asked to
should_tick = config.tick_empty_worlds or world.has_players()
Why it matters
When the server is the bottleneck, plugin code can only do so much. Patching the server let us fix the problem where it actually was.