-
Notifications
You must be signed in to change notification settings - Fork 135
How World Downloader works
World Downloader may seem like a complex mod, but the base functionality is relatively simple.
World Downloader's main function is, of course, downloading worlds. Well, it's fairly simple. When the mod is downloading, it detects when a chunk is being unloaded, and then saves that chunk to disk. This results in the world being saved as the player moves around. When the player stops downloading, WDL has to do something slightly more complicated, as there is no simple way of grabbing all of the loaded chunks (it's a private
variable, and we can't just grab it by name due to Minecraft's obfuscation). Thus, WDL has to look through the map of all loaded chunks, and save each one.
To handle editing and dealing with additional data, custom save logic is used, but it's more or less the vanilla save code with modifications to swap out entities and tile entities with the correct ones.
However, just calling saveChunk
doesn't do everything. Most tile entities, for example chests, do not get sent with the chunk data. Thus, it is needed to grab the data when the chest is shown to us. Opening the chest's GUI while looking at it serves this purpose, as we can get the chest's items from the GUI. The same thing applies to some entities, such as minecart chests and horses.
World Downloader also saves map items -- the ones you can hold in your hand or put in item frames. This is done by listening for the packet that contains the map's image, and then storing that data for later use. When the download is stopped, the modified maps are saved to disk in the world data folder.
While entity saving sounds like it would be simple, it's actually a pain because of the was that Minecraft sends the entities, or more precisely, unsends them. This unsending generally happens far before the chunk is unloaded, and the distance varies by entity. WDL can listen to the "Remove entity from world" event, but there's another complication: that event provides no way of telling whether the entity was unloaded or was killed.
Thus, WDL uses the entity's distance from the player to determine if it needs to be saved. However, there's another complication to it. The ranges vary based off of the server's configuration! While vanilla minecraft doesn't change it, spigot allows configuration, and also has a completely different set of ranges. Thus, WDL has to listen to the server's brand (which is always sent for debug reasons) and determine the ranges off of that.
After WDL has determined if an entity should be saved, it is stored for when the chunk is written to disk. When the chunk is being written, the entities are reloaded, saved, and then unloaded. The entities are also returned to their server positions (in case they drifted).
Resources:
- Official forum thread for the World Downloader mod for Minecraft 1.16.1, 1.15.2, 1.14.4, 1.13.2, 1.12.2, 1.11.2, 1.10.2, 1.9.4, and 1.8.9
- Wiki index
- Issue tracker
World Downloader is licensed under the MMPLv2.
Various screens that are used in the mod
- Backup GUI
- Entities GUI
- Generator options GUI
- Messages GUI
- Multiworld GUIs
- Player overrides GUI
- World overrides GUI
Information on how World Downloader achieves various things, both technically and practically