Skip to main content

Dragonfly server notes: forks, hooks, upstream behavior

Concept​

Dragonfly (df-mc, Go, MIT) is a library for building Bedrock server software in Go. It handles the protocol on top of gophertunnel. There are two ways to change Dragonfly's behavior: fork Dragonfly and patch it, or attach hooks to packets and sessions without a fork. The upstream behavior on this page is based on Dragonfly master 1bf4e242 (after v0.11.5, 2026-10-24) plus the 1.26.60 support PR (gophertunnel v1.63.0), commit d86aefd9ff9b6a357d6dfadab2093af811545256. (Source: private research)

Dragonfly content on other pages​

Layers​

LayerWhat it does
Dragonfly patchDragonfly's behavior itself (block rules, storage, ticks, chunk transfer, world hooks)
Packet hook layerHooks that reach sessions and packets. It intercepts and modifies the packets the server sends to the client and uses the session's private methods and fields. Dragonfly internals are touched only here
Client entry layerComponents added to the item and block entries the client receives at join. It uses only public registries and knows nothing about the game
GameItems and blocks implement the interfaces of the client entry layer

Try them from top to bottom. If the job can be done by intercepting packets or reading and writing session internals, put it in the packet hook layer. If it only adds client-side components, put it in the client entry layer. Patch only when Dragonfly's behavior itself must change, or when you cannot prove that a patch-free approach gives the same result. Mark patched places with a patch marker comment and update the patch list with it.

What to do with hooks, without a fork​

Jobs that only intercept packets or read and write session internals use the bedrock-gophers/inv approach: a packet hook in a connection that wraps the listener, go:linkname for the session's private methods, and reflection for private fields. The entity chest and screen operations sent to a single player (camera, field of view, HUD hiding, input locks, fake blocks, chunk center, titles) work this way. A single test that checks the internals the hooks expect by name shows right away what breaks after you upgrade Dragonfly.

What goes in patches​

  • Work inside Dragonfly such as storage, the chunk cache, tick performance, and panic recovery of world transactions.
  • Adding hooks where none exist (changing hopper transfer rules, notification after a block changes, column load and unload notifications).
  • Work you can verify only on a real client: chunks visible to one player only, resend after Activate, server-side breaking of custom blocks, the grass spread check.
  • Work you cannot prove gives the same result: block rules (composter, leaves), the NetherNet listener address, per-player recipe filters, chunks per tick while loading.

Client data verification​

Keep a test that starts the server the same way as a real run, connects a fake client once, hashes each received block entry, item registration, crafting data and creative list entry, and compares them with a golden file. If the golden stays the same after you change a patch or upgrade Dragonfly, the data the client receives is the same. Besides item ids, keep golden entries written by item name. The id of a custom item is its registration order, so even a change of package initialization order changes hundreds of lines in an id-based golden, while a name-based golden stays the same.

A change that moves client data or modifies a patch must leave the golden unchanged. Re-record the golden only for a change meant to alter what the client receives. If the code that reads entries meets a shape different from what it expects, have it panic with the block name, so the problem is caught here first after a Dragonfly upgrade.

Upstream behavior and how to fix it​

