Fifteen bookshelves, thirty levels
The enchanting table offers higher-level enchants as nearby bookshelves (one air block away, same height as the table) increase — the ceiling is 30 levels at 15 shelves. Arrange them in a ring one block out from the table, leaving gaps for the door; shelves hidden behind walls don't count. Fewer shelves simply lower the menu's maximum level.
The anvil is a combiner, not a vending machine
Anvils merge two identical enchantments into one of the next tier (Sharpness III + Sharpness III = Sharpness IV) and attach books to gear. Every operation raises the item's prior-work penalty, and once that hidden cost reaches 40 levels the item shows 'Too Expensive!' and refuses all further anvil work — permanent for that item on Java. The fix is ordering: do your cheapest merges first, and prefer combining two books into one super-book before it ever touches the tool.
Mending changes everything
A Mending book turns XP orbs into repairs instead of levels, which is why fishing, trading, and raid rolls for Mending are the most hunted enchant in the game. Once your best gear has Mending, the XP calculator stops being about survival — it's about funding library trades for villager-bought books.