UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

93 lines (92 loc) 3.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Action_1 = __importDefault(require("./Action")); const ActionGroup_1 = __importDefault(require("./ActionGroup")); const BlockLocation_1 = __importDefault(require("../minecraft/BlockLocation")); const IScriptGenerationContext_1 = require("./IScriptGenerationContext"); class SimulatedPlayerSpawnAction extends Action_1.default { get shortSubjectId() { return "simplayer"; } get typeTitle() { return "Spawn Simulated Player"; } get typeId() { return "test_simulated_player_spawn"; } get title() { let title = this.typeTitle; if (this.location) { title += " " + this.location.toSummary(); } return title; } get location() { return this.getArgumentAsBlockLocation("location"); } set location(location) { if (!location) { this.data["location"] = undefined; } else { this.data["location"] = [location.x, location.y, location.z]; } } validate() { this.validateArgumentIsType("location", "Location"); return true; } getScriptRequirements(options) { return { needsTest: true, }; } getCommandRequirements(options) { return {}; } addCommandLines(lines, indent, options) { let location = this.location; if (!location) { location = new BlockLocation_1.default(0, 0, 0); } location = this.absolutizeBlockLocation(location); ActionGroup_1.default.addLine(lines, indent, "tag @p[l=1] add " + this.getCommandSet()); } run(scope) { if (!scope.test) { scope.addError(this, "Test is not specified"); return; } if (!this.location) { scope.addError(this, "Location is not specified"); return; } const simPlayer = scope.test.spawnSimulatedPlayer(this.location); scope.setState(this.setId, simPlayer); } addScriptLines(lines, options, context, placement) { if (placement === IScriptGenerationContext_1.ScriptGenerationPlacement.inSequence) { let location = this.location; if (!location) { location = new BlockLocation_1.default(0, 0, 0); } ActionGroup_1.default.addLine(lines, context.indent, "const " + this.getScriptSet() + " = " + this.getScriptTest() + ".spawnSimulatedPlayer(new BlockLocation(" + location.x + ", " + location.y + ", " + location.z + '), "' + this.getScriptSet() + '");'); } } } exports.default = SimulatedPlayerSpawnAction;