MK: Ultra

MK: Ultra

59.5k Downloads

PlayerData.updatePlayerStats drops player health when entering the nether

notcake opened this issue ยท 2 comments

commented

Version: 0.99.11

The setHealth calls in PlayerData.updatePlayerStats incorrectly calculate the max health of players and use the base value of MAX_HEALTH instead. This ignores max health modifiers from Orb Mother talents and also every other mod, resulting in a loss of health when entering and leaving the nether when these health modifiers are in effect.

https://github.com/ChaosBuffalo/MKUltra/blob/master/src/main/java/com/chaosbuffalo/mkultra/core/PlayerData.java#L499

if (!hasChosenClass()) {
    // ...
    setHealth(Math.min(20, this.player.getHealth()));
    setTotalHealth(20);
    // ...
} else {
    // ...
    setTotalHealth(newTotalHealth);
    setHealth(Math.min(newTotalHealth, this.player.getHealth()));
    // ...
}

should be something like:

if (!hasChosenClass()) {
    // ...
    setTotalHealth(20); // setTotalHealth() must be called *before* getTotalHealth()
    setHealth(Math.min(getTotalHealth(), this.player.getHealth()));
    // ...
} else {
    // ...
    setTotalHealth(newTotalHealth);
    setHealth(Math.min(getTotalHealth(), this.player.getHealth()));
    // ...
}

Note that getTotalHealth() does not return the same value as set in setTotalHealth().
getTotalHealth takes into account all MAX_HEALTH modifiers while setTotalHealth sets the MAX_HEALTH base value.

commented

Thank ya'll for finding this issue. Please consider opening a PR with the fix.

commented

Looks like ralekdev has PR'd in a more comprehensive fix while we were distracted with modded minecraft. Thank you both for getting a fix into master!