PrivateconstructorThis function can be called in early-execution mode.
This function can't be called in read-only mode.
This function can throw errors.
CustomComponentInvalidRegistryError
ItemCustomComponentAlreadyRegisteredError
ItemCustomComponentReloadNewComponentError
ItemCustomComponentReloadNewEventError
import { BlockPermutation, ItemComponentMineBlockEvent, ItemCustomComponent, system } 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"));
}
}
}
system.beforeEvents.startup.subscribe((event) => {
event.itemComponentRegistry.registerCustomComponent("jayly:custom_item", new MineDiamondComponent());
});
Example: registerCustomItemComponent.ts