mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
Migrate all but two remaining legacy enums to native PHP 8.1 enums
This commit is contained in:
@@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\utils\EnumTrait;
|
||||
use pocketmine\utils\LegacyEnumShimTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
@@ -37,48 +37,55 @@ use pocketmine\utils\EnumTrait;
|
||||
* @method static ToolTier NETHERITE()
|
||||
* @method static ToolTier STONE()
|
||||
* @method static ToolTier WOOD()
|
||||
*
|
||||
* @phpstan-type TMetadata array{0: int, 1: int, 2: int, 3: int, 4: int}
|
||||
*/
|
||||
final class ToolTier{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
enum ToolTier{
|
||||
use LegacyEnumShimTrait;
|
||||
|
||||
case WOOD;
|
||||
case GOLD;
|
||||
case STONE;
|
||||
case IRON;
|
||||
case DIAMOND;
|
||||
case NETHERITE;
|
||||
|
||||
/**
|
||||
* This function exists only to permit the use of named arguments and to make the code easier to read in PhpStorm.
|
||||
* @phpstan-return TMetadata
|
||||
*/
|
||||
private static function meta(int $harvestLevel, int $maxDurability, int $baseAttackPoints, int $baseEfficiency, int $enchantability) : array{
|
||||
return [$harvestLevel, $maxDurability, $baseAttackPoints, $baseEfficiency, $enchantability];
|
||||
}
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("wood", 1, 60, 5, 2, 15),
|
||||
new self("gold", 2, 33, 5, 12, 22),
|
||||
new self("stone", 3, 132, 6, 4, 5),
|
||||
new self("iron", 4, 251, 7, 6, 14),
|
||||
new self("diamond", 5, 1562, 8, 8, 10),
|
||||
new self("netherite", 6, 2032, 9, 9, 15)
|
||||
);
|
||||
}
|
||||
|
||||
private function __construct(
|
||||
string $name,
|
||||
private int $harvestLevel,
|
||||
private int $maxDurability,
|
||||
private int $baseAttackPoints,
|
||||
private int $baseEfficiency,
|
||||
private int $enchantability
|
||||
){
|
||||
$this->Enum___construct($name);
|
||||
/**
|
||||
* @phpstan-return TMetadata
|
||||
*/
|
||||
private function getMetadata() : array{
|
||||
return match($this){
|
||||
self::WOOD => self::meta(1, 60, 5, 2, 15),
|
||||
self::GOLD => self::meta(2, 33, 5, 12, 22),
|
||||
self::STONE => self::meta(3, 132, 6, 4, 5),
|
||||
self::IRON => self::meta(4, 251, 7, 6, 14),
|
||||
self::DIAMOND => self::meta(5, 1562, 8, 8, 10),
|
||||
self::NETHERITE => self::meta(6, 2032, 9, 9, 15)
|
||||
};
|
||||
}
|
||||
|
||||
public function getHarvestLevel() : int{
|
||||
return $this->harvestLevel;
|
||||
return $this->getMetadata()[0];
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return $this->maxDurability;
|
||||
return $this->getMetadata()[1];
|
||||
}
|
||||
|
||||
public function getBaseAttackPoints() : int{
|
||||
return $this->baseAttackPoints;
|
||||
return $this->getMetadata()[2];
|
||||
}
|
||||
|
||||
public function getBaseEfficiency() : int{
|
||||
return $this->baseEfficiency;
|
||||
return $this->getMetadata()[3];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +95,6 @@ final class ToolTier{
|
||||
* or multiple enchantments upon being enchanted in an enchanting table.
|
||||
*/
|
||||
public function getEnchantability() : int{
|
||||
return $this->enchantability;
|
||||
return $this->getMetadata()[4];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user