Script API - v1.21.0
    Preparing search index...

    Contains information and methods that can be used at the initialization of the scripting environment for a World. Also, use the supplied blockRegistry object to register block custom components within the scope of the World Initialize execution.

    Index

    Properties

    blockTypeRegistry: BlockComponentRegistry
    import { world, BlockPermutation } from "@minecraft/server";
    world.beforeEvents.worldInitialize.subscribe((event) => {
    event.blockTypeRegistry.registerCustomComponent("jayly:custom_block", {
    onStepOn(data) {
    data.block.setPermutation(
    BlockPermutation.resolve("minecraft:emerald_block")
    );
    },
    });
    });
    itemComponentRegistry: ItemComponentRegistry

    Provides the functionality for registering custom components for items.

    import {
    BlockPermutation,
    ItemComponentMineBlockEvent,
    ItemCustomComponent,
    world,
    } from "@minecraft/server";

    class MineDiamondComponent implements ItemCustomComponent {
    onMineBlock(e: ItemComponentMineBlockEvent): void {
    const { minedBlockPermutation, block } = e;
    if (minedBlockPermutation.matches("minecraft:diamond_ore")) {
    block.setPermutation(BlockPermutation.resolve("minecraft:stone"));
    }
    }
    }

    world.beforeEvents.worldInitialize.subscribe((event) => {
    event.itemComponentRegistry.registerCustomComponent(
    "jayly:custom_item",
    new MineDiamondComponent()
    );
    });