UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

84 lines (82 loc) 2.93 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const Location_1 = require("./Location"); const Log_1 = require("./../core/Log"); const ComponentizedBase_1 = require("./ComponentizedBase"); const Rotation_1 = require("./Rotation"); const ste_events_1 = require("ste-events"); class Entity extends ComponentizedBase_1.default { constructor() { super(...arguments); this._typeId = ""; this.location = new Location_1.default(null, null, null); this.rotation = new Rotation_1.default(null, null); this.tags = []; this.definitions = []; this._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; //# sourceMappingURL=../maps/minecraft/Entity.js.map