UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

90 lines (89 loc) 3.25 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 }); const Location_1 = __importDefault(require("./Location")); const Log_1 = __importDefault(require("./../core/Log")); const ComponentizedBase_1 = __importDefault(require("./ComponentizedBase")); const Rotation_1 = __importDefault(require("./Rotation")); const ste_events_1 = require("ste-events"); class Entity extends ComponentizedBase_1.default { _typeId = ""; location = new Location_1.default(); rotation = new Rotation_1.default(); tags = []; definitions = []; customModel; /** Pre-transformed geometry that takes precedence over customModel.defaultGeometry. * Set by VanillaProjectManager after applying VanillaGeometryTransforms. */ customGeometry; customTextureData; customTextureUrl; customTintColor; customIgnoreAlpha; _onPropertyChanged = new ste_events_1.EventDispatcher(); get onPropertyChanged() { return this._onPropertyChanged.asEvent(); } get typeId() { return this._typeId; } set typeId(newTypeId) { this._typeId = newTypeId; } getProperty(name) { return this.getComponentProperty(name); } ensureProperty(name) { return this.addComponentProperty(name); } addProperty(name) { return this.addComponentProperty(name); } notifyComponentPropertyChanged(property) { this._onPropertyChanged.dispatch(this, property); } loadDefinitionsFromNbtTag(tagsTag) { const entityDefinitionChildren = tagsTag.getTagChildren(); const newDefinitions = []; for (let i = 0; i < entityDefinitionChildren.length; i++) { const definitionChild = entityDefinitionChildren[i]; newDefinitions.push(definitionChild.valueAsString); } this.definitions = newDefinitions; } loadTagsFromNbtTag(tagsTag) { const entityTagChildren = tagsTag.getTagChildren(); const newTags = []; for (let i = 0; i < entityTagChildren.length; i++) { const tagChild = entityTagChildren[i]; newTags.push(tagChild.valueAsString); } this.tags = newTags; } loadRotationFromNbtTag(rotationTag) { const entityRotChildren = rotationTag.getTagChildren(); if (entityRotChildren.length === 2) { this.rotation.yaw = entityRotChildren[0].valueAsFloat; this.rotation.pitch = entityRotChildren[1].valueAsFloat; } else { Log_1.default.debugAlert("Unexpected rotation"); } } loadLocationFromNbtTag(locationTag) { const tagChildren = locationTag.getTagChildren(); if (tagChildren.length === 3) { this.location.x = tagChildren[0].valueAsFloat; this.location.y = tagChildren[1].valueAsFloat; this.location.z = tagChildren[2].valueAsFloat; } else { Log_1.default.debugAlert("Unexpected pos"); } } } exports.default = Entity;