For a long time, one of the most important things to us in this game has been Mod Support. Since this is a pixel art game with pretty simply structured content, it would be rather silly not to allow players to easily extend the game with their own custom content. We want to have this system completely integrated with the game while maintaining blazing fast loading speeds (well, as fast as java can get). I’ve been working on some pretty cool features over the last couple days dealing with the mod support so I figured I’d go ahead and share what’s been going on! Here are my basic requirements for the mod support for the game:

A player can have as many mods loaded at a time as they want, without conflicts

A mod can add new items, scrolls, and objects to the game, or overwrite existing ones

A player can add and remove mods to an existing save game

A mod creator can update their mod, and no existing save games with that mod will become corrupted or get new conflicts

Load in all of the objects in the game

Load in all of the objects for each mod, overwriting old objects with the same name

Assign each object a unique short ID (allowing for 65536 objects)

Save the map of ID-Object pairs to a file in the save directory

Load in all of the objects for the game

Read which mods are being used in the save file

Load in all of the objects for each of the mods used in the save game

Load the map of ID-Objects pairs from the file

Check if any of the Objects in the map have been removed from the game, if so mark them as removed

Check if there are any new objects in the game, in which case give them new unique IDs and append them to the map

In order to successfully accomplish this I need to trade off some of the conveniences of static object IDs. Each save game will have to store it’s own list of IDs for all of the objects, which will increase the size of each save game, but will allow for much more flexibility with modding and updating. The current system for starting a new game with mods is as follows:I’m also going to need some special functionality for loading in save games:Another minor down-side to this method is when a player is joining an online server, the server will first have to send the object maps before sending over the world and game data. However, the map tends to be much smaller than the world and game data is anyways, so it doesn’t seem to be a huge deal. There’s only been one more lingering issue with allowing this much direct mod support into the game: packing the texture sheets. As I’ve said in a previous post, I take all of the textures in the game and pack them into one large texture sheet to increase drawing speed. That’s not very special though, as almost every pixel art game, or even 2d game in general does this. I want to have it so the mods get packed in with all the game’s other textures. Before, I had it so the game packs all the game’s textures together, along with the mod’s textures, when the game loads. This takes about an extra 6 seconds of loading at the moment, and it’s only going to get longer as the game gets bigger. In order to fix this problem, I’ve decided to cache all the most popular mod combinations on the user’s system. When you start a game with a combination of mods, it will still have to pack all the textures together on the first time it loads, however it will cache all of those packed textures on the file system in a folder. Right now, I’m taking the current version of the game, then appending all of the mods and their versions being used, and then hashing the result to get the folder to store the cache in. This way, if the same combination of mods and versions are being used it can easily find the folder where the cache should be. I know there is a possibility for hash collisions, but the probably is so low that this will happen, and it’s just going to be pretty funny if it ever does (and you can fix the problem by deleting the cache folders).Now, when the game is loading, it can check if there is a cache for all the mods being used and just load the cache in, which only takes a fraction of a second.