20 May 2024 - A Peek into Modding
<<< Previous Post
Next Post >>>
A lot of the modding API is inspired by that of Minecraft Forge. As it is designed now, all objects in the game go through the StarRegistries
class internally (including modded assets).
The Registry System
Registries are basically the same as Forge's Deferred Registry system, with the following exceptions:
- Registration is done explicitly by the modder, there is no event.
- The game does not have an event bus like Forge does
- There is an attribute which can be attached to static classes to initialize them immediately.
- Registry access is done manually and requires a reference to your own mod.
Otherwise, systems are roughly the same:
IRegistry<T>
allows mods to ask for the ability to register, returning...IRegistryAccess<T>
, which allows mods to register objects under an ID that works basically the same as (and has the same rules as)ResourceLocation
from Minecraftnamespace:entry
, which returns...IRegistryObject<T>
, which holds a reference to an object that will exist after registries are locked in (after the game has loaded to the main menu). This intermediary object can be passed around to other code to preemptively have a reference to the final object as soon as it is available.
Minecraft's Tag<T>
type also has an analogue in my game, for agnostic object handling.
Asset Loading
Mods load assets a bit like resource packs. Mods can override other mods' stuff, to an extent, however the game actually empowers developers to choose when (and if) that occurs - even potentially several ways at once for the same asset!
To do this, I have extended Godot's local path system (res://...
and user://...
are the built in local paths) to include several new ones. Most importantly is asset://<modid>/...
which loads the override asset, that is, if two mods declare a file at the same location, the one that loads last will override all previous mods. This will return that override.
But sometimes, you need an asset that you made and you can't allow changes. That's fine. Just use mod://<modid>
instead of asset://<modid>
to explicitly tell the game that you want the version from that specific mod.
Assets accept a modid
parameter so that assets can be namespaced, i.e. overriding asset://vanilla/somefile.txt
in another mod is possible.