@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
95 lines (94 loc) • 3.57 kB
TypeScript
/**
* TraitDetector - Maps native Minecraft components to trait identifiers.
*
* This module analyzes Minecraft Bedrock content (entity/block/item definitions)
* and detects which traits from the Content Meta-Schema would produce similar
* component configurations. This enables reverse-engineering of existing content
* into the simplified meta-schema format.
*
* @see ContentSchemaInferrer.ts for the main orchestrator
* @see IContentMetaSchema.ts for trait type definitions
*/
import { EntityTraitId, BlockTraitId, ItemTraitId, EntityBehaviorPreset } from "./IContentMetaSchema";
/**
* Result of trait detection with confidence scoring.
*/
export interface ITraitDetectionResult<T extends string> {
/** The detected trait ID */
traitId: T;
/** Confidence score 0-1 (1 = perfect match, 0.6 = likely match) */
confidence: number;
/** Components that matched this trait */
matchedComponents: string[];
/** Optional notes about the detection */
notes?: string;
}
/**
* Result of simplified property extraction.
*/
export interface IExtractedProperties {
health?: number;
attackDamage?: number;
movementSpeed?: number;
scale?: number;
followRange?: number;
knockbackResistance?: number;
collisionWidth?: number;
collisionHeight?: number;
families?: string[];
destroyTime?: number;
explosionResistance?: number;
lightEmission?: number;
lightDampening?: number;
friction?: number;
mapColor?: string;
maxStackSize?: number;
durability?: number;
damage?: number;
nutrition?: number;
saturation?: number;
}
/**
* TraitDetector - Detects traits from native Minecraft components.
*/
export default class TraitDetector {
/** Minimum confidence threshold for including a trait */
static readonly DEFAULT_MIN_CONFIDENCE = 0.6;
/**
* Detect entity traits from components.
*/
static detectEntityTraits(components: Record<string, any>, componentGroups?: Record<string, Record<string, any>>, minConfidence?: number): ITraitDetectionResult<EntityTraitId>[];
/**
* Detect behavior presets from components.
*/
static detectBehaviorPresets(components: Record<string, any>, minConfidence?: number): ITraitDetectionResult<EntityBehaviorPreset>[];
/**
* Detect block traits from components.
*/
static detectBlockTraits(components: Record<string, any>, minConfidence?: number): ITraitDetectionResult<BlockTraitId>[];
/**
* Detect item traits from components.
*/
static detectItemTraits(components: Record<string, any>, minConfidence?: number): ITraitDetectionResult<ItemTraitId>[];
/**
* Extract simplified properties from entity components.
*/
static extractEntityProperties(components: Record<string, any>): IExtractedProperties;
/**
* Extract simplified properties from block components.
*/
static extractBlockProperties(components: Record<string, any>): IExtractedProperties;
/**
* Extract simplified properties from item components.
*/
static extractItemProperties(components: Record<string, any>): IExtractedProperties;
/**
* Resolve conflicting traits by keeping higher confidence ones.
*/
private static resolveConflicts;
/**
* Get components that are NOT explained by any detected trait.
* These should be included as explicit components in the schema.
*/
static getUnexplainedComponents(allComponents: Record<string, any>, detectedTraits: ITraitDetectionResult<string>[]): string[];
}