Modernize property declarations in pocketmine\block namespace

This commit is contained in:
Dylan K. Taylor 2022-04-25 13:00:29 +01:00
parent 09778e3f1b
commit 72cff0ee11
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
23 changed files with 80 additions and 139 deletions

View File

@ -74,7 +74,7 @@ class BlockFactory{
* @var \SplFixedArray|Block[] * @var \SplFixedArray|Block[]
* @phpstan-var \SplFixedArray<Block> * @phpstan-var \SplFixedArray<Block>
*/ */
private $fullList; private \SplFixedArray $fullList;
/** /**
* @var \SplFixedArray|int[] * @var \SplFixedArray|int[]
@ -86,22 +86,22 @@ class BlockFactory{
* @var \SplFixedArray|int[] * @var \SplFixedArray|int[]
* @phpstan-var \SplFixedArray<int> * @phpstan-var \SplFixedArray<int>
*/ */
public $light; public \SplFixedArray $light;
/** /**
* @var \SplFixedArray|int[] * @var \SplFixedArray|int[]
* @phpstan-var \SplFixedArray<int> * @phpstan-var \SplFixedArray<int>
*/ */
public $lightFilter; public \SplFixedArray $lightFilter;
/** /**
* @var \SplFixedArray|bool[] * @var \SplFixedArray|bool[]
* @phpstan-var \SplFixedArray<bool> * @phpstan-var \SplFixedArray<bool>
*/ */
public $blocksDirectSkyLight; public \SplFixedArray $blocksDirectSkyLight;
/** /**
* @var \SplFixedArray|float[] * @var \SplFixedArray|float[]
* @phpstan-var \SplFixedArray<float> * @phpstan-var \SplFixedArray<float>
*/ */
public $blastResistance; public \SplFixedArray $blastResistance;
public function __construct(){ public function __construct(){
$this->fullList = new \SplFixedArray(1024 << Block::INTERNAL_METADATA_BITS); $this->fullList = new \SplFixedArray(1024 << Block::INTERNAL_METADATA_BITS);

View File

@ -33,10 +33,8 @@ use pocketmine\world\sound\Sound;
class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{ class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{
use AnimatedBlockInventoryTrait; use AnimatedBlockInventoryTrait;
/** @var ChestInventory */ private ChestInventory $left;
private $left; private ChestInventory $right;
/** @var ChestInventory */
private $right;
public function __construct(ChestInventory $left, ChestInventory $right){ public function __construct(ChestInventory $left, ChestInventory $right){
$this->left = $left; $this->left = $left;

View File

@ -44,14 +44,13 @@ class Banner extends Spawnable{
public const TAG_PATTERN_COLOR = "Color"; public const TAG_PATTERN_COLOR = "Color";
public const TAG_PATTERN_NAME = "Pattern"; public const TAG_PATTERN_NAME = "Pattern";
/** @var DyeColor */ private DyeColor $baseColor;
private $baseColor;
/** /**
* @var BannerPatternLayer[] * @var BannerPatternLayer[]
* @phpstan-var list<BannerPatternLayer> * @phpstan-var list<BannerPatternLayer>
*/ */
private $patterns = []; private array $patterns = [];
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
$this->baseColor = DyeColor::BLACK(); $this->baseColor = DyeColor::BLACK();

View File

@ -29,10 +29,8 @@ final class Beacon extends Spawnable{
private const TAG_PRIMARY = "primary"; //TAG_Int private const TAG_PRIMARY = "primary"; //TAG_Int
private const TAG_SECONDARY = "secondary"; //TAG_Int private const TAG_SECONDARY = "secondary"; //TAG_Int
/** @var int */ private int $primaryEffect = 0;
private $primaryEffect = 0; private int $secondaryEffect = 0;
/** @var int */
private $secondaryEffect = 0;
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
$nbt->setInt(self::TAG_PRIMARY, $this->primaryEffect); $nbt->setInt(self::TAG_PRIMARY, $this->primaryEffect);

View File

@ -32,8 +32,8 @@ use pocketmine\world\World;
class Bed extends Spawnable{ class Bed extends Spawnable{
public const TAG_COLOR = "color"; public const TAG_COLOR = "color";
/** @var DyeColor */
private $color; private DyeColor $color;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
$this->color = DyeColor::RED(); $this->color = DyeColor::RED();

View File

@ -49,10 +49,8 @@ class Chest extends Spawnable implements Container, Nameable{
/** @var DoubleChestInventory|null */ /** @var DoubleChestInventory|null */
protected $doubleInventory = null; protected $doubleInventory = null;
/** @var int|null */ private ?int $pairX = null;
private $pairX; private ?int $pairZ = null;
/** @var int|null */
private $pairZ;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos); parent::__construct($world, $pos);

View File

@ -38,8 +38,7 @@ class FlowerPot extends Spawnable{
private const TAG_ITEM = "item"; private const TAG_ITEM = "item";
private const TAG_ITEM_DATA = "mData"; private const TAG_ITEM_DATA = "mData";
/** @var Block|null */ private ?Block $plant = null;
private $plant = null;
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag && ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){ if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag && ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){

View File

@ -50,12 +50,9 @@ abstract class Furnace extends Spawnable implements Container, Nameable{
/** @var FurnaceInventory */ /** @var FurnaceInventory */
protected $inventory; protected $inventory;
/** @var int */ private int $remainingFuelTime = 0;
private $remainingFuelTime = 0; private int $cookTime = 0;
/** @var int */ private int $maxFuelTime = 0;
private $cookTime = 0;
/** @var int */
private $maxFuelTime = 0;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos); parent::__construct($world, $pos);

View File

@ -35,11 +35,8 @@ class Hopper extends Spawnable implements Container, Nameable{
private const TAG_TRANSFER_COOLDOWN = "TransferCooldown"; private const TAG_TRANSFER_COOLDOWN = "TransferCooldown";
/** @var HopperInventory */ private HopperInventory $inventory;
private $inventory; private int $transferCooldown = 0;
/** @var int */
private $transferCooldown = 0;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos); parent::__construct($world, $pos);

View File

@ -38,12 +38,9 @@ class ItemFrame extends Spawnable{
public const TAG_ITEM_DROP_CHANCE = "ItemDropChance"; public const TAG_ITEM_DROP_CHANCE = "ItemDropChance";
public const TAG_ITEM = "Item"; public const TAG_ITEM = "Item";
/** @var Item */ private Item $item;
private $item; private int $itemRotation = 0;
/** @var int */ private float $itemDropChance = 1.0;
private $itemRotation = 0;
/** @var float */
private $itemDropChance = 1.0;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
$this->item = VanillaItems::AIR(); $this->item = VanillaItems::AIR();

View File

@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag;
class Jukebox extends Spawnable{ class Jukebox extends Spawnable{
private const TAG_RECORD = "RecordItem"; //Item CompoundTag private const TAG_RECORD = "RecordItem"; //Item CompoundTag
/** @var Record|null */ private ?Record $record = null;
private $record = null;
public function getRecord() : ?Record{ public function getRecord() : ?Record{
return $this->record; return $this->record;

View File

@ -56,43 +56,24 @@ class MonsterSpawner extends Spawnable{
public const DEFAULT_SPAWN_RANGE = 4; //blocks public const DEFAULT_SPAWN_RANGE = 4; //blocks
public const DEFAULT_REQUIRED_PLAYER_RANGE = 16; public const DEFAULT_REQUIRED_PLAYER_RANGE = 16;
/** /** TODO: replace this with a cached entity or something of that nature */
* @var string private string $entityTypeId = ":";
* TODO: replace this with a cached entity or something of that nature /** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */
*/ private ?ListTag $spawnPotentials = null;
private $entityTypeId = ":"; /** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */
/** private ?CompoundTag $spawnData = null;
* @var ListTag|null
* TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun)
*/
private $spawnPotentials = null;
/**
* @var CompoundTag|null
* TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun)
*/
private $spawnData = null;
/** @var float */ private float $displayEntityWidth = 1.0;
private $displayEntityWidth = 1; private float $displayEntityHeight = 1.0;
/** @var float */ private float $displayEntityScale = 1.0;
private $displayEntityHeight = 1;
/** @var float */
private $displayEntityScale = 1;
/** @var int */ private int $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
private $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; private int $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
/** @var int */ private int $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY;
private $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; private int $spawnPerAttempt = 1;
/** @var int */ private int $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES;
private $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY; private int $spawnRange = self::DEFAULT_SPAWN_RANGE;
/** @var int */ private int $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
private $spawnPerAttempt = 1;
/** @var int */
private $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES;
/** @var int */
private $spawnRange = self::DEFAULT_SPAWN_RANGE;
/** @var int */
private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){ if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){

View File

@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag;
* @deprecated * @deprecated
*/ */
class Note extends Tile{ class Note extends Tile{
/** @var int */ private int $pitch = 0;
private $pitch = 0;
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
if(($pitch = $nbt->getByte("note", $this->pitch)) > BlockNote::MIN_PITCH && $pitch <= BlockNote::MAX_PITCH){ if(($pitch = $nbt->getByte("note", $this->pitch)) > BlockNote::MIN_PITCH && $pitch <= BlockNote::MAX_PITCH){

View File

@ -40,10 +40,8 @@ class Skull extends Spawnable{
private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte
private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int
/** @var SkullType */ private SkullType $skullType;
private $skullType; private int $skullRotation = 0;
/** @var int */
private $skullRotation = 0;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
$this->skullType = SkullType::SKELETON(); $this->skullType = SkullType::SKELETON();

View File

@ -28,11 +28,8 @@ use pocketmine\network\mcpe\protocol\types\CacheableNbt;
use function get_class; use function get_class;
abstract class Spawnable extends Tile{ abstract class Spawnable extends Tile{
/** /** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null */
* @var CacheableNbt|null private ?CacheableNbt $spawnCompoundCache = null;
* @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null
*/
private $spawnCompoundCache = null;
/** /**
* @deprecated * @deprecated

View File

@ -42,12 +42,12 @@ final class TileFactory{
* @var string[] classes that extend Tile * @var string[] classes that extend Tile
* @phpstan-var array<string, class-string<Tile>> * @phpstan-var array<string, class-string<Tile>>
*/ */
private $knownTiles = []; private array $knownTiles = [];
/** /**
* @var string[] * @var string[]
* @phpstan-var array<class-string<Tile>, string> * @phpstan-var array<class-string<Tile>, string>
*/ */
private $saveNames = []; private array $saveNames = [];
public function __construct(){ public function __construct(){
$this->register(Barrel::class, ["Barrel", "minecraft:barrel"]); $this->register(Barrel::class, ["Barrel", "minecraft:barrel"]);

View File

@ -30,14 +30,10 @@ use pocketmine\block\BaseBanner;
* @see BaseBanner * @see BaseBanner
*/ */
class BannerPatternLayer{ class BannerPatternLayer{
private BannerPatternType $type; public function __construct(
/** @var DyeColor */ private BannerPatternType $type,
private $color; private DyeColor $color
){}
public function __construct(BannerPatternType $type, DyeColor $color){
$this->type = $type;
$this->color = $color;
}
public function getType() : BannerPatternType{ return $this->type; } public function getType() : BannerPatternType{ return $this->type; }

View File

@ -42,9 +42,6 @@ final class CoralType{
__construct as Enum___construct; __construct as Enum___construct;
} }
/** @var string */
private $displayName;
protected static function setup() : void{ protected static function setup() : void{
self::registerAll( self::registerAll(
new self("tube", "Tube"), new self("tube", "Tube"),
@ -55,9 +52,11 @@ final class CoralType{
); );
} }
private function __construct(string $name, string $displayName){ private function __construct(
string $name,
private string $displayName
){
$this->Enum___construct($name); $this->Enum___construct($name);
$this->displayName = $displayName;
} }
public function getDisplayName() : string{ return $this->displayName; } public function getDisplayName() : string{ return $this->displayName; }

View File

@ -75,15 +75,12 @@ final class DyeColor{
); );
} }
/** @var string */ private function __construct(
private $displayName; string $enumName,
/** @var Color */ private string $displayName,
private $rgbValue; private Color $rgbValue
){
private function __construct(string $enumName, string $displayName, Color $rgbValue){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->rgbValue = $rgbValue;
} }
public function getDisplayName() : string{ public function getDisplayName() : string{

View File

@ -70,15 +70,13 @@ final class RecordType{
); );
} }
/** @var string */ private function __construct(
private $soundName; string $enumName,
/** @var int */ private string $soundName,
private $soundId; private int $soundId,
private Translatable $translatableName
private function __construct(string $enumName, string $soundName, int $soundId, private Translatable $translatableName){ ){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->soundName = $soundName;
$this->soundId = $soundId;
} }
public function getSoundName() : string{ public function getSoundName() : string{

View File

@ -36,7 +36,7 @@ class SignText{
public const LINE_COUNT = 4; public const LINE_COUNT = 4;
/** @var string[] */ /** @var string[] */
private $lines; private array $lines;
/** /**
* @param string[]|null $lines index-sensitive; omitting an index will leave it unchanged * @param string[]|null $lines index-sensitive; omitting an index will leave it unchanged

View File

@ -45,7 +45,7 @@ final class SkullType{
} }
/** @var SkullType[] */ /** @var SkullType[] */
private static $numericIdMap = []; private static array $numericIdMap = [];
protected static function setup() : void{ protected static function setup() : void{
self::registerAll( self::registerAll(
@ -75,15 +75,12 @@ final class SkullType{
return self::$numericIdMap[$magicNumber]; return self::$numericIdMap[$magicNumber];
} }
/** @var string */ private function __construct(
private $displayName; string $enumName,
/** @var int */ private string $displayName,
private $magicNumber; private int $magicNumber
){
private function __construct(string $enumName, string $displayName, int $magicNumber){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->magicNumber = $magicNumber;
} }
public function getDisplayName() : string{ public function getDisplayName() : string{

View File

@ -45,7 +45,7 @@ final class TreeType{
} }
/** @var TreeType[] */ /** @var TreeType[] */
private static $numericIdMap = []; private static array $numericIdMap = [];
protected static function setup() : void{ protected static function setup() : void{
self::registerAll( self::registerAll(
@ -76,15 +76,12 @@ final class TreeType{
return self::$numericIdMap[$magicNumber]; return self::$numericIdMap[$magicNumber];
} }
/** @var string */ private function __construct(
private $displayName; string $enumName,
/** @var int */ private string $displayName,
private $magicNumber; private int $magicNumber
){
private function __construct(string $enumName, string $displayName, int $magicNumber){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->magicNumber = $magicNumber;
} }
public function getDisplayName() : string{ public function getDisplayName() : string{