@ascentbv/ts-common - v1.0.123
    Preparing search index...

    Class EntityUtilAbstract

    Index

    Constructors

    Methods

    • Spawns or retrieves a protected singleton entity with async retry logic for chunk loading. If the entity of this type has already been spawned and is tracked, returns that instance instead. If chunk loading fails, will retry with exponential backoff using TimerUtil.

      Parameters

      • entityType: string

        The identifier of the entity to spawn or retrieve.

      • spawnLocation: Vec3

        The Vec3 location to spawn the entity at.

      • dimension: Dimension

        The dimension to spawn the entity in.

      • maxRetries: number = 5

        Maximum number of retry attempts (default: 5).

      • currentAttempt: number = 0

        Current attempt number (used internally for recursion).

      Returns Entity | undefined

      The entity if immediately available or successfully spawned, undefined if chunk loading required (will retry in background).

      // Returns entity immediately if available/spawnable, otherwise retries in background
      const tutorialBeef = EntityUtil.summonOrGetProtectedEntityAsync(`${Data.NAMESPACE}:tutorial`, location, dimension);
      if (tutorialBeef) {
      NpcDialogueController.setNameTag(tutorialBeef, `${Data.NAMESPACE}:tutorial.start`);
      }
      // If undefined, the method will keep retrying in background until successful

      // Synchronous version - returns undefined if chunk not loaded
      const entity = EntityUtil.summonOrGetProtectedEntity("minecraft:zombie", location, dimension);
      if (entity) {
      // Entity was spawned or retrieved
      } else {
      // Chunk not loaded or other error occurred
      }
    • Spawns or retrieves a protected singleton entity with retry logic for chunk loading (synchronous version). If the entity of this type has already been spawned and is tracked, returns that instance instead. This version attempts immediate spawning but falls back gracefully on chunk loading issues.

      Parameters

      • entityType: string

        The identifier of the entity to spawn or retrieve.

      • spawnLocation: Vec3

        The Vec3 location to spawn the entity at.

      • dimension: Dimension

        The dimension to spawn the entity in.

      Returns Entity | undefined

      The spawned or retrieved Entity instance, or undefined if chunk loading fails.

    • Spawns or retrieves a protected singleton entity (backwards compatibility wrapper). This version will throw errors if chunk loading fails, maintaining old behavior. For safer operation, use the async version or handle undefined returns.

      Parameters

      • entityType: string

        The identifier of the entity to spawn or retrieve.

      • spawnLocation: Vec3

        The Vec3 location to spawn the entity at.

      • dimension: Dimension

        The dimension to spawn the entity in.

      Returns Entity

      The spawned or retrieved Entity instance.

      Error if chunk is not loaded and entity cannot be spawned.

    • Retrieves a protected/singleton entity by its type.

      Parameters

      • entityType: string

        The type ID of the protected entity.

      Returns Entity | undefined

      The entity if it exists and is valid; otherwise undefined.

    • Checks whether a protected entity of a given type has already been spawned and tracked.

      Parameters

      • entityType: string

        The type ID to check.

      Returns boolean

      True if a protected entity exists; otherwise false.

    • Spawns an entity in the given dimension at the specified location.

      Parameters

      • type: string

        The entity type ID to spawn.

      • location: Vec3

        The Vec3 spawn location.

      • dimension: Dimension

        The dimension to spawn the entity in.

      Returns Entity

      The spawned entity.

    • Spawns an entity with an initial rotation.

      Parameters

      • type: string

        The entity type ID to spawn.

      • location: Vec3

        The Vec3 spawn location.

      • rotation: Vector2

        The Vector2 rotation (yaw, pitch) to apply.

      • dimension: Dimension

        The dimension to spawn the entity in.

      Returns Entity

      The spawned entity with rotation applied.

    • Gets all entities near a given entity within a specified distance.

      Parameters

      • query: { maxDistance: number }

        The query object with a maxDistance property.

      • entity: Entity

        The entity from whose location to search.

      Returns Entity[]

      A list of nearby entities in the same dimension.

    • Checks if an entity is affected by PvP logic. Currently only checks for player entities.

      Parameters

      • entity: Entity

        The entity to check.

      Returns boolean

      True if the entity is a player.

    • Links an entity to an owner by storing the owner's entity ID as a property.

      Parameters

      • entity: Entity

        The entity to assign an owner to.

      • owner: Entity

        The owner entity.

      Returns void

    • Retrieves the owner of a given entity, if available.

      Parameters

      • entity: Entity

        The entity whose owner to look up.

      Returns Entity | undefined

      The owner entity, or undefined if not found.

    • Gets an entity by its Minecraft unique ID.

      Parameters

      • id: string

        The entity's unique ID.

      Returns Entity | undefined

      The entity, or undefined if not found.

    • Checks whether an entity belongs to one or more type families.

      Parameters

      • entity: Entity

        The entity to check.

      • families: string | string[]

        One or more family strings to test for.

      • requireAll: boolean = false

        If true, all families must match. If false (default), at least one must match.

      Returns boolean

      True if the entity belongs to the family/families.

    • Gets the base name of an entity (without namespace).

      Parameters

      • entity: Entity

        The entity to query.

      Returns string

      The base name (e.g., "zombie" for "minecraft:zombie").

      const baseName = EntityUtil.getBaseEntityName(entity);
      console.log(baseName); // zombie
    • Iterate entities in a dimension with an optional query.

      • Returns how many entities were processed.
      • If the visitor returns false and stopOnFalse is true, iteration stops early.

      Parameters

      Returns number