Skip to content

API reference Obsidian.API.Client

IClientRegistry interface

What a mod's IClientPlugin.ConfigureClient registers its client side with.

public interface IClientRegistry

In Obsidian.API.Client.

Remarks

What the mod registers takes effect when IClientPlugin.ConfigureClient returns and stays until the client exits or the player reloads its mods; if it throws, none of it does. The registry is sealed then, since the client loads what depends on it afterwards: registering through it later throws InvalidOperationException, while IClientRegistry.Connection and IClientRegistry.Screens stay usable.

Like the server's content, what the mod registers is its own: identifiers are in its namespace (its mod id) and valid by vanilla's rules (lowercase letters, digits and _-./, one :).

Properties

Connection

IClientConnection Connection { get; }

The client's connection to the server it's playing on, to send the mod's payloads from outside a payload handler, like when one of its keys is pressed.

Screens

IClientScreens Screens { get; }

Opens the mod's screens, like a settings screen opened with one of its keys. Like IClientRegistry.Connection, it stays usable after IClientPlugin.ConfigureClient.

Sounds

IClientSounds Sounds { get; }

Local audio for this mod; usable after ConfigureClient returns, until the mod unloads.

Methods

HandlePayload<TPayload>(ClientPayloadHandler<TPayload>)

IClientRegistry HandlePayload<TPayload>(ClientPayloadHandler<TPayload> handler) where TPayload : ICustomPayload<TPayload>;

Handles the payloads the server sends on TPayload's channel, in the phases the mod declared it for with IPluginRegistry.MapPayload; the server's handler given there is the server's, and isn't called on the client.

OnTick(Action)

IClientRegistry OnTick(Action handler);

Runs handler on the game's thread every client tick, 20 times a second, in menus as in game, for the mod's own client logic, like polling IKeyBinding.IsDown. IClientRegistry.Connection's IClientConnection.Phase says whether the client is playing on a server. A handler that throws is logged and not run again.

RegisterBlockEntityModel(string, BlockEntityModelProperties)

IClientRegistry RegisterBlockEntityModel(string blockEntityType, BlockEntityModelProperties model);

Adds model parts from a block entity type's synced data to its blocks' models as the world is meshed, like cable connections and facades. A new update meshes the block again.

Parameters

blockEntityType
The identifier of a block entity type the mod registered, like examplemod:cable_bus.
model
The models the parts may name, and the provider choosing them.

RegisterBlockEntityRenderer(string, BlockEntityRendererProperties)

IClientRegistry RegisterBlockEntityRenderer(string blockEntityType, BlockEntityRendererProperties renderer);

Draws a block entity type's moving parts each frame, like vanilla's block entity renderers: parts its synced data describes, which the client animates, or code that draws them.

Parameters

blockEntityType
The identifier of a block entity type the mod registered, like examplemod:grinder.
renderer
The models the parts may name, and the provider or code drawing them.

RegisterBlockEntityShapes(string, Func<IReadOnlyDictionary<string, object>, BlockShapes>)

IClientRegistry RegisterBlockEntityShapes(string blockEntityType, Func<IReadOnlyDictionary<string, object>, BlockShapes> provider);

Supplies collision and outline shapes for a block entity type this mod registered. The provider receives its latest synced update tag as plain NBT values (nested compounds are dictionaries, lists are lists). Return null to use the block state's shapes. Runs at most once per snapshot on a reading thread: keep it pure and short, and do not mutate nested values. Registration is staged until ConfigureClient returns and removed when the mod unloads.

RegisterBlockTint(string, BlockTint)

IClientRegistry RegisterBlockTint(string block, BlockTint tint);

Tints a block: the faces of its models with a tintindex are multiplied by the tint's colour, and so are its item's when the item's definition (assets/<ns>/items/...) gives the model no tints of its own. Use BlockTint.FixedByIndex for a separate colour per tint index.

Parameters

block
The identifier of a block the mod registered, like examplemod:mossy_bricks.
tint
The tint.

RegisterDimensionEffects(string, DimensionEffectsProperties)

IClientRegistry RegisterDimensionEffects(string dimensionType, DimensionEffectsProperties effects);

Draws a mod's dimension type's clouds with its own texture, or adjusts and draws its sky, fog and clouds in code, beyond what the type's data says (see DimensionEffectsProperties).

Parameters

dimensionType
The identifier of a dimension type in the mod's namespace, like examplemod:skylands for the server's data/examplemod/dimension_type/skylands.json.
effects
The cloud texture, sky textures and code.

RegisterEntityRenderer(string, EntityRendererProperties)

IClientRegistry RegisterEntityRenderer(string entityType, EntityRendererProperties renderer);

Draws a mod's entity type with a model and texture from its assets. Without one, the type's entities aren't drawn.

Parameters

entityType
The identifier of an entity type the mod registered, like examplemod:golem.
renderer
The model and texture, and any layers and code.

RegisterItemCondition(string, Func<ItemStack, ItemModelContext, bool>)

IClientRegistry RegisterItemCondition(string property, Func<ItemStack, ItemModelContext, bool> condition);

Registers a property an item model definition's minecraft:condition model can test, like NeoForge's conditional item model properties: {"type":"minecraft:condition","property":"examplemod:charged", "on_true":...,"on_false":...}.

Parameters

property
The property's identifier, in the mod's namespace, like examplemod:charged.
condition
Whether the stack takes the on_true model.

Remarks

