minerender 2.1.0-alpha.78 → 2.1.0-alpha.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -523,6 +523,8 @@ interface ItemModel extends Model {
523
523
  gui_light?: GuiLight;
524
524
  special?: SpecialItemRenderer;
525
525
  tints?: ItemTintSource[];
526
+ /** Ordered composite children, each with its own textures, display pose, and tint sources. */
527
+ parts?: ItemModel[];
526
528
  }
527
529
  /** An sRGB packed `0xRRGGBB` value or an RGB triple with components from 0 to 1. */
528
530
  type ItemTintColor = number | TripleArray;
@@ -1186,26 +1188,46 @@ declare class Fonts {
1186
1188
  private static bitmap;
1187
1189
  }
1188
1190
 
1191
+ /** Caller-supplied item-preview state passed to {@link Models.getMerged}. */
1192
+ interface ItemModelContext {
1193
+ /** Context used by display-context selectors, overriding `properties`. Defaults to GUI. */
1194
+ displayContext?: DisplayPosition | "none";
1195
+ /** Explicit property overrides. Nodes with the same ID share one override, regardless of their parameters. */
1196
+ properties?: Record<string, boolean | string | number>;
1197
+ /** Supplied component JSON by ID. Item-registry defaults are not added; component selectors compare structural JSON values. */
1198
+ components?: Record<string, unknown>;
1199
+ /** Stack count, as a nonnegative integer. Defaults to 1; absent `max_stack_size` also defaults to 1. */
1200
+ count?: number;
1201
+ /** Item-model keys by reference-node ID, such as `minecraft:bundle/selected_item`. Unset references draw nothing. */
1202
+ itemReferences?: Record<string, AssetKey>;
1203
+ }
1189
1204
  /** Loads and caches Java block/item models, including inherited geometry and textures. */
