Tree Assist

Tree Assist

1M Downloads

Durability applied incorrectly when using Unbreaking Enchantment

serpi90 opened this issue ยท 2 comments

commented

In BaseTree, I think you are doing the probability calculation for damaging a tool with Unbreaking backwards.

From the wiki: "the chance that they will use durability is 1 in (1+level)"

Nothing = Loose Durability 1 in 1 (always) = 100%
Unbreaking I = Loose Durability 1 in 2 = 50%
Unbreaking II = Loose Durability 1 in 3 = 33%
Unbreaking III = Loose Durability 1 in 4 = 25%

Roughly, i see that you are doing the following:

if random < 25%
{
    return (dont damage)
}
else // > 25% (75% chance)
{
    apply damage
}

You are aplying damage with more chance when the enchantment level is higher.

As far as i know the calculation whould be done as follows (for simplicity)

maxChance = 1 + tool.getEnchantmentLevel(Enchantment.DURABILITY); //getEnchantmentLevel is 0 if not applied according to javadoc.
if(new Random().nextInt(maxChance) == 0) // 1 in maxChance
{
    apply damage
}
commented

mhhhhhh I will look into that, thanks :)

commented

if (tool.containsEnchantment(Enchantment.DURABILITY)) {
int damageChance = (int) (100d / ((double) tool
.getEnchantmentLevel(Enchantment.DURABILITY) + 1d));

            int random = new Random().nextInt(100);

            if (random < damageChance) {
                return;
            }
        }

That is my code. Ooooohh right, returning means "no damage", it should be the exact opposite logic.

Good catch !!!