UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

57 lines (55 loc) 2.19 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const InventorySlot_1 = require("../InventorySlot"); const Log_1 = require("../../core/Log"); const ComponentBase_1 = require("../ComponentBase"); class EntityInventoryComponent extends ComponentBase_1.default { 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; //# sourceMappingURL=../../maps/minecraft/components/EntityInventoryComponent.js.map