Script API - v1.21.90.25
    Preparing search index...

    Class ItemComponentRegistry

    Provides the functionality for registering custom components for items.

    import { world } from "@minecraft/server";

    world.beforeEvents.worldInitialize.subscribe((initEvent) => {
    initEvent.itemComponentRegistry.registerCustomComponent("custom:item", {
    onBeforeDurabilityDamage(event) {
    const { attackingEntity, durabilityDamage, hitEntity, itemStack } =
    event;
    // Your code here
    },
    onCompleteUse(event) {
    const { itemStack, source } = event;
    // Your code here
    },
    onConsume(event) {
    const { itemStack, source } = event;
    // Your code here
    },
    onHitEntity(event) {
    const { attackingEntity, hadEffect, hitEntity, itemStack } = event;
    // Your code here
    },
    onMineBlock(event) {
    const { block, itemStack, minedBlockPermutation, source } = event;
    // Your code here
    },
    onUse(event) {
    const { itemStack, source } = event;
    // Your code here
    },
    onUseOn(event) {
    const { source, usedOnBlockPermutation } = event;
    // Your code here
    },
    });
    });
    Index

    Constructors

    Methods

    • Parameters

      • name: string

        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.

      • itemCustomComponent: ItemCustomComponent

        The collection of event functions that will be called when the event occurs on an item using this custom component id.

      Returns void

      Registers an item custom component that can be used in item JSON configuration.

      This function can be called in early-execution mode.

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