Mods for NeoForge and Fabric
Mod system
A mod is a plugin that adds content the client has to know, such as blocks, items, entities and menus, so players install it alongside NeoForge or Fabric. Obsidian's mod system is modelled on NeoForge's.
Principles
- Familiar, but Obsidian's own. Close to NeoForge, designed for Obsidian. What loaders share (the wire protocol,
vanilla's data formats, the common
c:tags) is followed exactly. - One API, both sides. Obsidian.API doesn't depend on the server, and a plugin's
sidesays where it runs. - NeoForge and Fabric clients. Players join with the matching mod; vanilla clients join when no mod needs content they lack.
- Reloadable. A plugin reloads or unloads while the server runs, and players resynchronise instead of being disconnected.
How the protocol and reloads work
- NeoForge clients negotiate channels and synchronise registries with NeoForge's configuration-phase handshake;
Fabric clients use the common
c:versionandc:registerchannels and Fabric API's registry sync. The Obsidian client speaks NeoForge's protocol. - The server implements Obsidian.API; a client (the Obsidian client, or another) implements the client-facing parts, which are interfaces only. NeoForge-only formats, like its biome modifiers, have Obsidian equivalents.
- Where NeoForge freezes its registries, Obsidian separates identity from behaviour. The server owns identity: an
identifier like
ruby:ruby_blockkeeps its numeric id for the life of the process, across reloads, and saves store identifiers, not numeric ids. The plugin owns behaviour (handlers, block and item logic, codecs), and all of it is removed when the plugin unloads. When the channels or content change, players go back through the configuration phase to resynchronise.
Porting from NeoForge
Obsidian.Porting, a console tool in this repository, converts a NeoForge mod's data and metadata to Obsidian's
formats: its neoforge/biome_modifier files to Obsidian's biome modifiers and its neoforge.mods.toml to
obsidian.mod.json, copying the data and assets in vanilla's formats and reporting what has no Obsidian equivalent.
A mod's Java code can't be converted. See porting-from-neoforge.md.
What host services add
Besides IPluginRegistry, plugins add to the server through its services. Unloading undoes that too, so a reloaded
plugin starts clean.
Each plugin gets its own IServer and ILevelFactory: injected, from its services, or given to OnLoadedAsync and
OnServerReadyAsync. What a plugin adds through them is its own, whichever code makes the call (a library it uses,
say). While its code runs (event handlers, commands, payload handlers, behaviours and goals), e.Server, command and
payload contexts and IClient.Server also give the plugin's own instance.
When a plugin unloads:
- recipes it registered with
IServer.RegisterRecipesstop matching and leave players' recipe books; registered again, they come back under the same ids (see Recipes). Its server-side recipe types and their recipes go too; - its scoreboards and boss bars are removed from players' screens and their names are free again. Changing or showing
them afterwards throws
InvalidOperationException; - generators it registered with
ILevelFactory.RegisterGeneratorare removed, and levels using them stop until it registers them again.IPluginRegistry.RegisterGeneratorstays the preferred way; - its dialogs (
DialogRegistry.Register,DialogBuilder.Register), event handlers and commands are removed; - server players it added with
IServer.AddServerPlayerAsyncleave, as other players do; - entities it spawned are removed from their levels, without events or any of its code running. Item drops (from
SpawnItem,DestroyBlockandBlockBreakContext.ExtraDrops) belong to the server and stay.
Entities of a plugin's own entity types are removed too, whoever spawned them. Unlike vanilla, which drops entities of unknown types, Obsidian keeps them in their chunk's saved entities, and they spawn again once the plugin loads again.
Adding to an unloading plugin (dialogs, recipes, scoreboards, boss bars, generators, handlers, commands, server players
or entities) throws InvalidOperationException. An entity of an unloaded plugin's type isn't added to a level:
TryAddEntity returns false.
Next
Blocks and items, entities and the client cover content that needs a mod on the player's side; plugin archives covers building and packing one.