Resources
[!IMPORTANT] PulseLib does not draw model textures directly from arbitrary files. It first collects them into a runtime atlas, then the baked model stores UVs for that atlas. This is why model-resource registration is a required step instead of an optional convenience.
Model resources are declared by IPulseClientPlugin.registerModels(PModelRegistrar).
PulseLib collects these declarations at the beginning of every client resource reload, before atlas and model work starts. Both consumers use the completed resource map. Plugin instances survive reloads; model callbacks describe stable client content and may run repeatedly.
Register model resources
Declare an automatically discovered client plugin and register each model with its material texture references:
@PulsePlugin
public final class ExamplePulsePlugin implements IPulseClientPlugin
{
public static final PModelData ROBOT_MODEL =
PModelData.entity(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "robot"));
@Override
public Identifier getPluginId()
{
return Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "client");
}
@Override
public void registerModels(PModelRegistrar registrar)
{
registrar.model(ROBOT_MODEL).
texture("textures/body", Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "entity/robot/body")).
texture("textures/eyes", Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "entity/robot/eyes"));
}
}
registrar.model(PModelData) uses the model data's canonical ID and loader. For item JSON, create a static PModelData for registration; the JSON later creates a separate instance with the same canonical ID. registrar.model(Identifier) remains available for lower-level registrations and uses the glTF loader by default. The ID is canonical: it has no loader root or file extension. The glTF loader resolves entity/robot under glmodels/, and the Gecko loader resolves the same canonical id under geckolib/models/; call registrar.model(model, PGeckoModelLoader.INSTANCE.id()) for Gecko. Repeated calls for one model extend the same registration. A resource registration is also what makes PulseLib load and bake that model, so every PModelData canonical ID needs one matching registration.
The glTF loader accepts both .glb and .gltf. For every canonical ID it tries <model>.glb first and then <model>.gltf. The selected physical representation never changes the cache key or PModelData ID:
PModelData data = PModelData.entity(
Identifier.fromNamespaceAndPath("examplemod", "robot"));
registrar.model(data);
If neither candidate exists, resource reload fails and reports the canonical ID and both attempted physical paths.
Each texture key is the reference stored in the model material. For glTF it comes from the base-colour image URI, image name, or texture name. It preserves its complete directory path, while a final .png is ignored: body/claws.png becomes body/claws, and remains distinct from armor/claws. The value is a Minecraft resource location relative to textures without .png. Anonymous GLB bufferView images have no such key and are rejected during baking; use an image URI or a stable image or texture name:
assets/examplemod/textures/entity/robot/body.png
becomes:
Identifier.fromNamespaceAndPath("examplemod", "entity/robot/body")
Animation-event sidecars
An animation-event sidecar is optional and needs no plugin model declaration: the model loader finds it while loading its model or animation file. The first existing candidate is used, so keep only one sidecar for a model unless you deliberately want the earlier path to take precedence. Its contents use the animations JSON object described in Animation events.
For a glTF model at assets/examplemod/glmodels/entity/robot.glb or .gltf, PulseLib checks these paths in order:
assets/examplemod/glmodels/entity/robot.events.json
assets/examplemod/glmodels/entity/robot.animation_events.json
assets/examplemod/glmodels/events/entity/robot.events.json
assets/examplemod/glmodels/events/robot.events.json
Gecko sidecars are associated with the animation JSON that the loader selected. For an animation at assets/examplemod/geckolib/animations/robot.animation.json, the candidates are:
assets/examplemod/geckolib/animations/robot.events.json
assets/examplemod/geckolib/animations/robot.animation_events.json
assets/examplemod/geckolib/animations/events/robot.events.json
When the selected Gecko animation is in a subdirectory, the first two sidecar paths stay beside that selected animation file and the third path uses an events/ directory beside it.
glTF sidecar example
time is specified in seconds. The following file at assets/examplemod/glmodels/entity/robot.events.json adds effects, a callback, a graph-controller trigger, and visibility tracks to the attack animation:
{
"animations": {
"attack": {
"events": [
{
"type": "sound",
"time": 0.15,
"sound": "minecraft:entity.player.attack.strong",
"locator": "right_hand",
"volume": 0.9,
"pitch": 1.1
},
{
"type": "particle",
"time": 0.18,
"particle": "minecraft:crit",
"locator": "right_hand",
"offset": [0.0, 0.0, 0.0],
"motion": [0.0, 0.05, 0.0]
},
{
"type": "locator_callback",
"time": 0.20,
"callback": "examplemod:attack_hit",
"locator": "right_hand"
},
{
"type": "animation_parameter",
"time": 0.35,
"controller": "combat",
"parameter": "attack_complete",
"trigger": true
}
],
"visibility": {
"weapon": {
"0.0": false,
"0.12": true,
"0.45": false
},
"muzzle_flash": [
{ "time": 0.18, "visible": true },
{ "time": 0.23, "visible": false }
]
}
}
}
}
locator_callback invokes a callback registered through PAnimationEventCallbacks. animation_parameter addresses a graph controller; an empty controller uses the current graph controller, and trigger: true invokes the named trigger. Event types may use built-in short names, as above, or namespaced identifiers.
Gecko sidecar example
The format is identical for Gecko. A sidecar may also omit the outer animations object. For example, assets/examplemod/geckolib/animations/robot.animation_events.json can contain:
{
"animation.robot.idle": {
"events": [
{
"type": "camera_shake",
"time": 0.0,
"strength": 0.15,
"duration": 2,
"frequency": 8
}
],
"visibility": {
"glow": [
{ "time": 0.0, "visible": false },
{ "time": 0.5, "visible": true }
]
}
}
}
The animation key must exactly match the animation name in the loaded model. Both visibility forms shown above are supported.
Gecko model fallback texture
When a cube in a Gecko model has no texture field, PulseLib assigns the material reference "0". Register that reference as the model's fallback texture:
registrar.model(Identifier.fromNamespaceAndPath("examplemod", "entity/robot"),
PGeckoModelLoader.INSTANCE.id()).
texture("0", Identifier.fromNamespaceAndPath("examplemod", "entity/robot/fallback"));
Runtime atlas
The atlas is registered by PulseLib itself. Your mod contributes model-resource texture mappings.
Both loaders decode the same pulselib metadata section. PLibMetadata supplies the canonical emissive/alpha values; the native PLibSpriteMetadata adapter carries them into the atlas. With no metadata, emissive is false and alpha mode is AUTO. RuntimeLoader.CODEC / codec() provide the native atlas-source codec. The obsolete RuntimeLoader.TYPE and type() aliases have been removed.
Runtime atlas classes:
PulseLib registers the atlas at:
PResourceCache.ATLAS_LOCATION // pulselib:textures/atlas.png
Renderers normally pass PResourceCache.ATLAS_LOCATION to PRenderTypes, so you rarely need to access the atlas manually.
Alpha modes
PulseLib classifies each atlas sprite into one of four alpha modes:
opaquealways selects the solid pipeline.cutoutselects the cutout pipeline for fully transparent holes and hard edges.translucentselects a blended material. OIT additionally depends on the submission policy, target and backend support; alpha mode alone does not choose it.autoinspects the sprite while the model is baked. All-alpha-255 textures become opaque, textures containing only alpha 0 and 255 become cutout, and any intermediate alpha makes the texture translucent.
The default metadata mode is auto. You can override it next to the emissive flag in the texture's .png.mcmeta file:
{
"pulselib": {
"alpha_mode": "translucent",
"emissive": false
}
}
The render type supplied to the renderer remains authoritative by default. Opt into the sprite's baked classification with withAlphaMode(PAlphaMode.AUTO), or force OPAQUE, CUTOUT, or TRANSLUCENT. Passing null restores the renderer's original render-type function.
Per-mesh texture, emissive, and alpha overrides
PMeshRenderContext can override a mesh's colour, packed light, packed overlay, deformation, texture, emissive state, or alpha mode at render time. The replacement texture must still be registered in the runtime atlas. The first use of a (base mesh, replacement texture) pair lazily bakes and caches a matching PBakedMesh; later renders reuse it.
@Override
public PMeshRenderContext resolve(PBakedBone bone, PBakedMesh mesh,
PMeshRenderContext inherited)
{
if (!mesh.textureReference().equals("textures/eyes"))
return inherited;
return inherited.
withTexture(Identifier.fromNamespaceAndPath("examplemod", "entity/robot/eyes_active")).
withEmissive(true).
withAlphaMode(PAlphaMode.AUTO);
}
Pass null to withTexture, withEmissive, or withAlphaMode to return to the mesh's baked texture, metadata-derived emissive value, or renderer-selected pipeline respectively. An explicit false disables emissive even when the selected sprite metadata marks it emissive. Replacement texture variants cache their own alpha classification.
Prefer withColor(...), withPackedLight(...), withPackedOverlay(...), and the other with... methods when changing an inherited context. They preserve every override already attached by another resolver.
Emissive textures
Emissive textures are useful for eyes, screens, lamps, energy parts, and other pieces that should ignore normal light. PulseLib reads this flag from texture metadata through PLibSpriteMetadata.
To mark a texture as emissive, add a .png.mcmeta file next to it:
assets/examplemod/textures/entity/robot/eyes.png
assets/examplemod/textures/entity/robot/eyes.png.mcmeta
{
"pulselib": {
"emissive": true
}
}
When PModelCache bakes the model, each mesh stores whether its sprite is emissive. The default renderers also honour a PMeshRenderContext.withEmissive(...) override and automatically switch to an emissive variant through:
PRenderTypes.RenderTypeProvider.emissiveVariant(baseType, PResourceCache.ATLAS_LOCATION);
You can also choose an emissive render type directly in custom rendering code:
PRenderTypes.RenderTypeProvider::trianglesEmissiveCutout
PRenderTypes.RenderTypeProvider::trianglesEmissiveTranslucent
PRenderTypes.RenderTypeProvider::trianglesEmissiveSolid
Choose the solid, cutout, or translucent variant according to the desired alpha mode. Direct PBakedBone.instantDraw(...) rendering has matching trianglesInstantEmissiveSolid, trianglesInstantEmissiveCutout, and trianglesInstantEmissiveTranslucent variants. Use trianglesInstantTranslucent for the non-emissive instant translucent pipeline.
Classes used: