-
Notifications
You must be signed in to change notification settings - Fork 56
Codec Utilities
Codecs for the things pack authors actually write, and for surviving their mistakes.
Vanilla codecs are strict: one bad field and the whole file fails to load, usually with an unhelpful
message. Most of CodecUtils exists to make datapack facing formats forgiving, and to accept the
shorthand forms people expect ("a single item where a list is declared", "an id string instead of an
object").
These log a warning and fall back to a default instead of failing the whole file:
CodecUtils.lenientWithLog(SomeCodec, "field_name", defaultValue)
CodecUtils.lenientListCodec(elementCodec) // bad entries are skipped, not fatal
CodecUtils.lenientUnboundedMap(keyCodec, valueCodec)
CodecUtils.lenientHomogeneousList(Registries.BLOCK) // ids that don't exist are droppedUse them wherever a pack, rather than your own code, provides the file.
| Helper | Accepts |
|---|---|
singleOrList(codec) / lenientListOrSingleCodec
|
One element or a list of them |
ITEM_OR_STACK |
An item id or a full stack |
ITEMSTACK_OR_LIST_OR_HOLDER_SET |
A stack, a list, or a tag |
optionalRegistryCodec(registry, default) |
A registry id, falling back if it's missing |
alias(codec, "name", "old_name") |
Two field names for the same thing, for renames |
remapNamespaceCodec(reg, old, new) |
Ids whose namespace moved |
alternatives(a, b, c) / bestAlternative(...)
|
Several formats for one value, picking the one that parses |
AABB_CODEC, VEC2F
|
The geometry ones vanilla doesn't have |
MOD_LOADED_CODEC reads a mod id and gives you whether it's installed, useful for conditional
entries.
PostProcessCodecs runs a validation or fixup step after decoding. UnionCodec merges two decoded
objects into one. EitherLeftCodec and AlternativeCodec handle either-shaped values.
BiggerCodecs and BiggerStreamCodecs extend the record builder past vanilla's arity limit, which
you hit surprisingly fast on config objects.
CodecMapRegistry and StreamCodecMapRegistry are small registries keyed by id, for dispatch
codecs. RegistryAccessJsonReloadListener is the base for a reload listener that needs registry
access, which is how the trades and map markers files are loaded.
For codecs that also describe an editable form (used by the config screen), see
codecui's SchemaCodec, which Moonlight bundles.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder