Industrial Foregoing

Industrial Foregoing

95M Downloads

[1.16] Enchantment applicator essense consumption seems off

Opened this issue · 4 comments

commented

Industrial Foregoing Version:
I'm actually looking at the source for this:
https://github.com/InnovativeOnlineIndustries/Industrial-Foregoing/blob/1.16/src/main/java/com/buuz135/industrial/block/misc/tile/EnchantmentApplicatorTile.java#L96

The code here is:

    private int getEssenceConsumed(int experienceLevel) {
        int xp = 0;
        if (experienceLevel >= 0 && experienceLevel <= 15)
            xp = (int) (Math.pow(experienceLevel, 2) + 6 * experienceLevel);
        if (experienceLevel >= 16 && experienceLevel <= 30)
            xp = (int) (2.5 * Math.pow(experienceLevel, 2) - 40 * experienceLevel + 360);
        if (experienceLevel >= 32) xp = (int) (5.5 * Math.pow(experienceLevel, 2) - 162.5 * experienceLevel + 2220);
        return xp * 20;
    }

I was looking at this because for higher levels (say 35), the consumption seemed to be overly high.

I notice two things:
The second if ends with experienceLevel <= 30), and the third if starts with if (experienceLevel >= 32).
So level 31 is missing, and would be free?

I made a graph of the 3 expressions, and the switchover points from the if's:
image

From the first to the second you can see that at level 15 there's a nice smooth transition from the first to second curve, as you'd expect.
From the second to third though there's a big jump at level 30/32, which I think is not what was intended, I'd expect another smooth transition here. And that would explain the unexpected high consumption I was seeing.

commented

It is true that ranges are wrong but the formula is from the minecraft wiki

commented

Ah, from https://minecraft.gamepedia.com/Experience there's this:
level2 + 6 × level (at levels 0–16)
2.5 × level2 – 40.5 × level + 360 (at levels 17–31)
4.5 × level2 – 162.5 × level + 2220 (at levels 32+)

So I guess the correct code would be:

    private int getEssenceConsumed(int experienceLevel) {
        int xp = 0;
        if (experienceLevel >= 0 && experienceLevel <= 16)
            xp = (int) (Math.pow(experienceLevel, 2) + 6 * experienceLevel);
        if (experienceLevel >= 17 && experienceLevel <= 31)
            xp = (int) (2.5 * Math.pow(experienceLevel, 2) - 40.5 * experienceLevel + 360);
        if (experienceLevel >= 32) 
            xp = (int) (4.5 * Math.pow(experienceLevel, 2) - 162.5 * experienceLevel + 2220);
        return xp * 20;
    }

Looks a lot nicer if you graph it :)
image

commented

It is true that ranges are wrong but the formula is from the minecraft wiki

I just saw! :) But! Some of the numbers are different from the wiki :)
Especially there's a 5.5 instead of 4.5!

commented

Just to visualize the differences:
image