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.

Hierarchy

  • WorldInitializeBeforeEvent

Constructors

Properties

blockComponentRegistry: BlockComponentRegistry

Example

customBlockComponent.ts

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

Remarks

Provides the functionality for registering custom components for items.

Example

customItemComponent.ts

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