PlayerData.updatePlayerStats drops player health when entering the nether
notcake opened this issue ยท 2 comments
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.
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.