@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
59 lines (58 loc) • 2.31 kB
JavaScript
;
// 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 InventorySlot_1 = __importDefault(require("../InventorySlot"));
const Log_1 = __importDefault(require("../../core/Log"));
const ComponentBase_1 = __importDefault(require("../ComponentBase"));
class EntityInventoryComponent extends ComponentBase_1.default {
slots;
constructor() {
super();
this.slots = {};
}
ensureSlot(slotIndex) {
let slot = this.slots[slotIndex];
if (slot === undefined) {
slot = new InventorySlot_1.default(slotIndex);
this.slots[slotIndex] = slot;
}
return slot;
}
loadFromNbtTag(tag) {
const childSlotTags = tag.getTagChildren();
for (let k = 0; k < childSlotTags.length; k++) {
const childSlotTag = childSlotTags[k];
const slotIndexTag = childSlotTag.find("Slot");
const nameTag = childSlotTag.find("Name");
const countTag = childSlotTag.find("Count");
const wasPickedUpTag = childSlotTag.find("WasPickedUp");
const damageTag = childSlotTag.find("Damage");
if (nameTag !== null &&
nameTag.value !== null &&
countTag !== null &&
countTag !== null &&
damageTag !== null &&
damageTag.value !== null &&
wasPickedUpTag !== null &&
wasPickedUpTag.value !== null) {
let slotIndex = k;
if (slotIndexTag !== null) {
slotIndex = slotIndexTag.valueAsInt;
}
const slot = this.ensureSlot(slotIndex);
slot.name = nameTag.valueAsString;
slot.count = countTag.valueAsInt;
slot.wasPickedUp = wasPickedUpTag.valueAsBoolean;
slot.damage = damageTag.valueAsInt;
}
else {
Log_1.default.fail("Unexpected inventory item in structure.");
}
}
}
}
exports.default = EntityInventoryComponent;