import { BlockCustomComponent, ItemCustomComponent, } from "@minecraft/server"; /** * Define a custom item component. * @category Need Registry * @example * ~~~ts * // Define the component * const COMPONENT = new CustomItemComponent("lazuli:example", { * onConsume(arg) { * arg.source.addEffect("posion", 200); * }, * }) * // Registry the component * Register.componentRegistry(COMPONENT); * ~~~ */ export class CustomItemComponent { /** * @param typeId * The 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. * @param components * The collection of event functions that will be called when * the event occurs on an item using this custom component id. * @throws This function can throw errors. */ constructor( readonly typeId: string, public components: ItemCustomComponent ) {} } /** * Define a custom block component. * @category Need Registry * @example * ~~~ts * // Define the component * const COMPONENT = new CustomBlockComponent("lazuli:example", { * onEntityFallOn(arg) { * arg.dimension.createExplosion(arg.block.location, 5); * }, * }) * // Registry the component * Register.componentRegistry(COMPONENT); * ~~~ */ export class CustomBlockComponent { /** * @param typeId * The 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. * @param components * The collection of event functions that will be called when * the event occurs on an item using this custom component id. * @throws This function can throw errors. */ constructor( readonly typeId: string, public components: BlockCustomComponent ) {} }