Private
constructorThe id that represents this custom component. Must have a namespace. This id can be specified in a item's JSON configuration under the 'minecraft:custom_components' item component.
The collection of event functions that will be called when the event occurs on an item using this custom component id.
Registers an item custom component that can be used in item JSON configuration.
This function can throw errors.
CustomComponentInvalidRegistryError
ItemCustomComponentAlreadyRegisteredError
ItemCustomComponentReloadNewComponentError
ItemCustomComponentReloadNewEventError
ItemCustomComponentReloadVersionError
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()
);
});
Provides the functionality for registering custom components for items.
Example
registerCustomItemComponent.ts