Script API - v26.60
    Preparing search index...

    Class EntityTypes

    Used for accessing all entity types currently available for use within the world.

    export class EntityTypes {
    private constructor();
    static get<T = never>(identifier: EntityIdentifierType<NoInfer<T>>): EntityType | undefined;
    static getAll(): EntityType[];
    }
    Index
    • Type Parameters

      • T = never

      Parameters

      Returns EntityType | undefined

      Retrieves an entity type using a string-based identifier.

      This function can't be called in early-execution mode.

      import { EntityTypes, Player, system } from "@minecraft/server";

      // Run `/scriptevent example:getcreepertype` in chat to inspect the creeper entity type.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:getcreepertype" || !(sourceEntity instanceof Player)) return;

      const entityType = EntityTypes.get("minecraft:creeper");
      if (!entityType) return;

      sourceEntity.sendMessage(`Found entity type: ${entityType.id}`);
      });
    • Returns EntityType[]

      Retrieves a set of all entity types within this world.

      This function can't be called in early-execution mode.

      import { EntityTypes, Player, system } from "@minecraft/server";

      // Run `/scriptevent example:listentitytypes` in chat to list registered entity type IDs.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:listentitytypes" || !(sourceEntity instanceof Player)) return;

      const entityIds = EntityTypes.getAll().map((entityType) => entityType.id);
      sourceEntity.sendMessage(`Entity types (${entityIds.length}): ${entityIds.slice(0, 10).join(", ")}`);
      });