UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

98 lines (97 loc) 3.96 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.openSampleCommand = exports.OpenSampleCommand = void 0; const IToolCommand_1 = require("../IToolCommand"); const HttpStorage_1 = __importDefault(require("../../../storage/HttpStorage")); const Project_1 = __importDefault(require("../../Project")); const SAMPLES = { vanilla: { path: "/res/latest/van/serve/", title: "Vanilla Minecraft", description: "The complete vanilla Minecraft behavior pack + resource pack (2000+ files)", }, "vanilla-bp": { path: "/res/latest/van/serve/behavior_pack/", title: "Vanilla Behavior Pack", description: "Vanilla entities, items, recipes, loot tables, spawn rules, and biomes", }, "vanilla-rp": { path: "/res/latest/van/serve/resource_pack/", title: "Vanilla Resource Pack", description: "Vanilla textures, models, animations, and sounds", }, }; class OpenSampleCommand extends IToolCommand_1.ToolCommandBase { metadata = { name: "open-sample", description: "Open a built-in sample project (e.g., vanilla Minecraft content)", aliases: ["sample", "vanilla"], category: "Project", arguments: [ { name: "sample", description: "Sample to open: vanilla, vanilla-bp, vanilla-rp", type: "choice", required: false, defaultValue: "vanilla-bp", }, ], flags: [], isWriteCommand: false, examples: [ "/open-sample", "/open-sample vanilla-bp", "/open-sample vanilla", "/open-sample vanilla-rp", ], }; async execute(context, args, _flags) { const sampleId = (args[0] || "vanilla-bp").toLowerCase(); const sample = SAMPLES[sampleId]; if (!sample) { const available = Object.keys(SAMPLES).join(", "); return this.error("SAMPLE_NOT_FOUND", `Sample '${sampleId}' not found. Available: ${available}`); } if (!context.creatorTools) { return this.error("NO_CREATOR_TOOLS", "No CreatorTools instance available."); } context.output.info(`Loading ${sample.title}...`); try { const contentStorage = HttpStorage_1.default.get(sample.path); await contentStorage.rootFolder.load(); const newProject = new Project_1.default(context.creatorTools, sample.title, null); newProject.setProjectFolder(contentStorage.rootFolder); newProject.readOnlySafety = true; await newProject.attemptToLoadPreferences(); await newProject.inferProjectItemsFromFiles(true); context.project = newProject; const itemCount = newProject.items.length; context.output.success(`Loaded ${sample.title} with ${itemCount} items`); return this.success(`Loaded ${sample.title}`, { sampleId, itemCount, title: sample.title, }); } catch (error) { const message = error instanceof Error ? error.message : String(error); return this.error("LOAD_ERROR", `Failed to load sample: ${message}`); } } async getCompletions(_context, _args, partialArg, argIndex) { if (argIndex === 0) { const all = Object.keys(SAMPLES); if (!partialArg) return all; return all.filter((s) => s.startsWith(partialArg.toLowerCase())); } return []; } } exports.OpenSampleCommand = OpenSampleCommand; exports.openSampleCommand = new OpenSampleCommand();