bedrock-kit
    Preparing search index...

    Class AssetCollection<T>

    A typed, iterable collection keyed by a string identifier.

    Used for all top-level collections on AddOn (addon.items, addon.entities, addon.recipes, etc.). Provides both map-style lookups and array-style helpers without conversion overhead.

    // Map-style lookup — O(1)
    const spear = addon.items.get("mypack:copper_spear");

    // Array-style helpers
    const withTexture = addon.items.filter(i => i.texture !== undefined);
    const ids = addon.items.map(i => i.id);

    // Grouping by namespace
    const byNs = addon.items.groupBy(i => i.id.split(":")[0]);
    // { "minecraft": [...], "mypack": [...] }

    // Iterable
    for (const item of addon.items) { … }
    const arr = [...addon.items];

    Type Parameters

    • T

    Implements

    • Iterable<T>
    Index

    Accessors

    • get size(): number

      The number of assets in this collection.

      Returns number

    Methods

    • Returns Iterator<T>

    • Returns a plain array of all assets in insertion order.

      Returns T[]

    • All [key, asset] pairs in insertion order.

      Returns IterableIterator<[string, T]>

    • Returns true if every asset satisfies predicate.

      Parameters

      • predicate: (asset: T, key: string) => boolean

      Returns boolean

    • Returns a new AssetCollection containing only assets for which predicate returns true.

      Parameters

      • predicate: (asset: T, key: string) => boolean

      Returns AssetCollection<T>

    • Returns the first asset satisfying predicate, or undefined.

      Parameters

      • predicate: (asset: T, key: string) => boolean

      Returns T

    • Returns the asset with the given key, or undefined if not present.

      Parameters

      • key: string

      Returns T

    • Groups all assets by a derived key. Returns a plain Record where each value is an array of assets sharing that group key.

      Type Parameters

      • K extends string

      Parameters

      • keyFn: (asset: T, key: string) => K

      Returns Record<K, T[]>

      // Group items by namespace
      const byNamespace = addon.items.groupBy(item => item.id.split(":")[0]);
      // { "minecraft": [...], "mypack": [...] }
    • Returns true if an asset with the given key exists in this collection.

      Parameters

      • key: string

      Returns boolean

    • All keys in insertion order.

      Returns IterableIterator<string>

    • Maps each asset to a value and returns the results as a plain array.

      Type Parameters

      • U

      Parameters

      • fn: (asset: T, key: string) => U

      Returns U[]

    • Reduces all assets to a single accumulated value.

      Type Parameters

      • U

      Parameters

      • fn: (acc: U, asset: T, key: string) => U
      • initial: U

      Returns U

      const totalTiers = addon.trading.reduce((sum, t) => sum + t.tiers.length, 0);
      
    • Returns true if at least one asset satisfies predicate.

      Parameters

      • predicate: (asset: T, key: string) => boolean

      Returns boolean

    • All assets in insertion order.

      Returns IterableIterator<T>