mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Merge branch 'stable' into master
# Conflicts: # composer.lock # resources/vanilla # src/entity/Living.php # src/pocketmine/Player.php # src/pocketmine/VersionInfo.php # src/pocketmine/block/Potato.php # src/pocketmine/block/Sugarcane.php # src/pocketmine/entity/Entity.php # src/pocketmine/item/Item.php # src/pocketmine/level/format/Chunk.php # src/pocketmine/level/format/io/leveldb/LevelDB.php # src/world/generator/GeneratorRegisterTask.php # tests/phpstan/configs/check-explicit-mixed-baseline.neon # tests/phpstan/configs/l7-baseline.neon # tests/phpstan/configs/l8-baseline.neon # tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php # tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php # tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskPublishProgressRaceTest.php
This commit is contained in:
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity\utils;
|
||||
|
||||
use pocketmine\math\Math;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use function max;
|
||||
|
||||
abstract class ExperienceUtils{
|
||||
@ -59,6 +60,9 @@ abstract class ExperienceUtils{
|
||||
* This returns a floating-point number, the decimal part being the progress through the resulting level.
|
||||
*/
|
||||
public static function getLevelFromXp(int $xp) : float{
|
||||
if($xp < 0){
|
||||
throw new \InvalidArgumentException("XP must be at least 0");
|
||||
}
|
||||
if($xp <= self::getXpToReachLevel(16)){
|
||||
$a = 1;
|
||||
$b = 6;
|
||||
@ -74,6 +78,9 @@ abstract class ExperienceUtils{
|
||||
}
|
||||
|
||||
$x = Math::solveQuadratic($a, $b, $c - $xp);
|
||||
if(count($x) === 0){
|
||||
throw new AssumptionFailedError("Expected at least 1 solution");
|
||||
}
|
||||
|
||||
return max($x); //we're only interested in the positive solution
|
||||
}
|
||||
|
Reference in New Issue
Block a user