TransWikia.com

How do I give a player an item with custom properties?

Arqade Asked on December 26, 2020

I’m used to creating Java Edition Minecraft maps, where NBT can be used to set many different block, item, and entity properties, like an item’s CanPlaceOn/CanDestroy list, a chest’s items, and more!

To open my maps up to more players, I’ve started creating maps on Minecraft Bedrock Edition as well. But NBT is inaccessible from commands in BE, which I knew before, but didn’t know how much of a problem I would have creating these complicated command chains.

One of the things that I’ve always been doing is giving players items with custom item names, lores, enchantments, and other properties.

But there is a problem. All this would have been done in NBT in Java Edition. In Bedrock, NBT is inaccessible from commands, meaning the commands I used in JE don’t work. Are my dreams crushed?


Browse more workarounds for getting/setting NBT in Bedrock Edition

One Answer

Your dreams aren't crushed quite yet. Although it may be true that NBT is inaccessible from commands, there is still a workaround for what you want to do!

Here's a handy workaround that lets you give items with custom names and enchantments.

My plan is:

  1. Place the item you want to give in a chest.
  2. On command, clone the chest to the player's location.
  3. Use /setblock in destroy mode to destroy the chest, causing it to drop all its items on the player.

Item Customization

So to do this, you're going to need to place a chest in a template location, manually prepare your item, and place it into the chest. Here is a list of all available and unavailable properties to customize your item:

Properties you can set/change

The following properties can be changed within the game:

  • Custom name: Take your item to an anvil. Use the anvil’s rename form to change the item name. Instead of using raw JSON text, use formatting codes to stylize the item name.
  • Some enchantments: Get an enchanted book and combine it with your item in an anvil. You may also use /enchant while holding the item in your main hand. You may not exceed the maximum enchantment level, and you may not enchant items that don't make sense with that enchantment (so no enchanting a fish with Knockback X), but you can use an NBT editor—see below.
  • Default potion effects: Potions can be given as one of the default potions available in the Creative Inventory using data values, and do not require this workaround to be given. See these instructions for what to do.
    However, if you need to use this in conjunction with more of these properties, follow the instructions in the linked post, then come back here.
  • CanPlaceOn and CanDestroy: If you want to give an item with these properties alone, you can simply use /give with the JSON components can_place_on and can_destroy, without going through all this extra work. But if you want to combine this with some of these other customization methods, follow the instructions in the linked post, then come back here.
  • Filled maps: To give a filled map with custom scale/regions/ to a player, get an empty map yourself, bring it to the region, and activate it. Then place the filled map in the chest. This method is also required to give an empty locator map, because the locator/non-locator data is stored in NBT.

Properties that require one-time use of an NBT editor to be set/changed

The following properties can be changed through one-time use of an NBT editor. Follow these instructions to modify any of the below listed properties, and place the item in the chest. The below commands will then work to give an exact copy of the item, even with some properties changed, without requiring use of an NBT editor ever again.

  • Lore
  • Enchantments applied to items that cannot normally receive that enchantment
  • Enchantments that exceed the maximum enchantment level

Properties you cannot set/change

These are item tags that exist in Java Edition, but the matching NBT tag in Bedrock Edition has not been discovered, or is nonexistent. Feel free to tinker with the NBT tags in an editor, and if you can find any new NBT tags, please suggest an edit so I can add to this post!

  • Unbreakable
  • Custom potion effects

Commands

Now let's create the command chain we'll be using. Place an impulse command chain of 4 blocks.

Choose the command chain that best suits you.

To give item to a player

  1. Tell the player to clone the chest to their position.

    execute @p[name=THE_PLAYER_TO_TARGET] ~ ~ ~ clone Tx Ty Tz Tx Ty Tz ~ ~ ~
    

    Replace Tx, Ty, and Tz with the template location in both coordinate specifications.

  2. Tell the player to set the block to air and destroy the chest.

    execute @p[name=THE_PLAYER_TO_TARGET] ~ ~ ~ setblock ~ ~ ~ air destroy
    
  3. Kill the chest.

    kill @e[type=item,name=chest]
    

To summon item on the ground:

  1. Clone the chest.

    clone Tx Ty Tz Tx Ty Tz Rx Ry Rz
    

    T: Template location.
    R: Target location.

  2. Set the chest to air and destroy it.

    setblock Rx Ry Rz air destroy
    
  3. Kill the chest.

    kill @e[type=item, name=chest]
    

Sources

While this trick is handy, sadly, I cannot claim ownership of it. I discovered it in a map in Minecraft: Education Edition, from the We Are the Rangers library. I saw it as part of a task in the map, and while looking in the commands, it was too good to not post here. Thank you to the Minecraft Education Edition team at Microsoft for creating such awesome maps!

Correct answer by ExpertCoder14 on December 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP