Typed Content: from declaration to protocol
This page describes the implemented native Go Content API with startup publication, rather than future proposal features.
On this page
Overview
This page describes the implemented native Go Content API with startup publication, rather than future proposal features. A module author declares item/block semantics; Pulce validates resources, resolves references, and builds a representation for each enabled Bedrock protocol. Start with the Content API; see Content publication for commit and runtime behavior.
Model boundaries
| Layer | Main types | Responsibilities |
|---|---|---|
| Public module API | core/content.ItemDefinition, BlockDefinition, ItemID, BlockID; core/resources refs | ID, client label, aliases, geometry identifier, hardness, preferred tool, drop, associated item, creative category |
| Staging | internal/content.Scope, Batch, Owner | Snapshot of one module Load, local reservations, closing the registration window |
| Normalized model | internal/content.Snapshot, Item, Block | Resolved defaults, expanded block item, validated references, concrete mining profile |
| Bedrock lowering | internal/content/bedrock.Prepared, Projection, ItemPayload, CreativeMenu | Components, legacy specs, default-state palette inputs, and menus for each protocol |
| Publication | core/server.PublishPlan, private publishedContent | Complete registry entries, allocated IDs, combined palettes, server ownership, gameplay overlay |
| Session / wire | runtime.PublishedContent, pinned bedrockWire, ProtocolNext packets/codecs | Frozen projection of the negotiated protocol; packet encoding and client IDs |
BlockSpec and ItemSpec remain physically public: the old registrar and behavior APIs use them. The new typed registrar accepts concrete semantic definitions only. Public specs do not make raw components necessary for an ordinary module. ProtocolNext does not import Pulce semantic definitions.
flowchart TD
P[Native module Load] --> S[Module-owned Scope]
S --> B[Seal successful Batch]
B --> N[Normalize all batches]
R[Enabled-stack resource Catalog] --> N
A[Authoritative registries] --> N
N --> L[Prepare per enabled protocol]
L --> C[PrepareContentPublication]
C --> F[Atomic startup Commit]
F --> W[Pin protocol projection before bootstrap]
W --> X[ProtocolNext encoding]
Public definitions and IDs
content.Item(id) and content.Block(id) return typed values. Fluent methods return copies of the same values; struct literals are available for generated declarations. Register copies mutable optional values and drop lists. Mutating the original definition after registration does not change staged content.
api, err := module.TypedContent(ctx)
if err != nil {
return err
}
if _, err := api.Items().Register(content.Item("example:token").
DisplayName("Token").Icon("token").StackSize(1)); err != nil {
return err
}
_, err = api.Blocks().Register(content.Block("example:stone").
DisplayName("Example Stone").Texture("example_stone").
Hardness(0.5).Tool(content.Pickaxe).DropsSelf().WithItem())
return err
A successful Register accepts the declaration; it does not immediately expose the block in a registry. Resource validation and protocol lowering can still reject startup.
ItemID and BlockID are distinct named string types. Passing a typed item ID to Places(BlockID) requires an explicit conversion. String literals remain convenient for declarations. TextureID denotes an atlas alias; item and terrain references use distinct resources.ItemTextureRef and BlockTextureRef types. GeometryID aliases resources.GeometryRef and denotes a logical geometry identifier, not a file path.
A registration ID has one namespace:path separator. The namespace and path segments allow a-z, 0-9, _, ., -. A path may contain /, but empty segments, . and .. are rejected. Validation does not fold case, add a namespace, or repair whitespace. The minecraft namespace is reserved for new typed definitions. Places and fixed drops may reference existing vanilla content.
ParseItemID, ParseBlockID, Validate, and UnmarshalText validate plugin registration IDs. Therefore, UnmarshalText for minecraft:stone is not a universal parser for vanilla references: internal reference validation uses a separate rule. This is a current API boundary to account for when reading configuration.
Defaults and explicit values
| Declaration | Normalization/lowering result |
|---|---|
| Display name omitted | OmittedName; no item display-name component; ID is not automatically converted into UI text |
DisplayName("...") | Literal item display-name component; an explicitly empty/whitespace-only string is an error |
| Hardness omitted | Current release's default full-block mining profile; currently 1.0, FromDefault=true |
Hardness(0) | Explicit instant break, FromDefault=false |
Hardness(0.5) | Explicit value without profile substitution |
| Geometry omitted | Builtin minecraft:geometry.full_block; no model file required |
| Texture | Required terrain alias for a simple block, one texture for all faces |
| Render method | Internal opaque; no typed choice of other modes yet |
| Tool omitted | No preferred tool; Tool(Pickaxe) affects mining speed without requiring a pickaxe for harvesting |
Drops omitted / NoDrops() | No drops |
| Block item omitted | No item generated |
WithItem() | Same textual ID in the separate item registry; stack size 64, placement of the block's default state |
| Item stack size omitted | 64; explicit values must be 1–64 |
| Creative omitted | Hidden, lowered category none/0 |
Hardness declarations store *float64, preserving omission independently of zero. Normalization runs once and carries the resolved value into all protocol projections. The public contract promises the host profile for omission, rather than a permanent 1.0 constant; an engine profile update can change gameplay across releases. Modules requiring stable behavior must declare explicit hardness. The profile is fixed in the snapshot during one startup.
The block label is retained in the normalized block model and inherited by an associated item when that item's label is omitted. Current block lowering does not generate minecraft:display_name for the block definition itself; item lowering supplies the ordinary block item's visible name. A label on a block without an item is therefore not a proven client-visible label.
Block/item relationship, drops, and mining
WithItemDefinition allows a separate item ID, literal label, item icon, stack size, and creative category. Omitted label/category inherit explicit block values; explicit Hidden hides the item even when the block declares a visible category. Creative(...) on a block without WithItem does not create an item or creative entry.
The generated block item receives its placement link and required Bedrock components below the public API. Without a separate icon, lowering enables the block as its icon. Item(...).Places(blockID) also works: the link is validated after collecting all IDs, including authoritative vanilla/legacy block definitions. It places one default state. State selection, multiple states per placer, use_on restrictions, and new typed callback behavior are not implemented.
DropsSelf() requires an associated block item and drops one of its ID, including an override ID. Drops(content.Drop{Item: ..., Count: ...}) supports one fixed output with a positive count and an existing item ID. The definition stores a list for future model growth, but normalization rejects more than one output as unsupported. Different explicit loot modes conflict at registration rather than silently replacing each other. Loot tables, callbacks, Fortune/Silk Touch, and conditional drops are not implemented typed features.
Pickaxe, Axe, Shovel, Hoe, and Shears are preferred mining families. Minimum tier, mandatory correct tool, and separate harvestability are absent from this model. The gameplay regression tests check breaking and self drop by hand, with faster mining using a wooden pickaxe. This does not promise complete loot/mining parity for every kind of custom block.
Resource catalog
module.Resources(ctx) supplies a read-only service with ResolveItemTexture, ResolveBlockTexture, and ResolveGeometry. Ordinary registration does not require manual resolve calls: requirements follow from Icon, Texture, and Geometry. The host supplies the catalog of the same authoritative enabled stack used in client pack negotiation. Legacy ctx.ResourcePacks() remains a separate transport API; registering there does not automatically enable assets for typed content.
LoadStack validates manifests/ZIPs and produces enabled pack metadata. resourcepack.NewCatalog captures pack bytes in memory, verifies size/SHA256 when a transport digest is present, and builds an immutable structural snapshot. It checks safe archive paths, duplicate physical paths, strict JSON parsing, atlas objects, and model structures. A structural error even in an unreferenced alias/model prevents catalog construction. Bootstrap retains the error in a failed resource capability: consumers receive it during resolve, while legacy modules without asset lookups are not rejected solely by the new catalog validator. This is not mandatory exhaustive asset validation for every legacy startup.
Resolve validates the referenced asset closure: atlas definition, PNG paths/bytes, valid PNG decoding, at most 16,777,216 pixels, and geometry definition. PNG validation occurs during resolve, rather than for every unused image file. JSON/model validation does not replace a complete Bedrock schema validator, Molang execution, or a client rendering test.
Item and terrain atlases have separate alias namespaces. Lookup spans enabled packs; filenames and UUIDs are not part of the plugin contract. PackID, bindings, RequirePack, and declarative resource dependencies do not exist yet. Pack identity is intentionally not guaranteed: another enabled pack may supply the same assets.
Conflicting referenced providers are rejected even when stack ordering could establish a client override. Equivalent duplicate aliases require identical normalized definitions and matching path/hash closure. A higher-priority pack's physical override of a referenced path is checked too. Geometry comparison includes the parsed definition and format_version; equivalent definitions may occur in different files or within one pack's array. Different definitions of one geometry ID in a pack cause a structural error. Exact decimal normalization avoids float rounding; array order and omitted fields remain significant. No winner within a pack is guessed from filenames.
Lifecycle and validation
The native adapter creates a Scope before Load. Registration remains open until Seal; a capability retained in Start or a goroutine after Load returns receives ErrRegistrationClosed. The Scope mutex prevents a race with Seal, but the API does not prohibit registration from a goroutine that finishes before closure. A module must complete declaration work before returning from Load.
A successful Load retains an owned Batch; a returned error or panic closes and discards that scope. This is rollback of typed declarations for that module load. Immediate legacy registrations, commands, subscriptions, and other side effects do not automatically become transactional.
Normalize validates all successful batches against authoritative registries: collisions across modules/existing content, block-item links, drop targets, assets, and supported declaration shape. Forward references work independently of Register order. Normalized items/blocks are sorted by semantic ID. Owners contain module name, version, and load generation; the logger automatically receives module, version, and load_generation.
bedrock.Prepare creates independent owned projections for the explicitly supplied enabled protocols. Nonempty typed content supports only 898, 1001, 2168, 2169, and 2193; an empty snapshot may pass with other protocols. An unsupported protocol/feature rejects the entire prepare: no latest fallback, automatic skipping, or silent degradation. Hardness above MaxFloat32, or positive hardness rounding to zero in float32 conversion, is also rejected; explicit zero is valid. Prepared does not mutate registries or allocate runtime/network IDs.
The new typed API has no raw escape hatch. Advanced legacy specs/components remain available through the separate old registrar, with its existing compatibility boundaries and eager side effects. Per-face materials, transparency, states/permutations, localization modes, and callbacks require further development; proposal examples do not establish those methods as available.
For evidence, limitations, and differences from the proposal, see Content API audit.
Documentation source
Snapshot from Pulce 4fc8a1bb. This page is generated from committed Markdown; code examples are preserved unchanged.