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

    Interface ItemCustomComponent

    Contains a set of events that will be raised for an item. This object must be bound using the ItemComponentRegistry.

    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
    },
    });
    });
    import { system } from "@minecraft/server";

    system.beforeEvents.startup.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
    },
    });
    });
    interface ItemCustomComponent {
        onBeforeDurabilityDamage?: (
            arg0: ItemComponentBeforeDurabilityDamageEvent,
        ) => void;
        onCompleteUse?: (arg0: ItemComponentCompleteUseEvent) => void;
        onConsume?: (arg0: ItemComponentConsumeEvent) => void;
        onHitEntity?: (arg0: ItemComponentHitEntityEvent) => void;
        onMineBlock?: (arg0: ItemComponentMineBlockEvent) => void;
        onUse?: (arg0: ItemComponentUseEvent) => void;
        onUseOn?: (arg0: ItemComponentUseOnEvent) => void;
    }
    Index

    Properties

    onBeforeDurabilityDamage?: (
        arg0: ItemComponentBeforeDurabilityDamageEvent,
    ) => void

    This function will be called when an item containing this component is hitting an entity and about to take durability damage.

    onCompleteUse?: (arg0: ItemComponentCompleteUseEvent) => void

    This function will be called when an item containing this component's use duration was completed.

    onConsume?: (arg0: ItemComponentConsumeEvent) => void

    This function will be called when an item containing this component is eaten by an entity.

    onHitEntity?: (arg0: ItemComponentHitEntityEvent) => void

    This function will be called when an item containing this component is used to hit another entity.

    onMineBlock?: (arg0: ItemComponentMineBlockEvent) => void

    This function will be called when an item containing this component is used to mine a block.

    onUse?: (arg0: ItemComponentUseEvent) => void

    This function will be called when an item containing this component is used by a player.

    onUseOn?: (arg0: ItemComponentUseOnEvent) => void

    This function will be called when an item containing this component is used on a block.