Upstream behaviorResultHow to fix
When a session ends due to a packet handling error, it only leaves a Debug log and disconnects silentlyThe cause is hard to findWrite an ERROR log and send a Disconnect with the reason
A panic in a world transaction (block ticks, event and packet handlers) kills the process. Only Do/DoAfter jobs are caughtAn error in one world stops the whole serverCatch the panic in transaction execution, log it at ERROR with the stack, and keep the world running
Inventory changes do not mark the chunk as changedIf the same chunk has no other change, the contents of chests, barrels, hoppers and furnaces are not savedAdd a function that only marks a loaded column as changed (no packets or neighbor updates) and call it from each container's Inventory(tx, pos) and from the Tick of a lit furnace
The hand item read before a block Activate is written back after ActivateAn item put into a block that takes the hand item inside Activate is duplicatedReread the hand item after Activate and subtract
Even when a block Activate succeeds, surrounding blocks are not resentA block the client placed by prediction remains as a ghostResend the surrounding blocks after a successful Activate
A real client does not send the break action even after finishing cracking a custom blockThe custom block does not breakThe server breaks it itself once the break time passes. While the same block keeps being mined (ContinueDestroyBlock repeating), keep the start time
The crop and seeds dropped when harvesting a fully grown crop copy the fully grown statePlanting gives an instantly fully grown cropDrop a new item with growth 0
It takes the ingredients of the recipe the client picked regardless of slot positionA shaped recipe can be crafted in any arrangementReject if the items in the crafting grid do not match the recipe shape (anywhere inside the grid, mirrored only when allowed). For recipes that forbid mirroring, send AssumeSymmetry=false to the client
The result block state in vanilla recipe data (chest orientation and so on) can differ from the creative listThe client recipe book lists a recipe only when the result matches the creative entry, so some recipes do not showSend the recipe result's block runtime ID equal to the item's creative entry (when there is only one entry)
Grass and mycelium spread (spreadDirt) looks only at lightGrass survives and spreads even under custom solid blocks that do not block lightIf a full solid block (model.Solid) is above, turn the grass back into dirt and do not let it spread from such dirt (same as vanilla)
There is no setting to choose separately the local address to bind the NetherNet listener to and the public address to announce. The listener offers every interface address as an ICE candidateA server behind 1:1 NAT or a tunnel announces an address that does not fit. Behind a tunnel, players cannot reach those candidates and the host's own addresses are exposedAdd a local address (one address to bind and announce) and a public address (announced in place of the local address) to the listener config, and offer only those addresses as candidates {code}
It does not send VoxelShapesA 1.26 client logs that the shape list is missing {measured}Send the basic shapes minecraft:empty and minecraft:unit_cube at join
It sends no entity properties (no SyncActorProperty, no AddActor.EntityProperties) {code}PlayerUpdateEntityOverrides, which overrides an entity's int, float, bool or enum client property per player, cannot be used as isFirst build property definition sync, property values when an entity is added, and render controllers using query.property in the resource pack. Text (name tags) cannot be a property
When Use of an item.Usable returns true, the hand item read before Use is written back {code}Changes Use made to the held item are undoneReturn false from a Use that edits the held item
HandleBlockBreak carries no face {code}Breaking cannot be blocked on only one face of a block (for example its front)Record per player the face last hit in Punch(pos, face, tx, user) of block.Punchable, and cancel the break when that face is the front
Entities are saved with the world {code}Display entities the server spawned come back after the world is reloadedHave the display entity delete itself in Tick when its block is gone or the session does not know it, and respawn it when the column loads. A non-saved entity type from the optimizations below also works
gophertunnel closes the connection when one batch holds too many packets (maximumInBatch)A fake client that sent 861 SubChunkRequest in one batch was disconnected with no log {measured}The fake client sends 64 per tick
gophertunnel's decoder looks up the compression algorithm of each received batch by its ID and drops the connection when the result is not the connection's configured compression {code}Replacing the Flate compression with a level-configurable implementation without registering it cut every client off at Login, over both RakNet and NetherNet {measured}Register the replacement under the Flate ID with packet.RegisterCompression and use the same value as the server config Compression

Click dispatch order {code}​

When a block is clicked, Dragonfly handles it in this order.

  1. The player handler gets it first. Cancelling ends it there.
  2. The clicked block's Activate (block.Activatable). Skipped when the player sneaks while holding an item.
  3. If Activate returns false, the held item's UseOnBlock (item.UsableOnBlock).
  4. If neither applies, the held block is placed.

Clicking the air calls the held item's Use. The client sends air-use packets only for items it knows are usable, so a custom item needs minecraft:use_modifiers in its client entry for Use to be called (custom-items-and-blocks.mdx). Punch (block.Punchable) cannot stop breaking. BreakInfo().BreakHandler runs after the block is removed, and also runs when explosions or liquids break it.

Item stack values {code}​

Values attached with item.Stack.WithValue are saved in the item NBT under dragonflyData, so they persist in player data, containers and other stored stacks. Stacks with different values count as different items and do not stack; equal values stack.

Optimizations to try in a fork​

  • Cache the list of chunks that are targets of random and block entity ticks, and recompute only when a loader is added, removed or moved, a chunk is added or deleted, or on SetTickRange (force a recompute every 100 ticks as a safety net). Reuse the block entity position buffer.
  • Incremental saving: save modified columns oldest first, up to 16 per second, to split up save stalls (Save/Close save everything).
  • Encode palette entry NBT once per runtime ID and reuse it. Upstream palette NBT encoding is not deterministic (map order), so skipping Put by byte comparison below needs this cache first {code}.
  • Skip Put to LevelDB when the value has not changed (per-key hash). Delete empty subchunks.
  • Cache subchunk network data per column version.
  • Build recipe and creative data once per block registry and share it. Upstream rebuilds the recipe entries on every send with a new RecipeID from uuid.New, so caching also needs a fixed RecipeID {code}.
  • When the client is receiving chunks, increase the number of chunks sent per tick (from 4 to 16).
  • Send weather packets only when the value changes.
  • Have a temporary entity type that is not saved, such as display entities, and do not mark the column as modified for those entities.

Values measured with go test -bench (2 s) on a fork with these optimizations {measured}.

BenchmarkUpstreamFork
Tick of 5,000 block entities6.92 ms (4,670 allocs)3.29 ms (161 allocs)
Tick range for 450 loaders and 600 chunks6.30 ms3.22 ms
Disk encoding of 24 subchunks116 us27 us
Re-saving 100 unchanged columns11.8 ms, 11.7 MB4.9 ms, 3.5 MB
Subchunk entry with 2 viewers4,249 ns7 ns (cache hit)
Sending recipes6,173 ns1,859 ns
Sources
idSourceLicenseCommitAccessed
private-researchPrivate research (-)-2026-11-13
dragonflyDragonfly (df-mc)MITd86aefd (baseline of a patch for one Dragonfly-based server)2026-11-13
gophertunnelgophertunnel (Sandertv)MIT (c) 2019 Sandertve2251a62026-11-13