UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

134 lines (133 loc) 4.5 kB
/** * EntityTextureResolver * * Shared utilities for resolving entity textures from various sources: * - Project items (custom content) * - Vanilla resources (Database/VanillaProjectManager) * - Direct file paths * - URLs * * This centralizes texture resolution logic that was previously duplicated * across ModelViewer, MobViewer, CLI rendering, and MCP server. * * TEXTURE RESOLUTION ORDER: * ------------------------- * 1. Explicit texture data (Uint8Array) if provided * 2. Project item lookup (for custom content) * 3. Entity resource definition (client_entity -> textures map) * 4. Vanilla resources (built-in Minecraft textures) * 5. Fallback path construction * * TEXTURE PATH FORMATS: * --------------------- * Minecraft uses several path formats: * - "textures/entity/pig/pig" (resource pack relative, no extension) * - "textures/entity/pig/pig.png" (with extension) * - Full paths for custom content * * Last Updated: December 2025 */ import { IGeometry } from "./IModelGeometry"; import ModelGeometryDefinition from "./ModelGeometryDefinition"; import Project from "../app/Project"; import ProjectItem from "../app/ProjectItem"; import IFile from "../storage/IFile"; /** * Result of resolving an entity's textures and geometry */ export interface IResolvedEntityAssets { /** The geometry definition */ geometry?: IGeometry; /** The model definition container */ modelDefinition?: ModelGeometryDefinition; /** Geometry ID used */ geometryId?: string; /** Resolved texture path (without extension) */ texturePath?: string; /** Full URL to texture (for web loading) */ textureUrl?: string; /** Texture image data as bytes */ textureData?: Uint8Array; /** Texture dimensions from geometry description */ textureWidth?: number; /** Texture dimensions from geometry description */ textureHeight?: number; /** Source of the resolved assets */ source: "project" | "vanilla" | "url" | "data" | "none"; /** Any warnings or errors during resolution */ warnings?: string[]; } /** * Options for asset resolution */ export interface IEntityAssetResolveOptions { /** Entity type ID (e.g., "pig" or "minecraft:pig") */ entityTypeId?: string; /** Specific geometry ID to use */ geometryId?: string; /** Variant key for entities with multiple textures (e.g., "default", "warm") */ variantKey?: string; /** Direct geometry definition */ geometry?: IGeometry; /** Direct model definition */ modelDefinition?: ModelGeometryDefinition; /** Direct texture data */ textureData?: Uint8Array; /** Direct texture URL */ textureUrl?: string; /** Project to search for custom content */ project?: Project; /** Whether to skip vanilla resource lookup */ skipVanilla?: boolean; } export default class EntityTextureResolver { /** * Resolve all assets (geometry + texture) for an entity. * This is the main entry point for asset resolution. */ static resolveEntityAssets(options: IEntityAssetResolveOptions): Promise<IResolvedEntityAssets>; /** * Resolve texture from a project item. * Finds the related texture file for a model or entity definition. */ static resolveTextureForProjectItem(projectItem: ProjectItem, project?: Project): Promise<{ textureData?: Uint8Array; texturePath?: string; }>; /** * Load texture data from a URL. */ static loadTextureFromUrl(url: string): Promise<Uint8Array | null>; /** * Load texture data from a file. */ static loadTextureFromFile(file: IFile): Promise<Uint8Array | null>; /** * Canonicalize a texture path by removing extensions and normalizing slashes. */ static canonicalizeTexturePath(path: string): string; /** * Build a URL for a vanilla texture path. */ static buildVanillaTextureUrl(texturePath: string): string; /** * Resolve assets from a project. */ private static _resolveFromProject; /** * Find geometry in a project by geometry ID. */ private static _findGeometryInProject; /** * Find texture in a project by texture path. */ private static _findTextureInProject; /** * Resolve assets from vanilla resources. */ private static _resolveFromVanilla; /** * Extract texture dimensions from geometry description. */ private static _extractTextureDimensions; }