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

    Class WorldInitializeBeforeEvent

    This class is deprecated and will be removed in 2.0.0.

    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

    Constructors

    Properties

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

    This property is deprecated and will be removed in 2.0.0.

    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(),
    );
    });