var _a;
import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
export class ItemDrops {
    static getDropsOnTick(tick) {
        var _b;
        return (_b = this.dropsMap.get(tick)) !== null && _b !== void 0 ? _b : [];
    }
    static getDropsAtLocation(tick, location) {
        return this.getDropsOnTick(tick).filter(drop => drop.entity.isValid() && drop.entity.location.distance(location) < 5);
    }
}
_a = ItemDrops;
ItemDrops.dropsMap = new Map();
(() => {
    mc.world.afterEvents.entitySpawn.subscribe(event => {
        if (event.entity.typeId === "minecraft:item" && event.entity.isValid()) {
            const key = mc.system.currentTick;
            const entity = new utils.SafetyCheckedEntity(event.entity);
            try {
                const item = entity.getComponent("item").itemStack;
                if (_a.dropsMap.has(key)) {
                    _a.dropsMap.get(key).push({ item, entity });
                }
                else {
                    _a.dropsMap.set(key, [{ item, entity }]);
                }
            }
            catch (error) {
                // This may occur if the entity is despawned and the validation check fails. Do nothing if that is the case.
            }
            utils.waitForEvent(2, () => _a.dropsMap.delete(key));
        }
    });
})();
