@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
235 lines (234 loc) • 8.03 kB
TypeScript
/**
* ContentSchemaInferrer - Analyzes Minecraft content and infers meta-schema representation.
*
* This module is the inverse of ContentGenerator: instead of generating native Minecraft
* content from a meta-schema, it analyzes existing native content and produces an
* equivalent IMinecraftContentDefinition.
*
* Use cases:
* 1. Import existing projects into simplified format
* 2. Generate documentation for addons
* 3. Enable AI-assisted editing of existing content
* 4. Modernize legacy content with trait-based improvements
*
* @see ContentGenerator.ts for the forward transformation
* @see TraitDetector.ts for trait detection logic
* @see IContentMetaSchema.ts for schema type definitions
*/
import Project from "../app/Project";
import ProjectItem from "../app/ProjectItem";
import EntityTypeDefinition from "./EntityTypeDefinition";
import BlockTypeDefinition from "./BlockTypeDefinition";
import ItemTypeDefinition from "./ItemTypeDefinition";
import { ITraitDetectionResult } from "./TraitDetector";
import { IMinecraftContentDefinition, IEntityTypeDefinition, IBlockTypeDefinition, IItemTypeDefinition, IRecipeDefinition, ILootTableDefinition, ISpawnRuleDefinition, IFeatureDefinition, EntityTraitId } from "./IContentMetaSchema";
/**
* Options for controlling schema inference behavior.
*/
export interface IInferrerOptions {
/** Minimum confidence threshold for trait detection (0-1). Default: 0.6 */
minTraitConfidence?: number;
/** Include raw components not explained by traits. Default: true */
includeRawComponents?: boolean;
/** Try to detect namespace from identifiers. Default: true */
inferNamespace?: boolean;
/** Include behavior presets in addition to traits. Default: true */
includeBehaviorPresets?: boolean;
/** Include component groups as raw data. Default: false */
includeComponentGroups?: boolean;
/** Include events as raw data. Default: false */
includeEvents?: boolean;
}
/**
* Default inferrer options.
*/
export declare const DEFAULT_INFERRER_OPTIONS: Required<IInferrerOptions>;
/**
* Extended result with inference metadata.
*/
export interface IInferenceResult {
/** The inferred content definition */
definition: IMinecraftContentDefinition;
/** Metadata about the inference process */
metadata: IInferenceMetadata;
}
/**
* Metadata about how the schema was inferred.
*/
export interface IInferenceMetadata {
/** Number of entities analyzed */
entitiesAnalyzed: number;
/** Number of blocks analyzed */
blocksAnalyzed: number;
/** Number of items analyzed */
itemsAnalyzed: number;
/** Number of spawn rules analyzed */
spawnRulesAnalyzed?: number;
/** Number of loot tables analyzed */
lootTablesAnalyzed?: number;
/** Number of recipes analyzed */
recipesAnalyzed?: number;
/** Number of features analyzed */
featuresAnalyzed?: number;
/** Warnings encountered during inference */
warnings: string[];
/** Traits detected across all content */
allDetectedTraits: {
entity: Record<string, number>;
block: Record<string, number>;
item: Record<string, number>;
};
/** Time taken for inference in milliseconds */
inferenceTimeMs: number;
}
/**
* ContentSchemaInferrer - Main class for analyzing content and inferring schema.
*/
export default class ContentSchemaInferrer {
private _options;
constructor(options?: IInferrerOptions);
/**
* Infer a content schema from a project.
*/
inferFromProject(project: Project): Promise<IInferenceResult>;
/**
* Infer entity type definition from a project item.
*/
inferEntityFromItem(item: ProjectItem): Promise<{
definition: IEntityTypeDefinition;
detectionDetails: ITraitDetectionResult<EntityTraitId>[];
} | null>;
/**
* Infer entity type from an EntityTypeDefinition.
*/
inferEntityFromDefinition(entityDef: EntityTypeDefinition): {
definition: IEntityTypeDefinition;
detectionDetails: ITraitDetectionResult<EntityTraitId>[];
} | null;
/**
* Infer block type definition from a project item.
*/
inferBlockFromItem(item: ProjectItem): Promise<{
definition: IBlockTypeDefinition;
} | null>;
/**
* Infer block type from a BlockTypeDefinition.
*/
inferBlockFromDefinition(blockDef: BlockTypeDefinition): {
definition: IBlockTypeDefinition;
} | null;
/**
* Infer item type definition from a project item.
*/
inferItemFromItem(item: ProjectItem): Promise<{
definition: IItemTypeDefinition;
} | null>;
/**
* Infer item type from an ItemTypeDefinition.
*/
inferItemFromDefinition(itemDef: ItemTypeDefinition): {
definition: IItemTypeDefinition;
} | null;
/**
* Infer spawn rule definition from a project item.
*/
inferSpawnRuleFromItem(item: ProjectItem): Promise<ISpawnRuleDefinition | null>;
/**
* Extract biome names from a biome filter.
*/
private extractBiomesFromFilter;
/**
* Infer loot table definition from a project item.
*/
inferLootTableFromItem(item: ProjectItem): Promise<ILootTableDefinition | null>;
/**
* Infer recipe definition from a project item.
*/
inferRecipeFromItem(item: ProjectItem): Promise<IRecipeDefinition | null>;
/**
* Infer a shaped recipe.
*/
private inferShapedRecipe;
/**
* Infer a shapeless recipe.
*/
private inferShapelessRecipe;
/**
* Infer a furnace recipe.
*/
private inferFurnaceRecipe;
/**
* Infer a brewing recipe.
*/
private inferBrewingRecipe;
/**
* Infer a smithing recipe.
*/
private inferSmithingRecipe;
/**
* Infer feature definition from a project item.
*/
inferFeatureFromItem(item: ProjectItem): Promise<IFeatureDefinition | null>;
/**
* Infer feature definition from raw data.
*/
private inferFeatureFromData;
/**
* Infer namespace from identifiers.
*/
private inferNamespace;
/**
* Format an ID into a display name.
*/
private formatDisplayName;
/**
* Check if a component is implicit and doesn't need to be included.
*/
private isImplicitComponent;
/**
* Check if a block component is implicit.
*/
private isImplicitBlockComponent;
/**
* Check if an item component is implicit.
*/
private isImplicitItemComponent;
/**
* Infer schema from a project (static convenience method).
*/
static inferFromProject(project: Project, options?: IInferrerOptions): Promise<IInferenceResult>;
/**
* Infer schema from an entity definition (static convenience method).
*/
static inferEntityFromDefinition(entityDef: EntityTypeDefinition, options?: IInferrerOptions): {
definition: IEntityTypeDefinition;
detectionDetails: ITraitDetectionResult<EntityTraitId>[];
} | null;
/**
* Generate a lightweight summary of a project's content for AI context injection.
* This produces an IProjectSchemaSummary that can be sent with chat messages
* without bloating the context window.
*
* @param project The project to summarize
* @returns A summary object suitable for AI context
*/
static inferSummary(project: Project): Promise<{
isSummarized: true;
projectPath?: string;
namespace?: string;
entityCount: number;
blockCount: number;
itemCount: number;
recipeCount: number;
lootTableCount: number;
spawnRuleCount: number;
entityIds?: string[];
blockIds?: string[];
itemIds?: string[];
detectedEntityTraits?: string[];
detectedBlockTraits?: string[];
detectedItemTraits?: string[];
recentValidationIssues?: string[];
fullSchemaAvailableViaTool: "getEffectiveContentSchema";
}>;
}