Skip to main content

Registries and Data Tables

MiXianTu has two kinds of registries. Built-in registries hold the MapCodec implementations that a datapack selects with the type field, and are populated in Java code. Dynamic data tables are native datapack registries whose entries live in JSON files, are reloaded with the datapack and are synchronised to the client by the registry system.

Built-In Type Registries

Built-in registries use NeoForge's DeferredRegister<MapCodec<?>>, and a datapack is dispatched to the matching implementation through type:

public static final DeferredRegister<MapCodec<? extends Cost>> REGISTRY =
DeferredRegister.create(MxtRegistries.COST_TYPE, MiXianTu.MOD_ID);

The registry instances are declared in MxtRegistries, and their keys are declared once in MxtResourceKeys:

RegistryKeyContents
MxtRegistries.ABILITY_TYPEmxt:ability_typeAbility type codecs.
MxtRegistries.ABILITY_TARGET_SELECTOR_TYPEmxt:ability_target_selector_typeAbility target selector codecs.
MxtRegistries.COST_TYPEmxt:cost_typeCost type codecs.
MxtRegistries.CURSE_TYPEmxt:curse_typeCurse type codecs.
MxtRegistries.ABILITY_COMPONENT_TYPEmxt:ability_component_typeAbility component codecs.
MxtRegistries.TRIGGER_TYPEmxt:trigger_typeAbility trigger codecs.
MxtRegistries.NUMBER_PROVIDER_TYPEmxt:number_provider_typeNumber provider codecs.
MxtRegistries.AURA_MAXIMUM_TYPEmxt:aura_maximum_typeAura maximum codecs.
MxtRegistries.FORMULA_FUNCTIONmxt:formula_functionFormula functions available to expressions.
MxtRegistries.FORMULA_VARIABLEmxt:formula_variableFormula variables injected by the runtime.
MxtRegistries.RESOURCE_VALUE_PROVIDER_TYPEmxt:resource_value_provider_typeResource value provider codecs.
MxtRegistries.ENTITY_ACTION_TYPEmxt:entity_action_typeEntity action codecs.
MxtRegistries.BI_ENTITY_ACTION_TYPEmxt:bi_entity_action_typeBi-entity action codecs.
MxtRegistries.BLOCK_ACTION_TYPEmxt:block_action_typeBlock action codecs.
MxtRegistries.ITEM_ACTION_TYPEmxt:item_action_typeItem action codecs.
MxtRegistries.ENTITY_CONDITION_TYPEmxt:entity_condition_typeEntity condition codecs.
MxtRegistries.BI_ENTITY_CONDITION_TYPEmxt:bi_entity_condition_typeBi-entity condition codecs.
MxtRegistries.BLOCK_CONDITION_TYPEmxt:block_condition_typeBlock condition codecs.
MxtRegistries.ITEM_CONDITION_TYPEmxt:item_condition_typeItem condition codecs.
MxtRegistries.DAMAGE_CONDITION_TYPEmxt:damage_condition_typeDamage condition codecs.
MxtRegistries.RESOURCE_BAR_RENDER_DATA_TYPEmxt:resource_bar_render_data_typeResource bar render data codecs.
MxtRegistries.RESOURCE_BAR_CONTEXTmxt:resource_bar_contextResource bar contexts.
MxtRegistries.RESOURCE_BAR_VISIBILITY_TYPEmxt:resource_bar_visibility_typeResource bar visibility codecs.
MxtRegistries.BADGE_TYPEmxt:badge_typeBadge codecs.
MxtRegistries.ITEM_MATCHER_ENTRY_TYPEmxt:item_matcher_entry_typeItem matcher entry codecs.

The built-in types are grouped and registered by classes such as MxtEntityActions, MxtBiEntityActions, MxtBlockActions, MxtItemActions and MxtEntityConditions. Registering a new built-in type means providing a MapCodec and adding it to the matching DeferredRegister; a datapack reload never adds entries to these registries.

These registries are open to other mods: a third-party module may add its own codecs to any of them — the built-in trigger table documents this explicitly — and the new type ids then become available to datapacks.

Dynamic Data Tables

Every table the mod declares is listed — with its file directory, its purpose and every field — in JSON Data Formats. An addon normally adds entries to those tables rather than new tables.

Reading Data Tables

MxtDatapackRegistries is the supported entry point for both the server and the synchronised client copy. Every read skips entries that carry the mod's mxt:disabled tag.

MemberDescription
registries()Every registry key owned by the mod, in registration order.
get(key, id) / get(key, holder)Reads an enabled value by ID or by holder.
holder(key, id)Resolves an enabled entry while keeping its stable holder reference.
holders(key)Streams all enabled entries of a registry.
holders(access, key) / holders(provider, key)Streams enabled entries from a RegistryAccess or a HolderLookup.Provider, which is how the client reads the synchronised copy.
isDisabled(key, id) / isDisabled(key, holder)Checks whether an entry carries the mxt:disabled tag.
isTagged(key, id, tagId) / isTagged(key, holder, tagId)Checks a native datapack tag on one entry.
size(key) / registry(key)The underlying Registry; only available while a server is running.
note

registry(key) and size(key) throw an IllegalStateException when no server is running. On the client, use the holders(access, key) and get(access, key, id) overloads that take the synchronised lookup instead.

Codecs

A definition class exposes two codecs. CODEC reads and writes a Holder<Definition> reference and is what a field or another JSON file uses to point at a definition; DIRECT_CODEC reads and writes the whole object and is what a datapack registry uses for the entry itself. Read DIRECT_CODEC when you need the values of a definition, for example Resource.DIRECT_CODEC or Badge.DIRECT_CODEC.