"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _ActorItem_identifier, _ActorItem_nbtRoot, _ActorItem_dynamicProperties;
Object.defineProperty(exports, "__esModule", { value: true });
const Utilities_1 = require("../core/Utilities");
const NbtBinary_1 = require("./NbtBinary");
const NbtBinaryTag_1 = require("./NbtBinaryTag");
class ActorItem {
    constructor(identifier, keyData) {
        _ActorItem_identifier.set(this, void 0);
        _ActorItem_nbtRoot.set(this, void 0);
        _ActorItem_dynamicProperties.set(this, {});
        this.armorItems = [];
        this.chestItems = [];
        this.attributes = [];
        __classPrivateFieldSet(this, _ActorItem_identifier, identifier, "f");
        const actorStorage = new NbtBinary_1.default();
        actorStorage.context = identifier;
        actorStorage.fromBinary(keyData, true, false, 0, true);
        if (actorStorage.singleRoot) {
            __classPrivateFieldSet(this, _ActorItem_nbtRoot, actorStorage.singleRoot, "f");
            this.loadFromNbt();
        }
    }
    loadFromNbt() {
        if (!__classPrivateFieldGet(this, _ActorItem_nbtRoot, "f")) {
            return;
        }
        const root = __classPrivateFieldGet(this, _ActorItem_nbtRoot, "f");
        let tag = root.find("Armor");
        if (tag !== null) {
            const children = tag.getTagChildren();
            this.armorItems = [];
            for (let i = 0; i < children.length; i++) {
                const childTag = children[i];
                const countTag = childTag.find("Count");
                const damageTag = childTag.find("Damage");
                const nameTag = childTag.find("Name");
                const wasPickedUpTag = childTag.find("WasPickedUp");
                if (countTag && damageTag && nameTag && wasPickedUpTag) {
                    this.armorItems.push({
                        count: countTag.valueAsInt,
                        damage: damageTag.valueAsInt,
                        name: nameTag.valueAsString,
                        wasPickedUp: wasPickedUpTag.valueAsBoolean,
                    });
                }
            }
        }
        tag = root.find("ChestItems");
        if (tag !== null) {
            const children = tag.getTagChildren();
            this.armorItems = [];
            for (let i = 0; i < children.length; i++) {
                const childTag = children[i];
                const countTag = childTag.find("Count");
                const damageTag = childTag.find("Damage");
                const nameTag = childTag.find("Name");
                const slotTag = childTag.find("Slot");
                const wasPickedUpTag = childTag.find("WasPickedUp");
                if (countTag && damageTag && nameTag && slotTag && wasPickedUpTag) {
                    this.chestItems.push({
                        count: countTag.valueAsInt,
                        damage: damageTag.valueAsInt,
                        name: nameTag.valueAsString,
                        slot: slotTag.valueAsInt,
                        wasPickedUp: wasPickedUpTag.valueAsBoolean,
                    });
                }
            }
        }
        tag = root.find("Attributes");
        if (tag !== null) {
            const children = tag.getTagChildren();
            this.attributes = [];
            for (let i = 0; i < children.length; i++) {
                const childTag = children[i];
                const baseTag = childTag.find("Base");
                const currentTag = childTag.find("Current");
                const defaultMaxTag = childTag.find("DefaultMax");
                const defaultMinTag = childTag.find("DefaultMin");
                const maxTag = childTag.find("Max");
                const minTag = childTag.find("Min");
                const nameTag = childTag.find("Name");
                if (baseTag && currentTag && nameTag && defaultMaxTag && defaultMinTag && maxTag && minTag) {
                    this.attributes.push({
                        base: baseTag.valueAsInt,
                        current: currentTag.valueAsInt,
                        defaultMax: defaultMaxTag.valueAsInt,
                        defaultMin: defaultMinTag.valueAsInt,
                        max: maxTag.valueAsInt,
                        min: minTag.valueAsInt,
                        name: nameTag.valueAsString,
                    });
                }
            }
        }
        tag = root.find("DynamicProperties");
        if (tag !== null) {
            const children = tag.getTagChildren();
            __classPrivateFieldSet(this, _ActorItem_dynamicProperties, {}, "f");
            for (const child of children) {
                if (child.name && Utilities_1.default.isValidUuid(child.name)) {
                    __classPrivateFieldGet(this, _ActorItem_dynamicProperties, "f")[child.name] = {};
                    const bpChildren = child.getTagChildren();
                    for (const propChild of bpChildren) {
                        if (propChild.name && propChild.type === NbtBinaryTag_1.NbtTagType.string) {
                            __classPrivateFieldGet(this, _ActorItem_dynamicProperties, "f")[child.name][propChild.name] = propChild.valueAsString;
                        }
                    }
                }
            }
        }
        tag = root.find("AttackTime");
        if (tag !== null) {
            this.attackTime = tag.valueAsInt;
        }
        tag = root.find("Air");
        if (tag !== null) {
            this.air = tag.valueAsInt;
        }
        tag = root.find("BodyRot");
        if (tag !== null) {
            this.bodyRot = tag.valueAsFloat;
        }
        tag = root.find("Chested");
        if (tag !== null) {
            this.chested = tag.valueAsBoolean;
        }
        tag = root.find("Color");
        if (tag !== null) {
            this.color = tag.valueAsInt;
        }
        tag = root.find("Color2");
        if (tag !== null) {
            this.color2 = tag.valueAsInt;
        }
        tag = root.find("Dead");
        if (tag !== null) {
            this.dead = tag.valueAsBoolean;
        }
        tag = root.find("DeathTime");
        if (tag !== null) {
            this.deathTime = tag.valueAsInt;
        }
        tag = root.find("FallDistance");
        if (tag !== null) {
            this.fallDistance = tag.valueAsFloat;
        }
        tag = root.find("HasExecuted");
        if (tag !== null) {
            this.hasExecuted = tag.valueAsBoolean;
        }
        tag = root.find("HurtTime");
        if (tag !== null) {
            this.hurtTime = tag.valueAsInt;
        }
        tag = root.find("Invulnerable");
        if (tag !== null) {
            this.invulnerable = tag.valueAsBoolean;
        }
        tag = root.find("IsAngry");
        if (tag !== null) {
            this.isAngry = tag.valueAsBoolean;
        }
        tag = root.find("IsAutonomous");
        if (tag !== null) {
            this.isAutonomous = tag.valueAsBoolean;
        }
        tag = root.find("IsBaby");
        if (tag !== null) {
            this.isBaby = tag.valueAsBoolean;
        }
        tag = root.find("IsEating");
        if (tag !== null) {
            this.isEating = tag.valueAsBoolean;
        }
        tag = root.find("IsGliding");
        if (tag !== null) {
            this.isGliding = tag.valueAsBoolean;
        }
        tag = root.find("IsGlobal");
        if (tag !== null) {
            this.isGliding = tag.valueAsBoolean;
        }
        tag = root.find("IsIllagerCaptain");
        if (tag !== null) {
            this.isIllagerCaptain = tag.valueAsBoolean;
        }
        tag = root.find("IsOrphaned");
        if (tag !== null) {
            this.isOrphaned = tag.valueAsBoolean;
        }
        tag = root.find("IsOutOfControl");
        if (tag !== null) {
            this.isOutOfControl = tag.valueAsBoolean;
        }
        tag = root.find("IsPregnant");
        if (tag !== null) {
            this.isPregnant = tag.valueAsBoolean;
        }
        tag = root.find("IsRoaring");
        if (tag !== null) {
            this.isRoaring = tag.valueAsBoolean;
        }
        tag = root.find("IsScared");
        if (tag !== null) {
            this.isScared = tag.valueAsBoolean;
        }
        tag = root.find("IsStunned");
        if (tag !== null) {
            this.isStunned = tag.valueAsBoolean;
        }
        tag = root.find("IsSwimming");
        if (tag !== null) {
            this.isSwimming = tag.valueAsBoolean;
        }
        tag = root.find("IsTamed");
        if (tag !== null) {
            this.isTamed = tag.valueAsBoolean;
        }
        tag = root.find("IsTrusting");
        if (tag !== null) {
            this.isTrusting = tag.valueAsBoolean;
        }
        tag = root.find("LastDimensionId");
        if (tag !== null) {
            this.lastDimensionId = tag.valueAsInt;
        }
        tag = root.find("LeasherID");
        if (tag !== null) {
            this.leasherId = tag.valueAsInt;
        }
        tag = root.find("LootDropped");
        if (tag !== null) {
            this.lootDropped = tag.valueAsBoolean;
        }
        tag = root.find("Mainhand");
        if (tag !== null) {
            this.mainhand = tag.valueAsString;
        }
        tag = root.find("MarkVariant");
        if (tag !== null) {
            this.markVariant = tag.valueAsInt;
        }
        tag = root.find("NaturalSpawn");
        if (tag !== null) {
            this.naturalSpawn = tag.valueAsBoolean;
        }
        tag = root.find("Offhand");
        if (tag !== null) {
            this.offhand = tag.valueAsString;
        }
        tag = root.find("OnGround");
        if (tag !== null) {
            this.onGround = tag.valueAsBoolean;
        }
        tag = root.find("OwnerNew");
        if (tag !== null) {
            this.ownerNew = tag.valueAsBigInt;
        }
        tag = root.find("Persistent");
        if (tag !== null) {
            this.persistent = tag.valueAsBoolean;
        }
        tag = root.find("PortalCooldown");
        if (tag !== null) {
            this.portalCooldown = tag.valueAsBoolean;
        }
        tag = root.find("Pos");
        if (tag !== null) {
            this.pos = tag.valueAsNumericArray;
        }
        tag = root.find("Rotation");
        if (tag !== null) {
            this.rotation = tag.valueAsNumericArray;
        }
        tag = root.find("Saddled");
        if (tag !== null) {
            this.saddled = tag.valueAsBoolean;
        }
        tag = root.find("Sheared");
        if (tag !== null) {
            this.sheared = tag.valueAsBoolean;
        }
        tag = root.find("ShowBottom");
        if (tag !== null) {
            this.showBottom = tag.valueAsBoolean;
        }
        tag = root.find("Sitting");
        if (tag !== null) {
            this.sitting = tag.valueAsBoolean;
        }
        tag = root.find("SkinID");
        if (tag !== null) {
            this.skinId = tag.valueAsInt;
        }
        tag = root.find("Strength");
        if (tag !== null) {
            this.strength = tag.valueAsInt;
        }
        tag = root.find("StrengthMax");
        if (tag !== null) {
            this.strengthMax = tag.valueAsFloat;
        }
        tag = root.find("Surface");
        if (tag !== null) {
            this.surface = tag.valueAsBoolean;
        }
        tag = root.find("TargetID");
        if (tag !== null) {
            this.targetId = tag.valueAsBigInt;
        }
        tag = root.find("TradeExperience");
        if (tag !== null) {
            this.tradeExperience = tag.valueAsInt;
        }
        tag = root.find("TradeTier");
        if (tag !== null) {
            this.tradeTier = tag.valueAsInt;
        }
        tag = root.find("UniqueID");
        if (tag !== null) {
            this.uniqueId = tag.valueAsBigInt;
        }
        tag = root.find("Variant");
        if (tag !== null) {
            this.variant = tag.valueAsInt;
        }
        tag = root.find("boundX");
        if (tag !== null) {
            this.boundX = tag.valueAsInt;
        }
        tag = root.find("boundY");
        if (tag !== null) {
            this.boundY = tag.valueAsInt;
        }
        tag = root.find("boundZ");
        if (tag !== null) {
            this.boundZ = tag.valueAsInt;
        }
        tag = root.find("canPickupItems");
        if (tag !== null) {
            this.canPickupItems = tag.valueAsBoolean;
        }
        tag = root.find("definitions");
        if (tag !== null) {
            this.definitions = tag.valueAsStringArray;
        }
        tag = root.find("hasBoundOrigin");
        if (tag !== null) {
            this.hasBoundOrigin = tag.valueAsBoolean;
        }
        tag = root.find("hasSetCanPickupItems");
        if (tag !== null) {
            this.hasSetCanPickupItems = tag.valueAsBoolean;
        }
        tag = root.find("identifier");
        if (tag !== null) {
            this.identifier = tag.valueAsString;
        }
    }
}
exports.default = ActorItem;
_ActorItem_identifier = new WeakMap(), _ActorItem_nbtRoot = new WeakMap(), _ActorItem_dynamicProperties = new WeakMap();

//# sourceMappingURL=../maps/minecraft/ActorItem.js.map
