Wiki 9Minecraft Wiki 9Minecraft

Spawning Custom Items in the World

How to introduce custom items into a world using commands, loot tables, and Script API.

4Sections
4Code examples
3Known errors

Defining a custom item in your behavior pack makes it exist in the game registry, but players still need a way to obtain it. Unless your item is purely craftable, you will need to spawn it into the world or insert it directly into inventories. Bedrock Edition provides five main avenues for this: the creative menu, slash commands, loot tables, the Script API, and entity placer components.

Creative Menu and Slash Commands

During development, the fastest way to test a custom item is through the `/give` command or the creative inventory. For an item to appear in the creative menu, its behavior pack file must include a `menu_category` object inside the `description` block. If you omit this, or set `is_hidden_in_commands` to true, the item will not appear in the creative tabs and will not autocomplete in the chat window, though `/give` may still function if typed out manually.

Beyond `/give`, you can use `/replaceitem` to force a custom item into a specific slot on an entity or inside a block container, and `/loot` to generate items from a loot table directly into the world or an inventory. Always include your custom namespace when referencing the item in any command.

CommandSyntax ExampleUse Case
/give/give @s my_pack:copper_coin 16Adds stacks directly to a player's inventory or drops them at their feet if full.
/replaceitem/replaceitem entity @p slot.weapon.mainhand 0 my_pack:copper_coin 1Overwrites a specific equipment, hotbar, or chest slot with the custom item.
/loot/loot spawn ~~~ loot "loot_tables/chests/coin_pouch.json"Spawns the rolled results of a loot table as floating item entities at a coordinate.
BP/items/copper_coin.json
{
  "format_version": "1.20.50",
  "minecraft:item": {
    "description": {
      "identifier": "my_pack:copper_coin",
      "menu_category": {
        "category": "items",
        "group": "itemGroup.name.ingot",
        "is_hidden_in_commands": false
      }
    },
    "components": {
      "minecraft:icon": {
        "texture": "copper_coin"
      },
      "minecraft:max_stack_size": 64
    }
  }
}

Dropping Items from Loot Tables

For survival gameplay, custom items are most commonly spawned through loot tables. Mob deaths, chest generation, block destruction (when paired with the `minecraft:loot` block component), and fishing all pull from JSON files inside the `BP/loot_tables/` directory. To spawn your item, set an entry's `type` to `item` and its `name` to your full custom identifier.

Standard loot functions work on custom items just as they do on vanilla ones. You can use `set_count` to randomize the stack size, `set_damage` for items that have a `minecraft:durability` component, and `set_name` or `set_lore` to customize the tooltip on the spawned stack.

BP/loot_tables/entities/bandit_drops.json
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "my_pack:copper_coin",
          "weight": 3,
          "functions": [
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 5
              }
            }
          ]
        },
        {
          "type": "empty",
          "weight": 1
        }
      ]
    }
  ]
}

Spawning Item Entities with the Script API

When you need precise control over where an item appears in the physical world, the `@minecraft/server` Script API provides the `Dimension.spawnItem` method. This creates a floating `minecraft:item` entity at any `Vector3` location in the chosen dimension. You must first construct an `ItemStack` instance using your custom item's identifier and the desired stack size.

Because `spawnItem` returns the newly created `Entity` object, you can immediately call entity methods on the dropped item—such as `applyImpulse` or `clearVelocity`—to control how it scatters. Remember that calls which modify the world state cannot run inside read-only ”before” event callbacks; wrap them in `system.run` if triggered from a restricted context.

API Class / MethodWhat it doesNotes
new ItemStack(typeId, amount)Constructs an in-memory representation of an item stack.Throws an error if the identifier is unregistered or amount exceeds max_stack_size.
Dimension.spawnItem(itemStack, location)Spawns a physical item entity in the world at the given Vector3.Returns the spawned Entity instance (typeId is always 'minecraft:item').
Container.addItem(itemStack)Inserts the stack into the first available slot of an entity or block inventory.Returns any remainder ItemStack that could not fit, or undefined if all fit.
BP/scripts/spawn_coin.js
import { world, ItemStack } from "@minecraft/server";

world.afterEvents.playerBreakBlock.subscribe((event) => {
  const { block, dimension } = event;

  if (block.typeId === "minecraft:clay") {
    const coinStack = new ItemStack("my_pack:copper_coin", 2);
    const spawnPos = {
      x: block.location.x + 0.5,
      y: block.location.y + 0.5,
      z: block.location.z + 0.5
    };

    const itemEntity = dimension.spawnItem(coinStack, spawnPos);
    itemEntity.applyImpulse({ x: 0, y: 0.2, z: 0 });
  }
});

Using Items to Spawn Entities

The phrase ”spawning items” can also refer to items whose purpose is to spawn entities, similar to vanilla spawn eggs or boats. In Bedrock Edition, this is handled by attaching the `minecraft:entity_placer` component to your custom item. When the player uses the item on a block, the component spawns the specified entity at the clicked face and consumes one item from the stack (unless the player is in creative mode).

You can restrict which blocks the item works on by populating the `use_on` list with block identifiers, and which blocks it can be dispensed onto from a dispenser using `dispense_on`. If both lists are omitted, the item can place the entity on any solid surface.

BP/items/golem_totem.json
{
  "format_version": "1.20.50",
  "minecraft:item": {
    "description": {
      "identifier": "my_pack:golem_totem",
      "menu_category": {
        "category": "nature",
        "group": "itemGroup.name.mobEgg"
      }
    },
    "components": {
      "minecraft:icon": {
        "texture": "golem_totem"
      },
      "minecraft:max_stack_size": 16,
      "minecraft:entity_placer": {
        "entity": "minecraft:iron_golem",
        "use_on": [
          "minecraft:iron_block",
          "minecraft:stone"
        ],
        "dispense_on": [
          "minecraft:iron_block"
        ]
      }
    }
  }
}

Which versions this applies to

Applies to Bedrock Edition 1.20.50 and newer. No experimental toggles are required for custom items, loot tables, `minecraft:entity_placer`, or `Dimension.spawnItem` in the stable `@minecraft/server` module (1.8.0 and above).

When it does not work

What you seeWhyThe fix
Running `/give @s my_pack:copper_coin` returns `Syntax error: Unexpected "my_pack:copper_coin"`.The item JSON failed to parse or is located in the wrong folder, so the game never registered the identifier.Ensure the file is inside `BP/items/` (not `RP/items/`), check the Content Log for JSON syntax errors, and verify that `format_version` matches the component syntax you are using.
Script Log shows an unhandled exception when calling `new ItemStack("my_pack:copper_coin", 100)`.The `amount` argument passed to the `ItemStack` constructor is greater than the item's `minecraft:max_stack_size` component value (or greater than 64 by default).Clamp the stack amount in your script to match the `minecraft:max_stack_size` defined in your item's behavior file, or spawn multiple separate `ItemStack` instances in a loop.
Script Log shows `ReferenceError` or `Cannot call spawnItem in read-only mode` when spawning an item during an event.`Dimension.spawnItem` modifies the world by creating an entity, which is forbidden during `beforeEvents` execution.Switch your listener to `world.afterEvents`, or wrap the `dimension.spawnItem(...)` call inside a `system.run(() => { ... })` callback.

Reference, straight from the game files

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