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
- Chest window: 5.1 Implementation in Dragonfly: opening an entity chest window with a packet hook
- Modal forms: 6.3 Dragonfly-side constraints: the private-method constraint of
form.Custom - multiselect: sending a row
form.Customcannot hold as a raw packet - Server-driven DDUI guide: 4. Packets: intercepting DDUI packets by wrapping the listener
- HUD item icons: the setup that carries the runtime ID in the title
- Resource pack delivery: the setting that forces packs and pack processing
- Fake blocks and chunks: blocks and chunks sent to one player only
- Camera and input: hooks for screen operations aimed at one player
- Custom items and blocks: blocks and items defined in server code
- Crafting data: per-player recipe locking
- Protocol basics: join measurements and the blob cache
- Server performance: Dragonfly threading
- Particles: Spawning particles from the Script API: the custom server
SpawnParticleEffectitem (that item does not name Dragonfly)
Layers
| Layer | What it does |
|---|---|
| Dragonfly patch | Dragonfly's behavior itself (block rules, storage, ticks, chunk transfer, world hooks) |
| Packet hook layer | Hooks 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 layer | Components added to the item and block entries the client receives at join. It uses only public registries and knows nothing about the game |
| Game | Items 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 behavior | Result | How to fix |
|---|---|---|
| When a session ends due to a packet handling error, it only leaves a Debug log and disconnects silently | The cause is hard to find | Write 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 caught | An error in one world stops the whole server | Catch 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 changed | If the same chunk has no other change, the contents of chests, barrels, hoppers and furnaces are not saved | Add 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 Activate | An item put into a block that takes the hand item inside Activate is duplicated | Reread the hand item after Activate and subtract |
Even when a block Activate succeeds, surrounding blocks are not resent | A block the client placed by prediction remains as a ghost | Resend the surrounding blocks after a successful Activate |
| A real client does not send the break action even after finishing cracking a custom block | The custom block does not break | The 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 state | Planting gives an instantly fully grown crop | Drop a new item with growth 0 |
| It takes the ingredients of the recipe the client picked regardless of slot position | A shaped recipe can be crafted in any arrangement | Reject 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 list | The client recipe book lists a recipe only when the result matches the creative entry, so some recipes do not show | Send 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 light | Grass survives and spreads even under custom solid blocks that do not block light | If 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 candidate | A 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 exposed | Add 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 VoxelShapes | A 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 is | First 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 undone | Return 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 reloaded | Have 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.
- The player handler gets it first. Cancelling ends it there.
- The clicked block's
Activate(block.Activatable). Skipped when the player sneaks while holding an item. - If
Activatereturns false, the held item'sUseOnBlock(item.UsableOnBlock). - 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/Closesave everything). - Encode palette entry NBT once per runtime ID and reuse it. Upstream palette NBT encoding is not deterministic (map order), so skipping
Putby byte comparison below needs this cache first{code}. - Skip
Putto 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}.
| Benchmark | Upstream | Fork |
|---|---|---|
| Tick of 5,000 block entities | 6.92 ms (4,670 allocs) | 3.29 ms (161 allocs) |
| Tick range for 450 loaders and 600 chunks | 6.30 ms | 3.22 ms |
| Disk encoding of 24 subchunks | 116 us | 27 us |
| Re-saving 100 unchanged columns | 11.8 ms, 11.7 MB | 4.9 ms, 3.5 MB |
| Subchunk entry with 2 viewers | 4,249 ns | 7 ns (cache hit) |
| Sending recipes | 6,173 ns | 1,859 ns |
| id | Source | License | Commit | Accessed |
|---|---|---|---|---|
private-research | Private research (-) | - | 2026-11-13 | |
dragonfly | Dragonfly (df-mc) | MIT | d86aefd (baseline of a patch for one Dragonfly-based server) | 2026-11-13 |
gophertunnel | gophertunnel (Sandertv) | MIT (c) 2019 Sandertv | e2251a6 | 2026-11-13 |