1190
1205
  declare class Models {
1191
1206
  private static _persistentCache;
1192
1207
  private static get PERSISTENT_CACHE();
1193
1208
  /** Lists item filenames from the asset source's `_list.json`, with a legacy model-directory fallback. */
1194
1209
  static getItemList(): Promise<string[]>;
1195
- static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
1210
+ static loadAndMerge(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1196
1211
  private static getItemModel;
1197
- private static defaultItemModel;
1212
+ private static contextIdentifier;
1213
+ private static snapshotContext;
1214
+ private static contextKey;
1215
+ private static snapshotJson;
1216
+ private static propertyValue;
1217
+ private static selectItemModel;
1198
1218
  /** Loads one model file without resolving its parents. Returns `undefined` when the file is missing. */
1199
1219
  static getRaw(key: AssetKey): Promise<Maybe<Model>>;
1200
1220
  /**
1201
1221
  * Loads a model and resolves its parent chain. Returns `undefined` when the model is missing.
1202
- * Item keys use GUI context, false conditions, and zero numeric properties.
1222
+ * Item keys default to GUI context and a stack count of 1. Unresolved conditions are false and numeric properties are zero.
1223
+ * Pass `context` to supply component values, property overrides, and item references for a preview.
1224
+ * Composite items retain independently merged children in `ItemModel.parts`.
1203
1225
  *
1204
1226
  * @param key - Model key, for example `AssetKey.parse("models", "minecraft:item/diamond_sword")`.
1205
1227
  */
1206
- static getMerged(key: AssetKey): Promise<Maybe<Model>>;
1228
+ static getMerged(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1207
1229
  /** Alias for {@link getMerged}. */
1208
- static get(key: AssetKey): Promise<Maybe<Model>>;
1230
+ static get(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1209
1231
  /** Clears persisted models. Use {@link Caching.clear} to also discard in-memory assets. */
1210
1232
  static clearCache(): Promise<void>;
1211
1233
  }
@@ -1362,6 +1384,7 @@ declare class ModelObject extends SceneObject {
1362
1384
  private atlasTexture?;
1363
1385
  private unsubscribeAtlas?;
1364
1386
  private readonly specialMaterials;
1387
+ private readonly geometries;
1365
1388
  blockParent: Maybe<BlockObject>;
1366
1389
  private meshesCreated;
1367
1390
  constructor(originalModel: Model, options?: Partial<ModelObjectOptions>);
@@ -3210,4 +3233,4 @@ declare class BrowserCache extends PersistentCache<LocalForage> {
3210
3233
  */
3211
3234
  declare function probeImageSize(data: Uint8Array): ImageSizeInfo;
3212
3235
 
3213
- export { AXES, type AnimationFrame, type AnimationMeta, type AnimatorFunction, type AnvilChunk, AnvilParser, type AnvilRegion, ArchiveAssetSource, type ArchiveAssetSourceOptions, type ArchiveEntry, type ArchiveProxy, AssetKey, AssetLoadError, AssetLoader, AssetParser, AssetSource, type AssetType, Assets, Axis, BUILTIN_ENTITY, BUILTIN_GENERATED, BasicAssetKey, type BasicMinecraftAsset, BatchedExecutor, type BedrockBone, type BedrockCube, type BedrockEntityDescription, type BedrockEntityFile, type BedrockGeometry, type BedrockGeometryFile, type BitmapFont, type BitmapGlyph, type Block, BlockEntities, type BlockEntityEntry, type BlockEntityIndex, type BlockEntityPart, type BlockEntityRotation, type BlockFluidState, type BlockInfo, type BlockModel, type BlockModelTextures, BlockObject, type BlockObjectOptions, type BlockState, type BlockStateMultipart, type BlockStateProperties, type BlockStateProperty, type BlockStatePropertyDefaults, type BlockStatePropertyValue, BlockStateResolver, type BlockStateVariant, type BlockStateVariants, BlockStates, BlockTints, type BoxGeometryKey, BrowserArchiveProxy, BrowserCache, BrowserEnv, CUBE_FACES, CUBE_FACE_OFFSETS, type CacheKey, Caching, type CameraOptions, CanvasImage, type CapeLayout, Chunk, ChunkData, Colormaps, type CompatCanvas, type CompatImage, type ComposerOptions, type ControlsOptions, CubeFace, CubeFaceIndex, DEFAULT_ELEMENTS, DEFAULT_NAMESPACE, DEFAULT_ROOT, DEFAULT_UV, DISPLAY_POSITIONS, type DebugOptions, type DeepPartial, DefaultBlockStates, DisplayPosition, DisplayTransforms, type Disposable, type DoubleArray, ENTITY_ANIMATION_CHANNELS, type ElementFace, type ElementRotation, Entities, type EntityAnimation, type EntityAnimationBone, type EntityAnimationChannel, type EntityAnimationFile, type EntityAnimationKeyframe, type EntityAnimationOptions, EntityAnimationPlayer, type EntityAnimationPose, type EntityLayer, type EntityModel, type EntityModelCube, type EntityModelFile, type EntityModelLayer, type EntityModelOptions, type EntityModelPart, type EntityModelPass, EntityObject, type EntityObjectOptions, type EntityRenderMode, type EntityTransformOp, Env, type EnvProvider, type ExtractableImageData, type FluidKind, FluidModelObject, type FluidSample, type FluidSampler, Fonts, type FrameCallback, type FromTo, GUI_CONTAINER_LAYOUTS, Geometries, type GuiBookButtonState, type GuiBookOptions, type GuiBossBarColor, type GuiBossBarOptions, type GuiContainerType, GuiHelper, type GuiItemLayer, type GuiLayer, GuiLight, GuiObject, type GuiObjectOptions, type GuiRecipe, type GuiRecipeIngredient, type GuiRecipeOptions, type GuiSpriteScaling, type GuiText, type GuiTextLayer, type GuiTextLayout, type GuiTextOptions, type GuiTextRun, type GuiTextStyle, type GuiTextureLayer, type GuiTooltipOptions, HostedAssetSource, type IModelTextures, ITEM_GENERATED, type ImageInfo, ImageLoader, type ImageSizeInfo, InstanceManager, InstanceReference, type Instanceable, type ItemModel, type ItemModelTextures, type ItemTintColor, type ItemTintSource, ItemTints, type ListAsset, type LoadedSceneDocument, type LoadedSceneObject, MapControls, type MaterialKey, Materials, type Maybe, type MeshKey, Meshes, MineRenderError, MineRenderScene, type MineRenderSceneOptions, MineRenderWorld, type MineRenderWorldOptions, type MinecraftAsset, MinecraftCubeTexture, MinecraftFaceUV, type MinecraftTextureMeta, type Model, ModelCulling, type ModelDisplay, type ModelElement, type ModelFaces, ModelGenerator, ModelMerger, ModelObject, type ModelObjectOptions, ModelTextures, Models, type MultiBlockBlock, type MultiBlockEntity, type MultiBlockStructure, type MultipartCondition, type NBTAsset, NBTHelper, OrbitControls, type PackFormat, PackFormats, PackMetadata, PersistentCache, type PositionedGuiGlyph, type QuadArray, type RawImageKey, type RenderOptions, Renderer, type RendererFrame, type RendererOptions, type RequestConfig, RequestError, type RequestResponse, Requests, type ResolvedBlockEntity, type ResponseParser, SKIN_PARTS, type SceneBlockDefinition, type SceneDocument, SceneDocumentLoader, type SceneEntityDefinition, SceneExporter, type SceneGLTFExportOptions, type SceneGuiDefinition, type SceneGuiLayer, SceneInspector, type SceneModelDefinition, SceneObject, type SceneObjectDefinition, type SceneObjectDefinitionBase, type SceneObjectOptions, type SceneSkinDefinition, type SceneSkinPosePart, SceneStats, SceneStatsDisplay, SchematicParser, type SchematicParserOptions, SectionMesh, type SectionMeshEntry, type SectionMeshTemplate, SectionModels, type Serializable, type SkinGeometries, SkinImage, SkinObject, type SkinObjectOptions, SkinPart, type SkinTexture, type SkinTextureCoordinates, SkinTextures, Skins, type SpecialItemPart, type SpecialItemRenderer, SpecialItems, type StructureNBT, StructureParser, type TextureAsset, TextureAtlas, type TextureKey, TextureLoader, Textures, Ticker, type TickerFunction, TintColors, type Transformable, type TripleArray, UVMapper, WrappedImage, addBox3WireframeToObject, addWireframeToMesh, addWireframeToObject, applyElementRotation, applyGenericRotation, axisToVec3, base64decode, base64encode, capeTextureSizes, captureException, changeEvent, clampRotationDegrees, classicSkinGeometries, classicSkinTextureCoordinates, computeMorphedAttributes, createCanvas, createFluidGeometry, createGuiTextGeometry, createGuiTextureGeometry, createImage, entityAnimationTime, estimateBytesUsed, getBlockFluidState, getFluidKind, interleaveAttributes, isAssetKey, isBasicAssetKey, isBlockObject, isDisposable, isDoubleArray, isEntityObject, isGuiObject, isInstanceManager, isInstanceReference, isInstanceable, isInstancedMesh, isMesh, isMineRenderScene, isModelObject, isObject3D, isOrthographicCamera, isPerspectiveCamera, isQuadArray, isSceneObject, isTransformable, isTripleArray, isVector3, layoutGuiText, md5, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, parseSceneDocument, prefix, probeImageSize, registerBrowserEnv, sampleEntityAnimation, sampleEntityKeyframes, sampleFluid, serializeBoxGeometryKey, serializeImageKey, serializeMaterialKey, serializeMeshKey, serializeTextureKey, sha1, sha256, sha512, shutdown, sleep, slimSkinGeometries, slimSkinTextureCoordinates, timingEnd, timingStart, toDegrees, toRadians, toTrianglesDrawMode, trimCanvas };
3236
+ export { AXES, type AnimationFrame, type AnimationMeta, type AnimatorFunction, type AnvilChunk, AnvilParser, type AnvilRegion, ArchiveAssetSource, type ArchiveAssetSourceOptions, type ArchiveEntry, type ArchiveProxy, AssetKey, AssetLoadError, AssetLoader, AssetParser, AssetSource, type AssetType, Assets, Axis, BUILTIN_ENTITY, BUILTIN_GENERATED, BasicAssetKey, type BasicMinecraftAsset, BatchedExecutor, type BedrockBone, type BedrockCube, type BedrockEntityDescription, type BedrockEntityFile, type BedrockGeometry, type BedrockGeometryFile, type BitmapFont, type BitmapGlyph, type Block, BlockEntities, type BlockEntityEntry, type BlockEntityIndex, type BlockEntityPart, type BlockEntityRotation, type BlockFluidState, type BlockInfo, type BlockModel, type BlockModelTextures, BlockObject, type BlockObjectOptions, type BlockState, type BlockStateMultipart, type BlockStateProperties, type BlockStateProperty, type BlockStatePropertyDefaults, type BlockStatePropertyValue, BlockStateResolver, type BlockStateVariant, type BlockStateVariants, BlockStates, BlockTints, type BoxGeometryKey, BrowserArchiveProxy, BrowserCache, BrowserEnv, CUBE_FACES, CUBE_FACE_OFFSETS, type CacheKey, Caching, type CameraOptions, CanvasImage, type CapeLayout, Chunk, ChunkData, Colormaps, type CompatCanvas, type CompatImage, type ComposerOptions, type ControlsOptions, CubeFace, CubeFaceIndex, DEFAULT_ELEMENTS, DEFAULT_NAMESPACE, DEFAULT_ROOT, DEFAULT_UV, DISPLAY_POSITIONS, type DebugOptions, type DeepPartial, DefaultBlockStates, DisplayPosition, DisplayTransforms, type Disposable, type DoubleArray, ENTITY_ANIMATION_CHANNELS, type ElementFace, type ElementRotation, Entities, type EntityAnimation, type EntityAnimationBone, type EntityAnimationChannel, type EntityAnimationFile, type EntityAnimationKeyframe, type EntityAnimationOptions, EntityAnimationPlayer, type EntityAnimationPose, type EntityLayer, type EntityModel, type EntityModelCube, type EntityModelFile, type EntityModelLayer, type EntityModelOptions, type EntityModelPart, type EntityModelPass, EntityObject, type EntityObjectOptions, type EntityRenderMode, type EntityTransformOp, Env, type EnvProvider, type ExtractableImageData, type FluidKind, FluidModelObject, type FluidSample, type FluidSampler, Fonts, type FrameCallback, type FromTo, GUI_CONTAINER_LAYOUTS, Geometries, type GuiBookButtonState, type GuiBookOptions, type GuiBossBarColor, type GuiBossBarOptions, type GuiContainerType, GuiHelper, type GuiItemLayer, type GuiLayer, GuiLight, GuiObject, type GuiObjectOptions, type GuiRecipe, type GuiRecipeIngredient, type GuiRecipeOptions, type GuiSpriteScaling, type GuiText, type GuiTextLayer, type GuiTextLayout, type GuiTextOptions, type GuiTextRun, type GuiTextStyle, type GuiTextureLayer, type GuiTooltipOptions, HostedAssetSource, type IModelTextures, ITEM_GENERATED, type ImageInfo, ImageLoader, type ImageSizeInfo, InstanceManager, InstanceReference, type Instanceable, type ItemModel, type ItemModelContext, type ItemModelTextures, type ItemTintColor, type ItemTintSource, ItemTints, type ListAsset, type LoadedSceneDocument, type LoadedSceneObject, MapControls, type MaterialKey, Materials, type Maybe, type MeshKey, Meshes, MineRenderError, MineRenderScene, type MineRenderSceneOptions, MineRenderWorld, type MineRenderWorldOptions, type MinecraftAsset, MinecraftCubeTexture, MinecraftFaceUV, type MinecraftTextureMeta, type Model, ModelCulling, type ModelDisplay, type ModelElement, type ModelFaces, ModelGenerator, ModelMerger, ModelObject, type ModelObjectOptions, ModelTextures, Models, type MultiBlockBlock, type MultiBlockEntity, type MultiBlockStructure, type MultipartCondition, type NBTAsset, NBTHelper, OrbitControls, type PackFormat, PackFormats, PackMetadata, PersistentCache, type PositionedGuiGlyph, type QuadArray, type RawImageKey, type RenderOptions, Renderer, type RendererFrame, type RendererOptions, type RequestConfig, RequestError, type RequestResponse, Requests, type ResolvedBlockEntity, type ResponseParser, SKIN_PARTS, type SceneBlockDefinition, type SceneDocument, SceneDocumentLoader, type SceneEntityDefinition, SceneExporter, type SceneGLTFExportOptions, type SceneGuiDefinition, type SceneGuiLayer, SceneInspector, type SceneModelDefinition, SceneObject, type SceneObjectDefinition, type SceneObjectDefinitionBase, type SceneObjectOptions, type SceneSkinDefinition, type SceneSkinPosePart, SceneStats, SceneStatsDisplay, SchematicParser, type SchematicParserOptions, SectionMesh, type SectionMeshEntry, type SectionMeshTemplate, SectionModels, type Serializable, type SkinGeometries, SkinImage, SkinObject, type SkinObjectOptions, SkinPart, type SkinTexture, type SkinTextureCoordinates, SkinTextures, Skins, type SpecialItemPart, type SpecialItemRenderer, SpecialItems, type StructureNBT, StructureParser, type TextureAsset, TextureAtlas, type TextureKey, TextureLoader, Textures, Ticker, type TickerFunction, TintColors, type Transformable, type TripleArray, UVMapper, WrappedImage, addBox3WireframeToObject, addWireframeToMesh, addWireframeToObject, applyElementRotation, applyGenericRotation, axisToVec3, base64decode, base64encode, capeTextureSizes, captureException, changeEvent, clampRotationDegrees, classicSkinGeometries, classicSkinTextureCoordinates, computeMorphedAttributes, createCanvas, createFluidGeometry, createGuiTextGeometry, createGuiTextureGeometry, createImage, entityAnimationTime, estimateBytesUsed, getBlockFluidState, getFluidKind, interleaveAttributes, isAssetKey, isBasicAssetKey, isBlockObject, isDisposable, isDoubleArray, isEntityObject, isGuiObject, isInstanceManager, isInstanceReference, isInstanceable, isInstancedMesh, isMesh, isMineRenderScene, isModelObject, isObject3D, isOrthographicCamera, isPerspectiveCamera, isQuadArray, isSceneObject, isTransformable, isTripleArray, isVector3, layoutGuiText, md5, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, parseSceneDocument, prefix, probeImageSize, registerBrowserEnv, sampleEntityAnimation, sampleEntityKeyframes, sampleFluid, serializeBoxGeometryKey, serializeImageKey, serializeMaterialKey, serializeMeshKey, serializeTextureKey, sha1, sha256, sha512, shutdown, sleep, slimSkinGeometries, slimSkinTextureCoordinates, timingEnd, timingStart, toDegrees, toRadians, toTrianglesDrawMode, trimCanvas };
@@ -523,6 +523,8 @@ interface ItemModel extends Model {
523
523
  gui_light?: GuiLight;
524
524
  special?: SpecialItemRenderer;
525
525
  tints?: ItemTintSource[];
526
+ /** Ordered composite children, each with its own textures, display pose, and tint sources. */
527
+ parts?: ItemModel[];
526
528
  }
527
529
  /** An sRGB packed `0xRRGGBB` value or an RGB triple with components from 0 to 1. */
528
530
  type ItemTintColor = number | TripleArray;
@@ -1186,26 +1188,46 @@ declare class Fonts {
1186
1188
  private static bitmap;
1187
1189
  }
1188
1190
 
1191
+ /** Caller-supplied item-preview state passed to {@link Models.getMerged}. */
1192
+ interface ItemModelContext {
1193
+ /** Context used by display-context selectors, overriding `properties`. Defaults to GUI. */
1194
+ displayContext?: DisplayPosition | "none";
1195
+ /** Explicit property overrides. Nodes with the same ID share one override, regardless of their parameters. */
1196
+ properties?: Record<string, boolean | string | number>;
1197
+ /** Supplied component JSON by ID. Item-registry defaults are not added; component selectors compare structural JSON values. */
1198
+ components?: Record<string, unknown>;
1199
+ /** Stack count, as a nonnegative integer. Defaults to 1; absent `max_stack_size` also defaults to 1. */
1200
+ count?: number;
1201
+ /** Item-model keys by reference-node ID, such as `minecraft:bundle/selected_item`. Unset references draw nothing. */
1202
+ itemReferences?: Record<string, AssetKey>;
1203
+ }
1189
1204
  /** Loads and caches Java block/item models, including inherited geometry and textures. */
1190
1205
  declare class Models {
1191
1206
  private static _persistentCache;
1192
1207
  private static get PERSISTENT_CACHE();
1193
1208
  /** Lists item filenames from the asset source's `_list.json`, with a legacy model-directory fallback. */
1194
1209
  static getItemList(): Promise<string[]>;
1195
- static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
1210
+ static loadAndMerge(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1196
1211
  private static getItemModel;
1197
- private static defaultItemModel;
1212
+ private static contextIdentifier;
1213
+ private static snapshotContext;
1214
+ private static contextKey;
1215
+ private static snapshotJson;
1216
+ private static propertyValue;
1217
+ private static selectItemModel;
1198
1218
  /** Loads one model file without resolving its parents. Returns `undefined` when the file is missing. */
1199
1219
  static getRaw(key: AssetKey): Promise<Maybe<Model>>;
1200
1220
  /**
1201
1221
  * Loads a model and resolves its parent chain. Returns `undefined` when the model is missing.
1202
- * Item keys use GUI context, false conditions, and zero numeric properties.
1222
+ * Item keys default to GUI context and a stack count of 1. Unresolved conditions are false and numeric properties are zero.
1223
+ * Pass `context` to supply component values, property overrides, and item references for a preview.
1224
+ * Composite items retain independently merged children in `ItemModel.parts`.
1203
1225
  *
1204
1226
  * @param key - Model key, for example `AssetKey.parse("models", "minecraft:item/diamond_sword")`.
1205
1227
  */
1206
- static getMerged(key: AssetKey): Promise<Maybe<Model>>;
1228
+ static getMerged(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1207
1229
  /** Alias for {@link getMerged}. */
1208
- static get(key: AssetKey): Promise<Maybe<Model>>;
1230
+ static get(key: AssetKey, context?: ItemModelContext): Promise<Maybe<Model>>;
1209
1231
  /** Clears persisted models. Use {@link Caching.clear} to also discard in-memory assets. */
1210
1232
  static clearCache(): Promise<void>;
1211
1233
  }
@@ -1362,6 +1384,7 @@ declare class ModelObject extends SceneObject {
1362
1384
  private atlasTexture?;
1363
1385
  private unsubscribeAtlas?;
1364
1386
  private readonly specialMaterials;
1387
+ private readonly geometries;
1365
1388
  blockParent: Maybe<BlockObject>;
1366
1389
  private meshesCreated;
1367
1390
  constructor(originalModel: Model, options?: Partial<ModelObjectOptions>);
@@ -3210,4 +3233,4 @@ declare class BrowserCache extends PersistentCache<LocalForage> {
3210
3233
  */
3211
3234
  declare function probeImageSize(data: Uint8Array): ImageSizeInfo;
3212
3235
 
3213
- export { AXES, type AnimationFrame, type AnimationMeta, type AnimatorFunction, type AnvilChunk, AnvilParser, type AnvilRegion, ArchiveAssetSource, type ArchiveAssetSourceOptions, type ArchiveEntry, type ArchiveProxy, AssetKey, AssetLoadError, AssetLoader, AssetParser, AssetSource, type AssetType, Assets, Axis, BUILTIN_ENTITY, BUILTIN_GENERATED, BasicAssetKey, type BasicMinecraftAsset, BatchedExecutor, type BedrockBone, type BedrockCube, type BedrockEntityDescription, type BedrockEntityFile, type BedrockGeometry, type BedrockGeometryFile, type BitmapFont, type BitmapGlyph, type Block, BlockEntities, type BlockEntityEntry, type BlockEntityIndex, type BlockEntityPart, type BlockEntityRotation, type BlockFluidState, type BlockInfo, type BlockModel, type BlockModelTextures, BlockObject, type BlockObjectOptions, type BlockState, type BlockStateMultipart, type BlockStateProperties, type BlockStateProperty, type BlockStatePropertyDefaults, type BlockStatePropertyValue, BlockStateResolver, type BlockStateVariant, type BlockStateVariants, BlockStates, BlockTints, type BoxGeometryKey, BrowserArchiveProxy, BrowserCache, BrowserEnv, CUBE_FACES, CUBE_FACE_OFFSETS, type CacheKey, Caching, type CameraOptions, CanvasImage, type CapeLayout, Chunk, ChunkData, Colormaps, type CompatCanvas, type CompatImage, type ComposerOptions, type ControlsOptions, CubeFace, CubeFaceIndex, DEFAULT_ELEMENTS, DEFAULT_NAMESPACE, DEFAULT_ROOT, DEFAULT_UV, DISPLAY_POSITIONS, type DebugOptions, type DeepPartial, DefaultBlockStates, DisplayPosition, DisplayTransforms, type Disposable, type DoubleArray, ENTITY_ANIMATION_CHANNELS, type ElementFace, type ElementRotation, Entities, type EntityAnimation, type EntityAnimationBone, type EntityAnimationChannel, type EntityAnimationFile, type EntityAnimationKeyframe, type EntityAnimationOptions, EntityAnimationPlayer, type EntityAnimationPose, type EntityLayer, type EntityModel, type EntityModelCube, type EntityModelFile, type EntityModelLayer, type EntityModelOptions, type EntityModelPart, type EntityModelPass, EntityObject, type EntityObjectOptions, type EntityRenderMode, type EntityTransformOp, Env, type EnvProvider, type ExtractableImageData, type FluidKind, FluidModelObject, type FluidSample, type FluidSampler, Fonts, type FrameCallback, type FromTo, GUI_CONTAINER_LAYOUTS, Geometries, type GuiBookButtonState, type GuiBookOptions, type GuiBossBarColor, type GuiBossBarOptions, type GuiContainerType, GuiHelper, type GuiItemLayer, type GuiLayer, GuiLight, GuiObject, type GuiObjectOptions, type GuiRecipe, type GuiRecipeIngredient, type GuiRecipeOptions, type GuiSpriteScaling, type GuiText, type GuiTextLayer, type GuiTextLayout, type GuiTextOptions, type GuiTextRun, type GuiTextStyle, type GuiTextureLayer, type GuiTooltipOptions, HostedAssetSource, type IModelTextures, ITEM_GENERATED, type ImageInfo, ImageLoader, type ImageSizeInfo, InstanceManager, InstanceReference, type Instanceable, type ItemModel, type ItemModelTextures, type ItemTintColor, type ItemTintSource, ItemTints, type ListAsset, type LoadedSceneDocument, type LoadedSceneObject, MapControls, type MaterialKey, Materials, type Maybe, type MeshKey, Meshes, MineRenderError, MineRenderScene, type MineRenderSceneOptions, MineRenderWorld, type MineRenderWorldOptions, type MinecraftAsset, MinecraftCubeTexture, MinecraftFaceUV, type MinecraftTextureMeta, type Model, ModelCulling, type ModelDisplay, type ModelElement, type ModelFaces, ModelGenerator, ModelMerger, ModelObject, type ModelObjectOptions, ModelTextures, Models, type MultiBlockBlock, type MultiBlockEntity, type MultiBlockStructure, type MultipartCondition, type NBTAsset, NBTHelper, OrbitControls, type PackFormat, PackFormats, PackMetadata, PersistentCache, type PositionedGuiGlyph, type QuadArray, type RawImageKey, type RenderOptions, Renderer, type RendererFrame, type RendererOptions, type RequestConfig, RequestError, type RequestResponse, Requests, type ResolvedBlockEntity, type ResponseParser, SKIN_PARTS, type SceneBlockDefinition, type SceneDocument, SceneDocumentLoader, type SceneEntityDefinition, SceneExporter, type SceneGLTFExportOptions, type SceneGuiDefinition, type SceneGuiLayer, SceneInspector, type SceneModelDefinition, SceneObject, type SceneObjectDefinition, type SceneObjectDefinitionBase, type SceneObjectOptions, type SceneSkinDefinition, type SceneSkinPosePart, SceneStats, SceneStatsDisplay, SchematicParser, type SchematicParserOptions, SectionMesh, type SectionMeshEntry, type SectionMeshTemplate, SectionModels, type Serializable, type SkinGeometries, SkinImage, SkinObject, type SkinObjectOptions, SkinPart, type SkinTexture, type SkinTextureCoordinates, SkinTextures, Skins, type SpecialItemPart, type SpecialItemRenderer, SpecialItems, type StructureNBT, StructureParser, type TextureAsset, TextureAtlas, type TextureKey, TextureLoader, Textures, Ticker, type TickerFunction, TintColors, type Transformable, type TripleArray, UVMapper, WrappedImage, addBox3WireframeToObject, addWireframeToMesh, addWireframeToObject, applyElementRotation, applyGenericRotation, axisToVec3, base64decode, base64encode, capeTextureSizes, captureException, changeEvent, clampRotationDegrees, classicSkinGeometries, classicSkinTextureCoordinates, computeMorphedAttributes, createCanvas, createFluidGeometry, createGuiTextGeometry, createGuiTextureGeometry, createImage, entityAnimationTime, estimateBytesUsed, getBlockFluidState, getFluidKind, interleaveAttributes, isAssetKey, isBasicAssetKey, isBlockObject, isDisposable, isDoubleArray, isEntityObject, isGuiObject, isInstanceManager, isInstanceReference, isInstanceable, isInstancedMesh, isMesh, isMineRenderScene, isModelObject, isObject3D, isOrthographicCamera, isPerspectiveCamera, isQuadArray, isSceneObject, isTransformable, isTripleArray, isVector3, layoutGuiText, md5, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, parseSceneDocument, prefix, probeImageSize, registerBrowserEnv, sampleEntityAnimation, sampleEntityKeyframes, sampleFluid, serializeBoxGeometryKey, serializeImageKey, serializeMaterialKey, serializeMeshKey, serializeTextureKey, sha1, sha256, sha512, shutdown, sleep, slimSkinGeometries, slimSkinTextureCoordinates, timingEnd, timingStart, toDegrees, toRadians, toTrianglesDrawMode, trimCanvas };
3236
+ export { AXES, type AnimationFrame, type AnimationMeta, type AnimatorFunction, type AnvilChunk, AnvilParser, type AnvilRegion, ArchiveAssetSource, type ArchiveAssetSourceOptions, type ArchiveEntry, type ArchiveProxy, AssetKey, AssetLoadError, AssetLoader, AssetParser, AssetSource, type AssetType, Assets, Axis, BUILTIN_ENTITY, BUILTIN_GENERATED, BasicAssetKey, type BasicMinecraftAsset, BatchedExecutor, type BedrockBone, type BedrockCube, type BedrockEntityDescription, type BedrockEntityFile, type BedrockGeometry, type BedrockGeometryFile, type BitmapFont, type BitmapGlyph, type Block, BlockEntities, type BlockEntityEntry, type BlockEntityIndex, type BlockEntityPart, type BlockEntityRotation, type BlockFluidState, type BlockInfo, type BlockModel, type BlockModelTextures, BlockObject, type BlockObjectOptions, type BlockState, type BlockStateMultipart, type BlockStateProperties, type BlockStateProperty, type BlockStatePropertyDefaults, type BlockStatePropertyValue, BlockStateResolver, type BlockStateVariant, type BlockStateVariants, BlockStates, BlockTints, type BoxGeometryKey, BrowserArchiveProxy, BrowserCache, BrowserEnv, CUBE_FACES, CUBE_FACE_OFFSETS, type CacheKey, Caching, type CameraOptions, CanvasImage, type CapeLayout, Chunk, ChunkData, Colormaps, type CompatCanvas, type CompatImage, type ComposerOptions, type ControlsOptions, CubeFace, CubeFaceIndex, DEFAULT_ELEMENTS, DEFAULT_NAMESPACE, DEFAULT_ROOT, DEFAULT_UV, DISPLAY_POSITIONS, type DebugOptions, type DeepPartial, DefaultBlockStates, DisplayPosition, DisplayTransforms, type Disposable, type DoubleArray, ENTITY_ANIMATION_CHANNELS, type ElementFace, type ElementRotation, Entities, type EntityAnimation, type EntityAnimationBone, type EntityAnimationChannel, type EntityAnimationFile, type EntityAnimationKeyframe, type EntityAnimationOptions, EntityAnimationPlayer, type EntityAnimationPose, type EntityLayer, type EntityModel, type EntityModelCube, type EntityModelFile, type EntityModelLayer, type EntityModelOptions, type EntityModelPart, type EntityModelPass, EntityObject, type EntityObjectOptions, type EntityRenderMode, type EntityTransformOp, Env, type EnvProvider, type ExtractableImageData, type FluidKind, FluidModelObject, type FluidSample, type FluidSampler, Fonts, type FrameCallback, type FromTo, GUI_CONTAINER_LAYOUTS, Geometries, type GuiBookButtonState, type GuiBookOptions, type GuiBossBarColor, type GuiBossBarOptions, type GuiContainerType, GuiHelper, type GuiItemLayer, type GuiLayer, GuiLight, GuiObject, type GuiObjectOptions, type GuiRecipe, type GuiRecipeIngredient, type GuiRecipeOptions, type GuiSpriteScaling, type GuiText, type GuiTextLayer, type GuiTextLayout, type GuiTextOptions, type GuiTextRun, type GuiTextStyle, type GuiTextureLayer, type GuiTooltipOptions, HostedAssetSource, type IModelTextures, ITEM_GENERATED, type ImageInfo, ImageLoader, type ImageSizeInfo, InstanceManager, InstanceReference, type Instanceable, type ItemModel, type ItemModelContext, type ItemModelTextures, type ItemTintColor, type ItemTintSource, ItemTints, type ListAsset, type LoadedSceneDocument, type LoadedSceneObject, MapControls, type MaterialKey, Materials, type Maybe, type MeshKey, Meshes, MineRenderError, MineRenderScene, type MineRenderSceneOptions, MineRenderWorld, type MineRenderWorldOptions, type MinecraftAsset, MinecraftCubeTexture, MinecraftFaceUV, type MinecraftTextureMeta, type Model, ModelCulling, type ModelDisplay, type ModelElement, type ModelFaces, ModelGenerator, ModelMerger, ModelObject, type ModelObjectOptions, ModelTextures, Models, type MultiBlockBlock, type MultiBlockEntity, type MultiBlockStructure, type MultipartCondition, type NBTAsset, NBTHelper, OrbitControls, type PackFormat, PackFormats, PackMetadata, PersistentCache, type PositionedGuiGlyph, type QuadArray, type RawImageKey, type RenderOptions, Renderer, type RendererFrame, type RendererOptions, type RequestConfig, RequestError, type RequestResponse, Requests, type ResolvedBlockEntity, type ResponseParser, SKIN_PARTS, type SceneBlockDefinition, type SceneDocument, SceneDocumentLoader, type SceneEntityDefinition, SceneExporter, type SceneGLTFExportOptions, type SceneGuiDefinition, type SceneGuiLayer, SceneInspector, type SceneModelDefinition, SceneObject, type SceneObjectDefinition, type SceneObjectDefinitionBase, type SceneObjectOptions, type SceneSkinDefinition, type SceneSkinPosePart, SceneStats, SceneStatsDisplay, SchematicParser, type SchematicParserOptions, SectionMesh, type SectionMeshEntry, type SectionMeshTemplate, SectionModels, type Serializable, type SkinGeometries, SkinImage, SkinObject, type SkinObjectOptions, SkinPart, type SkinTexture, type SkinTextureCoordinates, SkinTextures, Skins, type SpecialItemPart, type SpecialItemRenderer, SpecialItems, type StructureNBT, StructureParser, type TextureAsset, TextureAtlas, type TextureKey, TextureLoader, Textures, Ticker, type TickerFunction, TintColors, type Transformable, type TripleArray, UVMapper, WrappedImage, addBox3WireframeToObject, addWireframeToMesh, addWireframeToObject, applyElementRotation, applyGenericRotation, axisToVec3, base64decode, base64encode, capeTextureSizes, captureException, changeEvent, clampRotationDegrees, classicSkinGeometries, classicSkinTextureCoordinates, computeMorphedAttributes, createCanvas, createFluidGeometry, createGuiTextGeometry, createGuiTextureGeometry, createImage, entityAnimationTime, estimateBytesUsed, getBlockFluidState, getFluidKind, interleaveAttributes, isAssetKey, isBasicAssetKey, isBlockObject, isDisposable, isDoubleArray, isEntityObject, isGuiObject, isInstanceManager, isInstanceReference, isInstanceable, isInstancedMesh, isMesh, isMineRenderScene, isModelObject, isObject3D, isOrthographicCamera, isPerspectiveCamera, isQuadArray, isSceneObject, isTransformable, isTripleArray, isVector3, layoutGuiText, md5, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, parseSceneDocument, prefix, probeImageSize, registerBrowserEnv, sampleEntityAnimation, sampleEntityKeyframes, sampleFluid, serializeBoxGeometryKey, serializeImageKey, serializeMaterialKey, serializeMeshKey, serializeTextureKey, sha1, sha256, sha512, shutdown, sleep, slimSkinGeometries, slimSkinTextureCoordinates, timingEnd, timingStart, toDegrees, toRadians, toTrianglesDrawMode, trimCanvas };
@@ -1478,6 +1478,8 @@ var init_ModelMerger = __esm({
1478
1478
  ModelMerger = class {
1479
1479
  /** Loads the parent chain and returns a merged model without modifying the supplied definition. */
1480
1480
  static async mergeWithParents(model) {
1481
+ const parts = model.parts;
1482
+ if (parts) return { ...model, parts: await Promise.all(parts.map((part) => this.mergeWithParents(part))) };
1481
1483
  const models = await this.collectAllParents(model);
1482
1484
  let merged = {};
1483
1485
  for (const source of [...models, model]) {
@@ -1538,6 +1540,7 @@ var init_Models = __esm({
1538
1540
  init_PersistentCache();
1539
1541
  init_AssetKey();
1540
1542
  init_AssetParsers();
1543
+ init_DisplayPosition();
1541
1544
  Models = class _Models {
1542
1545
  // opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
1543
1546
  // the library, and would require an EnvProvider before any entry has had a chance to register
@@ -1552,34 +1555,174 @@ var init_Models = __esm({
1552
1555
  return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
1553
1556
  }).then((r) => r?.files ?? []);
1554
1557
  }
1555
- static async loadAndMerge(key) {
1556
- const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
1558
+ static async loadAndMerge(key, context = {}) {
1559
+ const model = key.type === "item" ? await this.getItemModel(key, context) : await this.getRaw(key);
1557
1560
  if (!model) {
1558
1561
  return void 0;
1559
1562
  }
1560
1563
  return ModelMerger.mergeWithParents(model);
1561
1564
  }
1562
- static async getItemModel(key) {
1565
+ static async getItemModel(key, context = {}) {
1566
+ const preview = this.snapshotContext(key, context);
1563
1567
  const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1564
- const model = await this.PERSISTENT_CACHE.getOrLoad(`item-v2:${AssetLoader.persistentKey(itemKey.serialize())}`, async () => {
1568
+ const cacheKey = itemKey.serialize() + this.contextKey(preview);
1569
+ const model = await this.PERSISTENT_CACHE.getOrLoad(`item-v3:${AssetLoader.persistentKey(cacheKey)}`, async () => {
1565
1570
  const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1566
1571
  if (!result) return void 0;
1567
1572
  if (result.key.assetType !== "items") return { ...result.asset, key };
1568
- const selected = this.defaultItemModel(result.asset.model, key);
1569
- const modelKey = AssetKey.parse("models", selected.model);
1570
- modelKey.root = key.root;
1571
- const model2 = await this.getRaw(modelKey);
1572
- if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
1573
- return { ...model2, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
1573
+ const load = async (selected) => {
1574
+ if ("parts" in selected) {
1575
+ return { key, parts: await Promise.all(selected.parts.map(load)) };
1576
+ }
1577
+ if ("item" in selected) {
1578
+ const model3 = await this.getItemModel(selected.item, { displayContext: preview.displayContext });
1579
+ if (!model3) throw new Error(`Item ${key.toNamespacedString()} references missing item ${selected.item.toNamespacedString()}`);
1580
+ return model3;
1581
+ }
1582
+ const modelKey = AssetKey.parse("models", selected.model);
1583
+ modelKey.root = key.root;
1584
+ const model2 = await this.getRaw(modelKey);
1585
+ if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
1586
+ return { ...model2, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
1587
+ };
1588
+ return load(this.selectItemModel(result.asset.model, key, preview));
1574
1589
  });
1575
- return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
1590
+ const restore = (model2) => ({
1591
+ ...model2,
1592
+ key: Object.assign(new AssetKey("", ""), model2.key),
1593
+ ...model2.parts && { parts: model2.parts.map(restore) }
1594
+ });
1595
+ return model ? restore(model) : void 0;
1596
+ }
1597
+ static contextIdentifier(id) {
1598
+ if (typeof id !== "string" || !/^(?:[a-z0-9_.-]+:)?[a-z0-9_./-]+$/.test(id)) {
1599
+ throw new Error(`Invalid item-preview identifier: ${id}`);
1600
+ }
1601
+ return id.includes(":") ? id : `minecraft:${id}`;
1602
+ }
1603
+ static snapshotContext(key, context) {
1604
+ const displayContext = context.displayContext ?? "gui" /* GUI */;
1605
+ if (displayContext !== "none" && !Object.values(DisplayPosition).includes(displayContext)) {
1606
+ throw new Error(`Unsupported item display context: ${displayContext}`);
1607
+ }
1608
+ for (const map of [context.properties, context.components, context.itemReferences]) {
1609
+ if (map !== void 0 && (!map || typeof map !== "object" || Array.isArray(map))) {
1610
+ throw new Error("Item-preview properties, components, and references must be objects keyed by identifier");
1611
+ }
1612
+ }
1613
+ const count = context.count === void 0 ? 1 : context.count;
1614
+ if (!Number.isSafeInteger(count) || count < 0) throw new Error("Item-preview count must be a nonnegative safe integer");
1615
+ const properties = {};
1616
+ for (const [id, value] of Object.entries(context.properties ?? {})) {
1617
+ const property = this.contextIdentifier(id);
1618
+ if (!["boolean", "string", "number"].includes(typeof value) || typeof value === "number" && !Number.isFinite(value)) {
1619
+ throw new Error(`Item-preview property ${property} must be a boolean, string, or finite number`);
1620
+ }
1621
+ if (Object.prototype.hasOwnProperty.call(properties, property)) throw new Error(`Duplicate item-preview property: ${property}`);
1622
+ properties[property] = value;
1623
+ }
1624
+ const components = {};
1625
+ for (const [id, value] of Object.entries(context.components ?? {})) {
1626
+ const component = this.contextIdentifier(id);
1627
+ if (Object.prototype.hasOwnProperty.call(components, component)) throw new Error(`Duplicate item-preview component: ${component}`);
1628
+ components[component] = this.snapshotJson(value);
1629
+ }
1630
+ const itemReferences = {};
1631
+ for (const [id, value] of Object.entries(context.itemReferences ?? {})) {
1632
+ const reference = this.contextIdentifier(id);
1633
+ if (!isAssetKey(value) || value.assetType !== "models" || value.type !== "item") {
1634
+ throw new Error(`Item-preview reference ${reference} must be an item-model AssetKey`);
1635
+ }
1636
+ this.contextIdentifier(`${value.namespace}:${value.path}`);
1637
+ if (Object.prototype.hasOwnProperty.call(itemReferences, reference)) throw new Error(`Duplicate item-preview reference: ${reference}`);
1638
+ itemReferences[reference] = Object.assign(new AssetKey("", ""), value, { root: value.root ?? key.root });
1639
+ }
1640
+ return { displayContext, properties, components, count, itemReferences };
1641
+ }
1642
+ static contextKey(context) {
1643
+ const itemReferences = Object.fromEntries(Object.entries(context.itemReferences).map(([id, key]) => [id, key.serialize()]));
1644
+ return `|item-v3:${JSON.stringify(this.snapshotJson({ ...context, itemReferences }))}`;
1576
1645
  }
1577
- // Item previews use the GUI context, false conditions, and zero numeric properties.
1578
- static defaultItemModel(node, key) {
1646
+ static snapshotJson(value, ancestors = /* @__PURE__ */ new Set()) {
1647
+ if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) return value;
1648
+ if (typeof value !== "object" || ancestors.has(value) || !Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
1649
+ throw new Error("Item-preview components must contain finite JSON values without circular references");
1650
+ }
1651
+ ancestors.add(value);
1652
+ const copy = Array.isArray(value) ? Array.from(value, (entry) => this.snapshotJson(entry, ancestors)) : Object.fromEntries(Object.keys(value).sort().map((key) => [key, this.snapshotJson(value[key], ancestors)]));
1653
+ ancestors.delete(value);
1654
+ return copy;
1655
+ }
1656
+ static propertyValue(node, context) {
1657
+ const kind = node.type.replace(/^minecraft:/, "");
1658
+ const property = node.property ? this.contextIdentifier(node.property) : void 0;
1659
+ if (kind === "select" && property === "minecraft:display_context") return context.displayContext;
1660
+ if (property && Object.prototype.hasOwnProperty.call(context.properties, property)) return context.properties[property];
1661
+ const fallback = kind === "condition" ? false : kind === "range_dispatch" ? 0 : void 0;
1662
+ const component = (id) => context.components[this.contextIdentifier(id)];
1663
+ if (property === "minecraft:custom_model_data") {
1664
+ const index = node.index ?? 0;
1665
+ if (!Number.isSafeInteger(index) || index < 0) throw new Error("Item-model custom_model_data index must be a nonnegative integer");
1666
+ const data = component("custom_model_data");
1667
+ if (data === void 0) return fallback;
1668
+ if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("Item-preview custom_model_data must be an object");
1669
+ const field = kind === "condition" ? "flags" : kind === "select" ? "strings" : "floats";
1670
+ const values = data[field];
1671
+ if (values === void 0) return fallback;
1672
+ if (!Array.isArray(values)) throw new Error(`Item-preview custom_model_data.${field} must be an array`);
1673
+ return index < values.length ? values[index] : fallback;
1674
+ }
1675
+ if (kind === "condition" && property === "minecraft:has_component") {
1676
+ if (node.ignore_default) throw new Error("Item-preview has_component with ignore_default requires an explicit properties override; item defaults are unavailable");
1677
+ return Object.prototype.hasOwnProperty.call(context.components, this.contextIdentifier(node.component));
1678
+ }
1679
+ if (kind === "select") {
1680
+ switch (property) {
1681
+ case "minecraft:component":
1682
+ return component(node.component);
1683
+ case "minecraft:block_state": {
1684
+ const state = component("block_state");
1685
+ if (state === void 0) return void 0;
1686
+ if (!state || typeof state !== "object" || Array.isArray(state)) throw new Error("Item-preview block_state must be an object");
1687
+ if (typeof node.block_state_property !== "string") throw new Error("Item-model block_state requires block_state_property");
1688
+ return Object.prototype.hasOwnProperty.call(state, node.block_state_property) ? state[node.block_state_property] : void 0;
1689
+ }
1690
+ case "minecraft:charge_type": {
1691
+ const projectiles = component("charged_projectiles");
1692
+ if (projectiles === void 0) return "none";
1693
+ if (!Array.isArray(projectiles)) throw new Error("Item-preview charged_projectiles must be an array of item stacks");
1694
+ const ids = projectiles.map((stack) => {
1695
+ if (!stack || typeof stack !== "object" || Array.isArray(stack)) throw new Error("Item-preview charged_projectiles must contain item-stack objects");
1696
+ return this.contextIdentifier(stack.id);
1697
+ });
1698
+ return !ids.length ? "none" : ids.includes("minecraft:firework_rocket") ? "rocket" : "arrow";
1699
+ }
1700
+ }
1701
+ }
1702
+ if (kind === "range_dispatch" && (property === "minecraft:damage" || property === "minecraft:count")) {
1703
+ const damage = property === "minecraft:damage";
1704
+ const maximumComponent = component(damage ? "max_damage" : "max_stack_size");
1705
+ const maximum = maximumComponent === void 0 ? damage ? 0 : 1 : maximumComponent;
1706
+ const damageComponent = component("damage");
1707
+ const value = damage ? damageComponent === void 0 ? 0 : damageComponent : context.count;
1708
+ if (typeof value !== "number" || typeof maximum !== "number" || maximum < 0) throw new Error(`Item-preview ${property} requires numeric components and a nonnegative maximum`);
1709
+ const clamped = Math.max(0, Math.min(maximum, value));
1710
+ return node.normalize === false ? clamped : clamped / maximum;
1711
+ }
1712
+ return fallback;
1713
+ }
1714
+ static selectItemModel(node, key, context) {
1579
1715
  if (!node || typeof node.type !== "string") {
1580
1716
  throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
1581
1717
  }
1582
1718
  switch (node.type.replace(/^minecraft:/, "")) {
1719
+ case "composite":
1720
+ if (Array.isArray(node.models)) return { parts: node.models.map((child) => this.selectItemModel(child, key, context)) };
1721
+ break;
1722
+ case "bundle/selected_item": {
1723
+ const item = context.itemReferences["minecraft:bundle/selected_item"];
1724
+ return item ? { item } : { parts: [] };
1725
+ }
1583
1726
  case "model":
1584
1727
  if (typeof node.model === "string" && node.model) return { model: node.model, tints: node.tints };
1585
1728
  break;
@@ -1600,17 +1743,29 @@ var init_Models = __esm({
1600
1743
  }
1601
1744
  throw new Error(`Unsupported special item renderer ${special.type} for ${key.toNamespacedString()}`);
1602
1745
  }
1603
- case "condition":
1604
- return this.defaultItemModel(node.on_false, key);
1746
+ case "condition": {
1747
+ const value = this.propertyValue(node, context);
1748
+ if (typeof value !== "boolean") throw new Error(`Item-preview condition ${node.property} requires a boolean`);
1749
+ return this.selectItemModel(value ? node.on_true : node.on_false, key, context);
1750
+ }
1605
1751
  case "select": {
1606
- const selected = node.property?.replace(/^minecraft:/, "") === "display_context" ? node.cases?.find((entry) => Array.isArray(entry.when) ? entry.when.includes("gui") : entry.when === "gui")?.model : void 0;
1607
- return this.defaultItemModel(selected ?? node.fallback, key);
1752
+ const value = this.propertyValue(node, context);
1753
+ const component = node.property && this.contextIdentifier(node.property) === "minecraft:component";
1754
+ if (!component && value !== void 0 && typeof value !== "string") throw new Error(`Item-preview selector ${node.property} requires a string`);
1755
+ const matches = (candidate) => component ? JSON.stringify(this.snapshotJson(candidate)) === JSON.stringify(this.snapshotJson(value)) : candidate === value;
1756
+ const selected = value === void 0 ? void 0 : node.cases?.find((entry) => matches(entry.when) || Array.isArray(entry.when) && entry.when.some(matches))?.model;
1757
+ return this.selectItemModel(selected ?? node.fallback, key, context);
1608
1758
  }
1609
1759
  case "range_dispatch": {
1760
+ const value = this.propertyValue(node, context);
1761
+ if (typeof value !== "number") throw new Error(`Item-preview range ${node.property} requires a number`);
1762
+ if (Number.isNaN(value)) return this.selectItemModel(node.fallback, key, context);
1763
+ const scaled = value * (node.scale ?? 1);
1764
+ if (!Number.isFinite(scaled)) throw new Error(`Item-preview range ${node.property} requires a finite value and scale`);
1610
1765
  const selected = node.entries?.reduce((match, entry) => {
1611
- return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
1766
+ return entry.threshold <= scaled && (!match || entry.threshold >= match.threshold) ? entry : match;
1612
1767
  }, void 0);
1613
- return this.defaultItemModel(selected?.model ?? node.fallback, key);
1768
+ return this.selectItemModel(selected?.model ?? node.fallback, key, context);
1614
1769
  }
1615
1770
  }
1616
1771
  throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
@@ -1637,25 +1792,28 @@ var init_Models = __esm({
1637
1792
  }
1638
1793
  /**
1639
1794
  * Loads a model and resolves its parent chain. Returns `undefined` when the model is missing.
1640
- * Item keys use GUI context, false conditions, and zero numeric properties.
1795
+ * Item keys default to GUI context and a stack count of 1. Unresolved conditions are false and numeric properties are zero.
1796
+ * Pass `context` to supply component values, property overrides, and item references for a preview.
1797
+ * Composite items retain independently merged children in `ItemModel.parts`.
1641
1798
  *
1642
1799
  * @param key - Model key, for example `AssetKey.parse("models", "minecraft:item/diamond_sword")`.
1643
1800
  */
1644
- static async getMerged(key) {
1801
+ static async getMerged(key, context = {}) {
1645
1802
  if (!key.assetType) {
1646
1803
  key.assetType = "models";
1647
1804
  }
1648
1805
  if (!key.extension) {
1649
1806
  key.extension = ".json";
1650
1807
  }
1651
- const keyStr = key.serialize();
1808
+ const preview = this.snapshotContext(key, context);
1809
+ const keyStr = key.serialize() + (key.type === "item" ? this.contextKey(preview) : "");
1652
1810
  return Caching.mergedModelCache.get(keyStr, (k) => {
1653
- return _Models.loadAndMerge(key);
1811
+ return _Models.loadAndMerge(key, preview);
1654
1812
  });
1655
1813
  }
1656
1814
  /** Alias for {@link getMerged}. */
1657
- static async get(key) {
1658
- return this.getMerged(key);
1815
+ static async get(key, context = {}) {
1816
+ return this.getMerged(key, context);
1659
1817
  }
1660
1818
  /** Clears persisted models. Use {@link Caching.clear} to also discard in-memory assets. */
1661
1819
  static async clearCache() {
@@ -5485,22 +5643,45 @@ var init_ModelObject = __esm({
5485
5643
  this.originalModel = originalModel;
5486
5644
  this.isModelObject = true;
5487
5645
  this.specialMaterials = /* @__PURE__ */ new Map();
5646
+ this.geometries = /* @__PURE__ */ new Set();
5488
5647
  this.meshesCreated = false;
5489
5648
  this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
5490
- if (originalModel.special) this.options.instanceMeshes = false;
5649
+ if (originalModel.special || originalModel.parts) this.options.instanceMeshes = false;
5491
5650
  if (this.options.tints) this.options.tints = { ...this.options.tints };
5492
5651
  this.addEventListener("added", () => this.updateAnimationSubscription());
5493
5652
  this.addEventListener("removed", () => this.updateAnimationSubscription());
5494
5653
  }
5495
5654
  async init() {
5655
+ const parts = this.originalModel.parts;
5656
+ if (parts) {
5657
+ try {
5658
+ for (const part of parts) {
5659
+ const object3 = new _ModelObject(part, { ...this.options, instanceMeshes: false });
5660
+ this.add(object3);
5661
+ await object3.init();
5662
+ }
5663
+ let order = 0;
5664
+ this.iterateAllMeshes((mesh) => {
5665
+ mesh.renderOrder = order++;
5666
+ for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
5667
+ material.transparent = true;
5668
+ }
5669
+ });
5670
+ } catch (error) {
5671
+ this.disposeAndRemoveAllChildren();
5672
+ throw error;
5673
+ }
5674
+ this.notifyDirty();
5675
+ return;
5676
+ }
5496
5677
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
5497
5678
  const special = this.originalModel.special;
5498
5679
  if (special) {
5499
- const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
5680
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
5500
5681
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three25.Matrix4();
5501
5682
  transform.multiply(new import_three25.Matrix4().makeTranslation(-8, -8, -8));
5502
5683
  try {
5503
- for (const part of parts) {
5684
+ for (const part of parts2) {
5504
5685
  const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5505
5686
  object3.matrix.copy(transform).multiply(part.transform);
5506
5687
  object3.matrixWorldNeedsUpdate = true;
@@ -5551,6 +5732,7 @@ var init_ModelObject = __esm({
5551
5732
  if (this.atlas.model.elements) {
5552
5733
  this.atlas.model.elements?.forEach((el) => {
5553
5734
  const elGeo = this._getBoxGeometryFromElement(el).clone();
5735
+ this.geometries.add(elGeo);
5554
5736
  if (this.options.cullMask) {
5555
5737
  const indices = Array.from(elGeo.getIndex().array);
5556
5738
  elGeo.setIndex(indices.filter((_, index) => {
@@ -5604,10 +5786,14 @@ var init_ModelObject = __esm({
5604
5786
  let combinedGeo;
5605
5787
  if (allGeos.length > 0) {
5606
5788
  combinedGeo = mergeBufferGeometries(allGeos);
5789
+ for (const geometry of allGeos) {
5790
+ this.geometries.delete(geometry);
5791
+ }
5607
5792
  } else {
5608
5793
  combinedGeo = new import_three25.BoxGeometry(16, 16, 16);
5609
5794
  if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
5610
5795
  }
5796
+ this.geometries.add(combinedGeo);
5611
5797
  combinedGeo.computeBoundingBox();
5612
5798
  let mesh;
5613
5799
  if (this.options.instanceMeshes) {
@@ -5632,6 +5818,9 @@ var init_ModelObject = __esm({
5632
5818
  const mat = Materials.createShadedCanvasMaterial(this.atlas.image.canvas, this.atlas.hasTransparency, false, true);
5633
5819
  this.atlasMaterial = mat;
5634
5820
  this.atlasTexture = mat.uniforms?.map?.value ?? mat.map;
5821
+ if (this.options.displayPosition === "gui" /* GUI */ && this.originalModel.gui_light === "front" /* FRONT */ && mat.uniforms?.SHADE) {
5822
+ mat.uniforms.SHADE.value = false;
5823
+ }
5635
5824
  this.iterateAllMeshes((mesh) => {
5636
5825
  if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
5637
5826
  mesh.material = mat;
@@ -5640,7 +5829,9 @@ var init_ModelObject = __esm({
5640
5829
  }
5641
5830
  }
5642
5831
  updateAnimationSubscription() {
5643
- const active = !!this.parent && (!this.isInstanced || this.instanceCounter > 0);
5832
+ let root = this;
5833
+ while (root.parent && isModelObject(root.parent)) root = root.parent;
5834
+ const active = !!root.parent && (!this.isInstanced || this.instanceCounter > 0);
5644
5835
  if (active && this.atlas?.hasAnimation && this.atlasTexture) {
5645
5836
  if (!this.unsubscribeAtlas) {
5646
5837
  this.atlasTexture.needsUpdate = true;
@@ -5656,6 +5847,9 @@ var init_ModelObject = __esm({
5656
5847
  this.unsubscribeAtlas?.();
5657
5848
  this.unsubscribeAtlas = void 0;
5658
5849
  }
5850
+ for (const child of this.children) {
5851
+ if (isModelObject(child)) child.updateAnimationSubscription();
5852
+ }
5659
5853
  }
5660
5854
  nextInstance() {
5661
5855
  const reference = super.nextInstance();
@@ -5675,6 +5869,8 @@ var init_ModelObject = __esm({
5675
5869
  this.atlasMaterial = void 0;
5676
5870
  for (const material of this.specialMaterials.values()) material.dispose();
5677
5871
  this.specialMaterials.clear();
5872
+ for (const geometry of this.geometries) geometry.dispose();
5873
+ this.geometries.clear();
5678
5874
  super.disposeAndRemoveAllChildren();
5679
5875
  }
5680
5876
  };
@@ -9815,7 +10011,6 @@ init_SceneObject();
9815
10011
  init_Materials();
9816
10012
  init_ModelObject();
9817
10013
  init_DisplayPosition();
9818
- init_GuiLight();
9819
10014
  var GuiObject = class extends SceneObject {
9820
10015
  constructor(textureLayers, options) {
9821
10016
  super({ ...options, instanceMeshes: false, mergeMeshes: false });
@@ -9883,12 +10078,16 @@ var GuiObject = class extends SceneObject {
9883
10078
  mesh2.geometry.computeBoundingBox();
9884
10079
  bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three26.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
9885
10080
  });
9886
- item.position.z = depth - bounds.min.z;
9887
- depth += bounds.max.z - bounds.min.z + 0.01;
10081
+ item.position.z = depth;
10082
+ if (!bounds.isEmpty()) {
10083
+ item.position.z -= bounds.min.z;
10084
+ depth += bounds.max.z - bounds.min.z;
10085
+ this.bounds.expandByPoint(new import_three26.Vector2(bounds.min.x, -bounds.max.y));
10086
+ this.bounds.expandByPoint(new import_three26.Vector2(bounds.max.x, -bounds.min.y));
10087
+ }
10088
+ depth += 0.01;
9888
10089
  this.bounds.expandByPoint(new import_three26.Vector2(x, y));
9889
10090
  this.bounds.expandByPoint(new import_three26.Vector2(x + width2, y + height2));
9890
- this.bounds.expandByPoint(new import_three26.Vector2(bounds.min.x, -bounds.max.y));
9891
- this.bounds.expandByPoint(new import_three26.Vector2(bounds.max.x, -bounds.min.y));
9892
10091
  continue;
9893
10092
  }
9894
10093
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
@@ -9928,15 +10127,13 @@ var GuiObject = class extends SceneObject {
9928
10127
  item.name = `group:${layer.name ?? index}`;
9929
10128
  this.add(item);
9930
10129
  await item.init();
9931
- item.iterateAllMeshes((mesh) => {
9932
- if (!model.special) this.geometries.add(mesh.geometry);
10130
+ const meshes = [];
10131
+ item.iterateAllMeshes((mesh) => meshes.push(mesh));
10132
+ meshes.forEach((mesh, partIndex) => {
9933
10133
  mesh.name = `mesh:${layer.name ?? index}`;
9934
- mesh.renderOrder = index;
10134
+ mesh.renderOrder = index + partIndex / (meshes.length + 1) * 0.5;
9935
10135
  for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
9936
10136
  material.transparent = true;
9937
- if (model.gui_light === "front" /* FRONT */ && material.uniforms?.SHADE) {
9938
- material.uniforms.SHADE.value = false;
9939
- }
9940
10137
  }
9941
10138
  });
9942
10139
  return item;