The property is a function of the stack, read-only with its components (including the mod's own, read with ItemStack.TryGet), and where it's drawn. It runs on the client's game thread inside a call into the mod, when a stack drawn with the definition changes, or its context does (a new tick, another holder or display context): its value is kept per stack and display context in between, so keep it pure. If it throws, the error is logged, and it's false for the stack until the stack changes.

Condition, select and range properties are separate, like vanilla's: one identifier can name one of each.

RegisterItemRange(string, Func<ItemStack, ItemModelContext, float>)

IClientRegistry RegisterItemRange(string property, Func<ItemStack, ItemModelContext, float> range);

Registers a property an item model definition's minecraft:range_dispatch model can choose by, like NeoForge's range item model properties: the value, times the model's scale, chooses the entry with the highest threshold at or below it, else the fallback.

Parameters

property
The property's identifier, in the mod's namespace, like examplemod:fill.
range
The stack's value.

Remarks

It runs, is kept and fails like IClientRegistry.RegisterItemCondition's properties; a failure gives 0.

RegisterItemRenderer(string, ItemRendererProperties)

IClientRegistry RegisterItemRenderer(string specialModelType, ItemRendererProperties renderer);

Draws a special item model type with code, like NeoForge's special model renderers: items whose definitions have a minecraft:special model of the type draw with the renderer in every display context.

Parameters

specialModelType
The type's identifier, in the mod's namespace, like examplemod:gem_display.
renderer
The models it may draw, and its code.

RegisterItemSelect(string, Func<ItemStack, ItemModelContext, string>)

IClientRegistry RegisterItemSelect(string property, Func<ItemStack, ItemModelContext, string> select);

Registers a property an item model definition's minecraft:select model can choose by, like NeoForge's select item model properties: the case whose when is the value (or lists it) is drawn, else the fallback.

Parameters

property
The property's identifier, in the mod's namespace, like examplemod:gem.
select
The stack's value, compared with the cases' when strings exactly; null for none.

Remarks

It runs, is kept and fails like IClientRegistry.RegisterItemCondition's properties; a failure, or null, chooses the fallback.

RegisterItemTooltip(string, Action<ItemStack, IList<string>>)

IClientRegistry RegisterItemTooltip(string item, Action<ItemStack, IList<string>> lines);

Registers lines a mod's item adds to its tooltip under its name, like an item's appendHoverText in NeoForge: a storage cell's fill, say, read from its components.

Parameters

item
The item, one of the mod's, like examplemod:battery.
lines
Adds the stack's lines to the list it's given.

Remarks

The lines take vanilla's legacy § formatting codes, like Widget.Tooltip; start a line with §7 for vanilla's grey. They're asked for each time the tooltip is drawn, on the client's game thread inside a call into the mod, so keep it short and pure. If it throws, the error is logged and the tooltip shows none of its lines.

RegisterKeyBinding(string, string, string)

IKeyBinding RegisterKeyBinding(string identifier, string defaultKey, string category);

Registers a key binding, listed in the key binds screen under its category and saved in options.txt like vanilla's.

Parameters

identifier
The binding's identifier, in the mod's namespace, like examplemod:open_map; its name, and translation key, is key.examplemod.open_map.
defaultKey
The key or mouse button it's bound to until the player rebinds it, in vanilla's names: key.keyboard.g, key.keyboard.left.alt, key.mouse.middle, or key.keyboard.unknown for none.
category
The category's identifier, like examplemod:main, in any namespace so mods can share one; its translation key is key.category.examplemod.main.

RegisterMenuScreen(string, Func<IScreenMenu, ModMenuScreen>)

IClientRegistry RegisterMenuScreen(string menuType, Func<IScreenMenu, ModMenuScreen> screen);

Shows a mod's menu type with a screen built in code: screen makes one for the menu each time the server opens it, for the widgets its ModScreen.Init adds. Use it rather than MenuScreenProperties for a menu with more than slots on a background: progress, buttons, text fields, lists.

Parameters

menuType
The identifier of a menu type the mod registered, like examplemod:grinder.
screen
Makes the screen for an opened menu.

RegisterMenuScreen(string, MenuScreenProperties)

IClientRegistry RegisterMenuScreen(string menuType, MenuScreenProperties screen);

Shows a mod's menu type with a background and slot positions from its assets. Without a screen, the menu shows like a chest.

Parameters

menuType
The identifier of a menu type the mod registered, like examplemod:pouch.
screen
The background and where the slots go.

RegisterMenuScreen<TComponent>(string)

IClientRegistry RegisterMenuScreen<TComponent>(string menuType) where TComponent : ModComponent;

Shows a mod's menu type with a screen built in Razor: the client renders TComponent in the menu's container screen each time the server opens the menu, with the menu in its ScreenContext. It's the Razor form of IClientRegistry.RegisterMenuScreen, hosted the same way.

Type parameters

TComponent
The screen's component.

Parameters

menuType
The identifier of a menu type the mod registered, like examplemod:grinder.

RegisterOverlay(ModOverlay)

IClientRegistry RegisterOverlay(ModOverlay overlay);

Draws an overlay on the HUD, like a minimap or a mana bar, from when IClientPlugin.ConfigureClient returns until the mod unloads; its ModOverlay.Tick updates it while the player is in a world.

Parameters

overlay
The overlay, with the widgets it draws.

RegisterParticleProvider(string, ParticleProviderProperties)

IClientRegistry RegisterParticleProvider(string particleType, ParticleProviderProperties provider);

Sets how a mod's particle type's particles move and how long they live. They're drawn with the sprites of its definition, assets/<ns>/particles/<name>.json, with or without a provider.

Parameters

particleType
The identifier of a particle type the mod registered, like examplemod:spark.
provider
How its particles move and live.

On this page