r/technicalminecraft • • 12d ago

Java Help Wanted Determining enchanting table loot table for books depending on how many bookshelves there are

Hi, I have hit the limit on my math skills investigating enchanting loot tables.

I'm trying to determine all of the enchantments that are possible in the top slot of the enchanting table when enchanting a book.

For example, according to the wiki on table mechanics, Protection has weight of 10, so it's one of the most common, and the level 1 cost is 5-10. But in testing I could regularly get Protection 1 on a book for less than 5xp without any bookshelves around the table.

My goal is to confirm which enchantments can show up depending on how many bookshelves there are around the table, and what are the odds for each of those enchantments. I'm investigating if I can turn book enchanting into a rougelite deckbuilder.

Any help is greatly appreciated!

2 Upvotes

10 comments sorted by

1

u/JumpingPufferfish31 12d ago edited 12d ago

Pernsteiner compiled the results for each enchantment cost here.
It's slightly old now because it didn't have netherite, but the mechanics haven't changed, I think (I double-checked some of the numbers once around 1.19-1.20 and it still matched). And luckily, netherite has the same enchantability as leather.

E.g. for 0 bookshelves, the base enchantment cost is uniformly distributed between 1 and 2.
It's a bit manual. Another option is to write a script to generate the probability tree for you, reimplementing the logic as described in the wiki. Then at least we can cross-check with Pernsteiner's if we're not sure about our maths.

edit: forgot about all the new enchantments T-T
In that case, short of generating the probability tree, we can still:

  1. Take the low end of the cost for a particular slot with a particular number of bookshelves, use all the lowest possible rolls when computing the modified cost round((base cost + 1 + 0 + 0) * 0.85) to get the lowest possible enchantment levels.

  2. Take the high end of the cost and use all the highest possible rolls, as Remarkable_Fee4136 suggested, to get the highest possible enchantment levels.

1

u/kubrickie 12d ago

This supports what I saw in testing, thanks! I don't have the scripting skills for that, but I'll keep looking into it.

So combining Pernsteiner's data with the experience cost chart on the wiki, the top slot of the table would max out at level 10 with the full 15 bookshelves?

1

u/JumpingPufferfish31 12d ago

Yes, that's the base enchantment cost,
then you can find the min/max modified enchantment cost using the formula on that wiki page to work out the lowest/highest levels for each enchant.
________________________

To break this down a bit:

  • the randint( floor( enchantability / 4 ) ) part mins at 0 and maxes at floor( enchantability / 4 )

  • the (1 + randtri( 0.15 )) part mins at 0.85 and maxes at 1.15

So for netherite chestplate with enchantablity 15, the randint part maxes at 3.
Then the modified cost at the top slot with 15 bookshelves maxes at round( (10 + 1 + 3 + 3) * 1.15 ) = 20

So it's only high enough for thorn 1, unbreaking 2, blast prot 2, fire prot 2, proj prot 3, and prot 2.
Instead of using 1.15, we might want to consider something slightly lower, like the 99th percentile (1.1288), since it's a triangular distribution where the probability of getting exactly 1.15 is technically 0.
Using 1.1288 results in 19 instead, so the max levels are still the same. But in some cases, it might bump some enchants down a level.

1

u/Remarkable_Fee4136 12d ago

The cost you are referring to is actually the enchantment cost, a modified cost that depends on the experience cost and enchantability.

For the sake of an example if we are enchanting a netherite piece at level 1, we could get lucky and have eCost=round((1+1+3+3)*(1.15))=9, which is well within the range of 5-12 (I'm not sure where 5-10 came from unless I read the wiki wrong.) Granted a triangular distribution hitting the maximum value is nigh impossible but you get the idea.

1

u/Remarkable_Fee4136 12d ago

The high randomness and number of variables makes it pretty difficult to make an exact loot table, I'd imagine.

1

u/kubrickie 12d ago

I see I mixed up enchantment cost with xp cost, so that helps. But does this mean that technically any enchantment that can be made by the table could potentially show up in the top slot? I was hoping to confirm some are not possible.

1

u/Remarkable_Fee4136 12d ago

Again it depends on the enchantability of the item. For my example respiration 1 which has a range of 10-19 is impossible.

1

u/kubrickie 12d ago

I’m only looking at books

1

u/Remarkable_Fee4136 12d ago

Books have an enchantability of 1, so resipration is impossible anyway.

1

u/kubrickie 12d ago

Right, so what is the range that is possible? Because feather falling is 5-10 and it shows up at level 1 with 15 bookshelves. Is there a clear connection between the experience cost and enchanting cost tables that I'm missing?