@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
112 lines (110 loc) • 3.46 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const NbtBinaryTag_1 = require("./NbtBinaryTag");
const IBlockTypePropertyData_1 = require("./IBlockTypePropertyData");
class BlockProperty {
constructor(block) {
this._nbtType = null;
this._block = block;
}
static getBlockPropertyTypeByName(name) {
switch (this.name) {
case "direction":
case "age":
case "stage":
return IBlockTypePropertyData_1.BlockPropertyType.int;
case "leaves":
case "damage":
return IBlockTypePropertyData_1.BlockPropertyType.stringEnum;
}
throw new Error();
}
get type() {
if (typeof this._value === "string") {
return IBlockTypePropertyData_1.BlockPropertyType.string;
}
else if (typeof this._value === "number") {
return IBlockTypePropertyData_1.BlockPropertyType.int;
}
else if (typeof this._value === "boolean") {
return IBlockTypePropertyData_1.BlockPropertyType.boolean;
}
else {
return IBlockTypePropertyData_1.BlockPropertyType.int;
}
}
get nbtType() {
if (this._nbtType === null) {
if (typeof this._value === "string") {
return NbtBinaryTag_1.NbtTagType.string;
}
else if (typeof this._value === "number") {
return NbtBinaryTag_1.NbtTagType.int;
}
else if (typeof this._value === "boolean") {
return NbtBinaryTag_1.NbtTagType.byte;
}
else {
return NbtBinaryTag_1.NbtTagType.byte;
}
}
return this._nbtType;
}
set nbtType(newType) {
this._nbtType = newType;
}
get value() {
return this._value;
}
asBoolean(defaultVal) {
if (this._value === null || this._value === undefined) {
return defaultVal;
}
if (typeof this._value === "boolean") {
return this._value;
}
else if (typeof this._value === "number") {
return this._value !== 0;
}
else if (typeof this._value === "string") {
return this._value === "true" || this._value === "1";
}
return defaultVal;
}
asString(defaultVal) {
if (this._value === null || this._value === undefined) {
return defaultVal;
}
return this._value.toString();
}
asNumber(defaultVal) {
if (this._value === null || this._value === undefined) {
return defaultVal;
}
if (typeof this._value === "number") {
return this._value;
}
else if (typeof this._value === "string") {
return parseInt(this._value);
}
else if (typeof this._value === "boolean") {
if (this._value) {
return 1;
}
else {
return 0;
}
}
return defaultVal;
}
set value(newValue) {
if (this._value !== newValue) {
this._value = newValue;
this._block._notifyPropertyChanged(this);
}
}
}
exports.default = BlockProperty;
//# sourceMappingURL=../maps/minecraft/BlockProperty.js.map