Wiki 9Minecraft Wiki 9Minecraft

Custom Item Events and the Migration to Custom Components

How item events worked in legacy formats and how to replace them in modern Bedrock.

5Sections
2Code examples
3Known errors

Item events used to be the standard way to run logic when a player swung a weapon, right-clicked a tool, or ate custom food in a Behavior Pack. In modern Minecraft Bedrock, JSON item events are completely deprecated and removed from the latest format versions. You now reach for the Script API and the minecraft:custom_components item component to handle all interactive item behavior.

The Deprecation of JSON Item Events

Between format versions 1.16.100 and 1.20.40, creators defined an events object at the bottom of their item JSON files, right alongside the components block. Components like minecraft:on_use or minecraft:weapon would point to a named event inside that file, which could then run slash commands, play sounds, damage the item, or teleport the holder.

Starting in format version 1.20.50 and finalized around 1.21.0, Mojang removed the events block and all event-triggering item components from the current item schema. If you set your item's format_version to a modern release like 1.21.10 and include an events section, the Content Log will throw a schema error and your item will either fail to load or lose its functionality. All event-driven logic for items now lives in JavaScript via the @minecraft/server module.

Legacy Event Architecture (Format 1.16.100)

If you are maintaining an older add-on or reading legacy code, you will frequently encounter the 1.16.100 event pattern. Under the old Holiday Creator Features experimental toggle, an item used trigger components to call an event string when an action occurred.

Inside the event definition, responses were scoped to a target—usually holder for the player holding the item, or target for an entity that was hit. The most common responses were run_command to execute a list of slash commands, and damage to reduce the durability of the item. Because Holiday Creator Features has been completely removed from the game, files written this way will no longer function in current versions of Bedrock.

The Modern Replacement: Custom Components

To make an item do something when used, hit, or mined with in modern Bedrock, you attach the minecraft:custom_components component in your item JSON. Instead of writing the logic in JSON, you only provide a list of custom namespace identifiers inside an array.

This keeps the JSON file purely declarative. You combine minecraft:custom_components with standard passive components like minecraft:cooldown, minecraft:durability, and minecraft:icon. When the world loads, the game links those string identifiers to event listeners that you register inside your Behavior Pack's script files.

BP/items/wind_staff.json
{
  "format_version": "1.21.10",
  "minecraft:item": {
    "description": {
      "identifier": "example:wind_staff",
      "menu_category": {
        "category": "equipment"
      }
    },
    "components": {
      "minecraft:icon": "wind_staff",
      "minecraft:max_stack_size": 1,
      "minecraft:cooldown": {
        "category": "wind_staff",
        "duration": 2.5
      },
      "minecraft:custom_components": [
        "example:staff_behavior"
      ]
    }
  }
}

Registering Item Events in Script

In your script entry file, you subscribe to the worldInitialize event to access the itemComponentRegistry. Calling registerCustomComponent lets you bind your custom identifier (such as example:staff_behavior) to an object containing the actual event handlers.

This registration must happen during the world initialization phase, before any items are ticked or loaded into inventories. Inside the callback, you receive an event data object that gives you direct access to the source entity (usually the player), the itemStack being used, and context like the block or entity that was targeted. From there, you can apply knockback, spawn particles, or run commands using the Script API.

BP/scripts/main.js
import { world, EquipmentSlot, EntityComponentTypes } from "@minecraft/server";

world.beforeEvents.worldInitialize.subscribe((initEvent) => {
  initEvent.itemComponentRegistry.registerCustomComponent("example:staff_behavior", {
    onUse(event) {
      const player = event.source;
      const viewDir = player.getViewDirection();

      player.applyKnockback(viewDir.x, viewDir.z, 3.0, 0.6);
      player.playSound("mob.breeze.shoot");

      const cooldown = event.itemStack.getComponent("minecraft:cooldown");
      if (cooldown) {
        cooldown.startCooldown(player);
      }
    },
    onHitEntity(event) {
      const target = event.hitEntity;
      target.setOnFire(5, true);
    }
  });
});

Available Custom Component Event Hooks

When you register an item custom component in JavaScript, you can implement several built-in lifecycle methods on the configuration object. Each method corresponds to one of the old JSON trigger components that existed in earlier format versions.

You only need to include the methods your item actually uses. For example, a custom sword might only implement onHitEntity, while a magical food item would only implement onConsume.

Script MethodWhat it doesNotes
onUseFires when a player right-clicks or long-presses with the item in hand.Replaces the old minecraft:on_use JSON component.
onUseOnFires when the item is used directly on a block face.Replaces the old minecraft:on_use_on JSON component.
onHitEntityFires when the holder attacks an entity while holding the item.Replaces the on_hurt_entity trigger inside old weapon components.
onMineBlockFires when a player finishes breaking a block with this item.Useful for custom pickaxes, vein miners, or durability handling.
onCompleteUseFires when an item with a use duration finishes charging or being eaten.Requires minecraft:use_modifiers on the item to define the duration.
onConsumeFires specifically when a food item is eaten by the player.Requires the minecraft:food component on the item.

Which versions this applies to

Applies to Bedrock Edition 1.21.10 and newer. JSON item events were deprecated in 1.20.40 and removed alongside the Holiday Creator Features toggle in 1.21.20. The replacement minecraft:custom_components system is stable and requires no experimental toggles, though your manifest.json must include a script module dependency on @minecraft/server.

When it does not work

What you seeWhyThe fix
[Item][error]-example:wind_staff | minecraft:item | events is not a valid propertyYou placed an events block inside an item file that uses a modern format_version (such as 1.20.80 or 1.21.10).Remove the events block and any old trigger components like minecraft:on_use from the JSON file, and move your logic into a custom component script.
Content Log shows: Failed to find custom component 'example:staff_behavior' for item 'example:wind_staff'The item JSON lists a custom component identifier, but no script registered that exact identifier during worldInitialize, or your script file failed to load due to a syntax error.Verify that main.js is running, check for spelling mismatches in the identifier string, and ensure registerCustomComponent is called inside world.beforeEvents.worldInitialize.subscribe.
onCompleteUse or onConsume never fires when right-clicking the itemThe item finishes using instantly or cannot be held down because it lacks the required supporting components in JSON.Add the minecraft:use_modifiers component with a use_duration greater than 0 to the item JSON, and add minecraft:food if you are using onConsume.

Reference, straight from the game files

Read out of the game itself, so the ids match the version you are building for.