Wednesday, January 25, 2012

On the Minecraft Bookshelf Dependency Part II: The 1.1 Changes

[Editors Note: For those who do not play Minecraft, you should. You can play it in your browser here, but I strongly recommend downloading the client from here.]

[Another Editors Note: This post is outdated. An updated version is available for the enchanting systems introduced version 1.3]

It took only three weeks for my post about the Enchantment Level - Bookshelf dependency in Minecraft to go out of date. One of the most welcomed changes listed in the version history for Minecraft 1.1 reads "Decreased randomness of enchantment levels at Enchantment Tables." I have admittedly been waiting for someone else to go digging in the source code and update the formulae on the wiki page, but no one has. So, I had to do it myself.

I downloaded the Minecraft Coder Pack and decompiled the source code for versions 1.0 and 1.1. Despite having practically no java experience, it did not take me more than a few minutes to find what had changed. In fact, the only difference was a single line, which had previously read
    j = 1 + random.nextInt((j >> 1) + 1) + random.nextInt(j + 1);
and which now reads
    j = 1 + (j >> 1) + random.nextInt(j + 1);

It is immediately obvious that saying that they "decreased the randomness" means they literally went into the code and deleted one call to the function "random.nextInt". At this stage of the code, j is the number of book shelves around the enchantment table, and is capped at 30.

What this means is that the enchantment level is calculated by adding together 1, half the number of bookshelves (rounded down), and a random integer between 0 and the number of bookshelves. Later on in the code, a random integer between 0 and 4 is added to this. Previously, instead of using half the number of bookshelves, a second random integer between zero and half the number of bookshelves had been used.

This obviously skews the distribution of the offered enchantment levels toward the higher levels, but it also makes lower level enchantments impossible to obtain if you have too many bookshelves. This is not an issue, however, because adding and removing bookshelves is not at all difficult. The net result is that instead of requiring an average of 2480 attempts to be offered a level 50 enchantment as before, the user need only make an average of 155 attempts. This should take less than a couple of minutes to find for most players. The updated probability distributions are shown in Figure 1, with the original distributions shown as dotted lines. The sloping distribution in the upper and lower five levels of the range are caused by the additional random integer between 0 and 4 that is added on.

Figure 1: Distribution of enchantment levels appearing in the bottom slot

The more important relationship for the player is the one that tells the player the optimum number of bookshelves to use to obtain an enchantment of some desired level. The fact that higher levels are more likely has an interesting effect. Previously, the probability of obtaining lower levels was high enough that the bottom slot was almost always the most likely to offer the level you wanted, even if that level was much lower than the maximum available. After the update, however, the top and middle slots play a significant role, resulting in the optimum number of bookshelves having local minima at levels 26 and 34. The optimum number of bookshelves required is shown in Figure 2.

Figure 2: Optimum number of bookshelves to obtain a desired enchantment level

Thanks go to FifthWhammy for pointing out a small error. It has been corrected.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .

No comments: