Blocks as Items
Automatic Block Items
When you hold a block in your hand, what you're really holding is an item that places the block. When a custom block is registered to the game, Minecraft also automatically registers a new item to represent that block in the inventory.
This item uses the menu category and display name defined by the block, but no other components of the auto-block-item can be modified. In order to apply other components, such as a 2D icon for your block, you'll need to replace the block's item with your own.
Replacing Block Items
BEFORE PLAYER PLACE
Replaced block items do not trigger the beforeOnPlayerPlace
event hook.
In order to replace a block item, you will need to create a new item JSON file that has the same identifier as the block.
Your new item will also need the block placer component which will allow the item to place the block. The block placer component will also give the item the 3D appearance of the block by default, however this can be overridden with the icon component to display a 2D sprite.
Custom Flower Example
One example of a situation where replacing the block item is necessary is with flower blocks, which should display as an icon in item form rather than being 3D.
{
"format_version": "1.21.60",
"minecraft:block": {
"description": {
"identifier": "wiki:daffodil"
},
"components": {
"minecraft:geometry": "minecraft:geometry.cross",
"minecraft:material_instances": {
"*": {
"texture": "wiki:daffodil",
"render_method": "alpha_test"
}
}
}
}
}
{
"format_version": "1.21.60",
"minecraft:item": {
"description": {
"identifier": "wiki:daffodil", // Same as the block's ID
"menu_category": {
"category": "nature",
"group": "minecraft:itemGroup.name.flower"
}
},
"components": {
"minecraft:icon": "wiki:daffodil",
"minecraft:block_placer": {
"block": "wiki:daffodil",
"replace_block_item": true
}
}
}
}
Contributors
Edit Blocks as Items on GitHubText and image content on this page is licensed under the Creative Commons Attribution 4.0 International License
Code samples on this page are licensed under the MIT License