Stackable Enchanted Books
A small Fabric mod for Minecraft 1.21.1. Identical enchanted books stack up
to 16 instead of 1 — you can raise or lower that limit in the config.
Enchanted books that are actually identical (same enchantments, same levels,
same anvil work penalty, same custom name, same everything else) pile up in
your inventory and shulker boxes like any other item. Books that differ in
any way still take separate slots, exactly like vanilla.
Features
- Identical enchanted books stack, up to a configurable limit (default 16).
- The anvil and the grindstone are updated to work on one book of a stack
at a time, so a stack is never duplicated or destroyed in a single
operation.
- No other item is affected. Only enchanted books get the new stacking
behavior.
- No registry changes, no new items, no new blocks — just a default item
component tweak plus the container fixes needed to keep it safe.
What counts as "identical"
Two enchanted books stack together only when the game itself considers them
the exact same item: ItemStack.isSameItemSameComponents. In practice that
means the same stored enchantments at the same levels, the same anvil repair
cost, the same custom name, and any other component matching. A Sharpness I
book will never stack with a Sharpness II book or with an Unbreaking I
book. The mod doesn't add any merging logic beyond what vanilla already
checks for "is this the same item".
Anvil and grindstone behavior
Vanilla assumes every enchanted book has a count of 1. Without extra care,
letting books stack would mean losing whole stacks to a single anvil pull or
duplicating them in creative mode. This mod changes the relevant vanilla
code paths so stacks are always handled one book at a time:
| Situation |
Result |
| Anvil, book stack in the right slot (e.g. sword + 16 books) |
exactly 1 book is used per operation, not the whole stack |
| Anvil, book stack in the left slot with something to combine on the right |
worked one book at a time, at the normal single-book XP cost; taking the result removes 1 book from each stack, and a shift-click takes only one result |
| Anvil, book stack in the left slot, right slot empty (renaming) |
unchanged — the whole stack is renamed and returned together, same as renaming any other item stack |
| Grindstone, a single book stack with the other slot empty |
1 disenchanted book at a time; a shift-click grinds the stack one book at a time, each for that one book's XP |
| Grindstone, book stack next to another item |
no result, same as vanilla |
| Grindstone, two identical single books |
vanilla's normal stackable-item path: 2 books in, 2 plain books out |
Everything else that touches books — the enchanting table (single-item slot,
and enchanted books can't be enchanted anyway), the chiseled bookshelf,
lecterns, loot tables, and villager trades — already worked correctly with
stackable books and needed no changes.
Configuration
The mod creates config/stackable_enchanted_books.json on first launch:
{
"maxStackSize": 16
}
| Key |
Default |
Valid values |
maxStackSize |
16 |
whole numbers 1–64 (1 keeps vanilla behavior) |
- The file is read once on startup — restart the game or server after
changing it.
- An invalid value (bad JSON, wrong type, a fraction, NaN, or out of range)
logs one warning and falls back to
16. The mod never rewrites or
"fixes" your file for you.
- On every start, the mod logs one line stating the value in effect, e.g.
Enchanted books stack up to 16.
Requirements
- Minecraft 1.21.1
- Fabric Loader 0.16.0 or newer
- Fabric API
- Java 21
Install on both sides, with the same value
This mod changes a default item component, which isn't something the
network syncs between client and server. Install it on the server and on
every client, using the same maxStackSize.
If a client and server end up mismatched anyway (nothing prevents it — the
mod adds no registry entries or packets to check for), here's what actually
happens, verified against the 1.21.1 source:
- Survival/adventure inventories and containers: the server is
authoritative and sends back the correct slot contents, so at worst you'll
see a visual glitch — books that seem to merge and then snap back, or an
anvil/grindstone preview that's briefly wrong. Nothing is duplicated or
lost.
- Creative mode: the server rejects a creative slot update above its
configured limit, so a client with a higher limit can see a picked-up
stack vanish. This is specific to creative inventory handling.
- Uninstalling later: worlds still load fine. Vanilla itself accepts
saved stacks above an item's normal limit (up to 99), so existing book
stacks just sit as they are until you move or split them.
Compatibility and limitations
- The mod is built on four small, targeted mixins (into
AnvilMenu,
GrindstoneMenu, the grindstone result slot, and one hook in
AbstractContainerMenu.broadcastChanges) plus Fabric API's
DefaultItemComponentEvents.
- Mods that replace vanilla's anvil or grindstone logic outright (anvil
overhauls, "no too expensive" mods, custom grindstone implementations) or
that add their own separate book-consuming machines are not covered by
these mixins.
- This is intentional: if another mod overwrites the exact vanilla methods
this mod hooks into, Mixin will fail loudly and stop the game at startup,
rather than silently letting a dupe or item-loss bug slip through.
- Enchanted books in a bundle (experimental in 1.21.1) now take up 1/16 of
the bundle each instead of filling the whole bundle.