import { system } from "@minecraft/server";// Use world.beforeEvents.worldInitialize.subscribe if you're using @minecraft/server v1system.beforeEvents.startup.subscribe((initEvent) => { initEvent.blockComponentRegistry.registerCustomComponent("custom:block", { beforeOnPlayerPlace: (event) => { const { player, block, face, permutationToPlace, dimension } = event; event.cancel = true; // include this if canceling block placement // Your code here }, onEntityFallOn: (event) => { const { entity, block, fallDistance, dimension } = event; // Your code here }, onPlace: (event) => { const { block, dimension, previousBlock } = event; // Your code here }, onPlayerBreak: (event) => { const { player, block, dimension, brokenBlockPermutation } = event; // Your code here }, onPlayerInteract: (event) => { const { player, block, dimension, face, faceLocation } = event; // Your code here }, onRandomTick: (event) => { const { block, dimension } = event; // Your code here }, onStepOff: (event) => { const { entity, block, dimension } = event; // Your code here }, onStepOn: (event) => { const { entity, block, dimension } = event; // Your code here }, onTick: (event) => { const { block, dimension } = event; // Your code here }, });}); Copy
import { system } from "@minecraft/server";// Use world.beforeEvents.worldInitialize.subscribe if you're using @minecraft/server v1system.beforeEvents.startup.subscribe((initEvent) => { initEvent.blockComponentRegistry.registerCustomComponent("custom:block", { beforeOnPlayerPlace: (event) => { const { player, block, face, permutationToPlace, dimension } = event; event.cancel = true; // include this if canceling block placement // Your code here }, onEntityFallOn: (event) => { const { entity, block, fallDistance, dimension } = event; // Your code here }, onPlace: (event) => { const { block, dimension, previousBlock } = event; // Your code here }, onPlayerBreak: (event) => { const { player, block, dimension, brokenBlockPermutation } = event; // Your code here }, onPlayerInteract: (event) => { const { player, block, dimension, face, faceLocation } = event; // Your code here }, onRandomTick: (event) => { const { block, dimension } = event; // Your code here }, onStepOff: (event) => { const { entity, block, dimension } = event; // Your code here }, onStepOn: (event) => { const { entity, block, dimension } = event; // Your code here }, onTick: (event) => { const { block, dimension } = event; // Your code here }, });});
import { system, BlockComponentPlayerPlaceBeforeEvent, BlockComponentEntityFallOnEvent, BlockComponentOnPlaceEvent, BlockComponentPlayerBreakEvent, BlockComponentPlayerInteractEvent, BlockComponentRandomTickEvent, BlockComponentStepOffEvent, BlockComponentStepOnEvent, BlockComponentTickEvent, CustomComponentParameters,} from "@minecraft/server";system.beforeEvents.startup.subscribe((startupEvent) => { startupEvent.blockComponentRegistry.registerCustomComponent("custom:block", { beforeOnPlayerPlace: (event: BlockComponentPlayerPlaceBeforeEvent, params: CustomComponentParameters) => { const { player, block, face, permutationToPlace, dimension } = event; event.cancel = true; // include this if canceling block placement // Your code here }, onEntityFallOn: (event: BlockComponentEntityFallOnEvent, params: CustomComponentParameters) => { const { entity, block, fallDistance, dimension } = event; // Your code here }, onPlace: (event: BlockComponentOnPlaceEvent, params: CustomComponentParameters) => { const { block, dimension, previousBlock } = event; // Your code here }, onPlayerBreak: (event: BlockComponentPlayerBreakEvent, params: CustomComponentParameters) => { const { player, block, dimension, brokenBlockPermutation } = event; // Your code here }, onPlayerInteract: (event: BlockComponentPlayerInteractEvent, params: CustomComponentParameters) => { const { player, block, dimension, face, faceLocation } = event; // Your code here }, onRandomTick: (event: BlockComponentRandomTickEvent, params: CustomComponentParameters) => { const { block, dimension } = event; // Your code here }, onStepOff: (event: BlockComponentStepOffEvent, params: CustomComponentParameters) => { const { entity, block, dimension } = event; // Your code here }, onStepOn: (event: BlockComponentStepOnEvent, params: CustomComponentParameters) => { const { entity, block, dimension } = event; // Your code here }, onTick: (event: BlockComponentTickEvent, params: CustomComponentParameters) => { const { block, dimension } = event; // Your code here }, });}); Copy
import { system, BlockComponentPlayerPlaceBeforeEvent, BlockComponentEntityFallOnEvent, BlockComponentOnPlaceEvent, BlockComponentPlayerBreakEvent, BlockComponentPlayerInteractEvent, BlockComponentRandomTickEvent, BlockComponentStepOffEvent, BlockComponentStepOnEvent, BlockComponentTickEvent, CustomComponentParameters,} from "@minecraft/server";system.beforeEvents.startup.subscribe((startupEvent) => { startupEvent.blockComponentRegistry.registerCustomComponent("custom:block", { beforeOnPlayerPlace: (event: BlockComponentPlayerPlaceBeforeEvent, params: CustomComponentParameters) => { const { player, block, face, permutationToPlace, dimension } = event; event.cancel = true; // include this if canceling block placement // Your code here }, onEntityFallOn: (event: BlockComponentEntityFallOnEvent, params: CustomComponentParameters) => { const { entity, block, fallDistance, dimension } = event; // Your code here }, onPlace: (event: BlockComponentOnPlaceEvent, params: CustomComponentParameters) => { const { block, dimension, previousBlock } = event; // Your code here }, onPlayerBreak: (event: BlockComponentPlayerBreakEvent, params: CustomComponentParameters) => { const { player, block, dimension, brokenBlockPermutation } = event; // Your code here }, onPlayerInteract: (event: BlockComponentPlayerInteractEvent, params: CustomComponentParameters) => { const { player, block, dimension, face, faceLocation } = event; // Your code here }, onRandomTick: (event: BlockComponentRandomTickEvent, params: CustomComponentParameters) => { const { block, dimension } = event; // Your code here }, onStepOff: (event: BlockComponentStepOffEvent, params: CustomComponentParameters) => { const { entity, block, dimension } = event; // Your code here }, onStepOn: (event: BlockComponentStepOnEvent, params: CustomComponentParameters) => { const { entity, block, dimension } = event; // Your code here }, onTick: (event: BlockComponentTickEvent, params: CustomComponentParameters) => { const { block, dimension } = event; // Your code here }, });});
Optional
Example: registerBlockComponent_v1.ts
Example: registerBlockComponent_v2.ts