Updated:
1. Build the bookshelf ring and table
/fill ~-2 ~ ~2 ~2 ~1 ~6 minecraft:bookshelf
/fill ~-1 ~ ~3 ~1 ~1 ~5 minecraft:air
/fill ~ ~ ~2 ~ ~1 ~2 minecraft:air
/setblock ~ ~ ~4 minecraft:enchanting_table
This places a 5x5, two-high block of shelves two blocks south of you, hollows out the middle 3x3, opens a doorway and puts the table in the center. That is 30 shelves, well over the 15 needed.
2. Bookshelf rules
- Leave exactly one air block between the table and each shelf.
- Shelves count at table level and one block higher.
- Torches or carpets in the gap block them.
3. XP and lapis
/xp add @s 30 levels
/give @s minecraft:lapis_lazuli 64
The level 30 option needs 30 levels and 3 lapis, and costs 3 levels. On Bedrock use /xp 30L @s (xp command).
4. Skip the table
/enchant @s sharpness 5
Adds an exact enchantment to the held item, no luck involved.
5. Add an anvil and grindstone
/setblock ~2 ~ ~1 minecraft:anvil
/setblock ~-2 ~ ~1 minecraft:grindstone[face=floor]
/give @s minecraft:enchanted_book[stored_enchantments={mending:1}]
Place them on both sides in front of the bookshelves. The anvil applies books and the grindstone removes enchantments. On 1.21.4 and older write {levels:{mending:1}}. See the enchanted book command.
Troubleshooting
- Not level 30: check the one-block gap and that nothing sits in it.
- No options: add lapis and use an enchantable item.
- Built in the wrong spot: it always goes south (positive Z), not where you face.
- Bedrock: the fill commands work the same.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.