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

    Class BlockTypes

    Contains a catalog of Minecraft Block Types that are available in this world.

    export class BlockTypes {
    private constructor();
    static get(typeName: string): BlockType | undefined;
    static getAll(): BlockType[];
    }
    Index
    • Parameters

      • typeName: string

        Identifier of the block type. Should follow a namespace:id pattern, such as minecraft:dirt.

      Returns BlockType | undefined

      BlockType object, or undefined if the block type is not available within this world.

      Returns a BlockType object for the specified identifier.

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

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

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

      const blockType = BlockTypes.get("minecraft:dirt");
      if (!blockType) return;

      sourceEntity.sendMessage(`Found block type: ${blockType.id}`);
      });
    • Returns BlockType[]

      Returns a collection of all available block types.

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

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

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

      const blockIds = BlockTypes.getAll().map((blockType) => blockType.id);
      sourceEntity.sendMessage(`Block types (${blockIds.length}): ${blockIds.slice(0, 10).join(", ")}`);
      });