Modernize private property declarations in src/entity

This commit is contained in:
Dylan K. Taylor 2022-05-17 20:42:17 +01:00
parent 343a12626e
commit ec6769a6fc
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
13 changed files with 49 additions and 96 deletions

View File

@ -29,7 +29,7 @@ final class AttributeFactory{
use SingletonTrait; use SingletonTrait;
/** @var Attribute[] */ /** @var Attribute[] */
private $attributes = []; private array $attributes = [];
public function __construct(){ public function __construct(){
$this->register(Attribute::ABSORPTION, 0.00, 340282346638528859811704183484516925440.00, 0.00); $this->register(Attribute::ABSORPTION, 0.00, 340282346638528859811704183484516925440.00, 0.00);

View File

@ -27,7 +27,7 @@ use function array_filter;
class AttributeMap{ class AttributeMap{
/** @var Attribute[] */ /** @var Attribute[] */
private $attributes = []; private array $attributes = [];
public function add(Attribute $attribute) : void{ public function add(Attribute $attribute) : void{
$this->attributes[$attribute->getId()] = $attribute; $this->attributes[$attribute->getId()] = $attribute;

View File

@ -96,8 +96,7 @@ abstract class Entity{
/** @var int */ /** @var int */
protected $id; protected $id;
/** @var EntityMetadataCollection */ private EntityMetadataCollection $networkProperties;
private $networkProperties;
/** @var EntityDamageEvent|null */ /** @var EntityDamageEvent|null */
protected $lastDamageCause = null; protected $lastDamageCause = null;
@ -124,10 +123,8 @@ abstract class Entity{
/** @var EntitySizeInfo */ /** @var EntitySizeInfo */
public $size; public $size;
/** @var float */ private float $health = 20.0;
private $health = 20.0; private int $maxHealth = 20;
/** @var int */
private $maxHealth = 20;
/** @var float */ /** @var float */
protected $ySize = 0.0; protected $ySize = 0.0;
@ -150,8 +147,7 @@ abstract class Entity{
/** @var bool */ /** @var bool */
protected $isStatic = false; protected $isStatic = false;
/** @var bool */ private bool $savedWithChunk = true;
private $savedWithChunk = true;
/** @var bool */ /** @var bool */
public $isCollided = false; public $isCollided = false;
@ -181,8 +177,7 @@ abstract class Entity{
/** @var bool */ /** @var bool */
protected $closed = false; protected $closed = false;
private bool $closeInFlight = false; private bool $closeInFlight = false;
/** @var bool */ private bool $needsDespawn = false;
private $needsDespawn = false;
/** @var TimingsHandler */ /** @var TimingsHandler */
protected $timings; protected $timings;

View File

@ -70,12 +70,12 @@ final class EntityFactory{
* @var \Closure[] save ID => creator function * @var \Closure[] save ID => creator function
* @phpstan-var array<int|string, \Closure(World, CompoundTag) : Entity> * @phpstan-var array<int|string, \Closure(World, CompoundTag) : Entity>
*/ */
private $creationFuncs = []; private array $creationFuncs = [];
/** /**
* @var string[] * @var string[]
* @phpstan-var array<class-string<Entity>, string> * @phpstan-var array<class-string<Entity>, string>
*/ */
private $saveNames = []; private array $saveNames = [];
public function __construct(){ public function __construct(){
//define legacy save IDs first - use them for saving for maximum compatibility with Minecraft PC //define legacy save IDs first - use them for saving for maximum compatibility with Minecraft PC

View File

@ -26,16 +26,13 @@ namespace pocketmine\entity;
use function min; use function min;
final class EntitySizeInfo{ final class EntitySizeInfo{
/** @var float */ private float $eyeHeight;
private $height;
/** @var float */
private $width;
/** @var float */
private $eyeHeight;
public function __construct(float $height, float $width, ?float $eyeHeight = null){ public function __construct(
$this->height = $height; private float $height,
$this->width = $width; private float $width,
?float $eyeHeight = null
){
$this->eyeHeight = $eyeHeight ?? min($this->height / 2 + 0.1, $this->height); $this->eyeHeight = $eyeHeight ?? min($this->height / 2 + 0.1, $this->height);
} }

View File

@ -38,26 +38,18 @@ use function min;
class ExperienceManager{ class ExperienceManager{
/** @var Human */ private Attribute $levelAttr;
private $entity; private Attribute $progressAttr;
/** @var Attribute */ private int $totalXp = 0;
private $levelAttr;
/** @var Attribute */
private $progressAttr;
/** @var int */ private bool $canAttractXpOrbs = true;
private $totalXp = 0;
/** @var bool */ private int $xpCooldown = 0;
private $canAttractXpOrbs = true;
/** @var int */
private $xpCooldown = 0;
public function __construct(Human $entity){
$this->entity = $entity;
public function __construct(
private Human $entity
){
$this->levelAttr = self::fetchAttribute($entity, Attribute::EXPERIENCE_LEVEL); $this->levelAttr = self::fetchAttribute($entity, Attribute::EXPERIENCE_LEVEL);
$this->progressAttr = self::fetchAttribute($entity, Attribute::EXPERIENCE); $this->progressAttr = self::fetchAttribute($entity, Attribute::EXPERIENCE);
} }

View File

@ -32,25 +32,17 @@ use function min;
class HungerManager{ class HungerManager{
/** @var Human */ private Attribute $hungerAttr;
private $entity; private Attribute $saturationAttr;
private Attribute $exhaustionAttr;
/** @var Attribute */ private int $foodTickTimer = 0;
private $hungerAttr;
/** @var Attribute */
private $saturationAttr;
/** @var Attribute */
private $exhaustionAttr;
/** @var int */ private bool $enabled = true;
private $foodTickTimer = 0;
/** @var bool */
private $enabled = true;
public function __construct(Human $entity){
$this->entity = $entity;
public function __construct(
private Human $entity
){
$this->hungerAttr = self::fetchAttribute($entity, Attribute::HUNGER); $this->hungerAttr = self::fetchAttribute($entity, Attribute::HUNGER);
$this->saturationAttr = self::fetchAttribute($entity, Attribute::SATURATION); $this->saturationAttr = self::fetchAttribute($entity, Attribute::SATURATION);
$this->exhaustionAttr = self::fetchAttribute($entity, Attribute::EXHAUSTION); $this->exhaustionAttr = self::fetchAttribute($entity, Attribute::EXHAUSTION);

View File

@ -39,16 +39,11 @@ final class Skin{
128 * 128 * 4 128 * 128 * 4
]; ];
/** @var string */ private string $skinId;
private $skinId; private string $skinData;
/** @var string */ private string $capeData;
private $skinData; private string $geometryName;
/** @var string */ private string $geometryData;
private $capeData;
/** @var string */
private $geometryName;
/** @var string */
private $geometryData;
private static function checkLength(string $string, string $name, int $maxLength) : void{ private static function checkLength(string $string, string $name, int $maxLength) : void{
if(strlen($string) > $maxLength){ if(strlen($string) > $maxLength){

View File

@ -44,8 +44,7 @@ class Squid extends WaterAnimal{
/** @var float */ /** @var float */
public $swimSpeed = 0.1; public $swimSpeed = 0.1;
/** @var int */ private int $switchDirectionTicker = 0;
private $switchDirectionTicker = 0;
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.95, 0.95); } protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.95, 0.95); }

View File

@ -38,10 +38,8 @@ class Villager extends Living implements Ageable{
public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; } public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; }
/** @var bool */ private bool $baby = false;
private $baby = false; private int $profession = self::PROFESSION_FARMER;
/** @var int */
private $profession = self::PROFESSION_FARMER;
protected function getInitialSizeInfo() : EntitySizeInfo{ protected function getInitialSizeInfo() : EntitySizeInfo{
return new EntitySizeInfo(1.8, 0.6); //TODO: eye height?? return new EntitySizeInfo(1.8, 0.6); //TODO: eye height??

View File

@ -28,23 +28,12 @@ use pocketmine\utils\Limits;
use function max; use function max;
class EffectInstance{ class EffectInstance{
/** @var Effect */ private Effect $effectType;
private $effectType; private int $duration;
private int $amplifier;
/** @var int */ private bool $visible;
private $duration; private bool $ambient;
private Color $color;
/** @var int */
private $amplifier;
/** @var bool */
private $visible;
/** @var bool */
private $ambient;
/** @var Color */
private $color;
/** /**
* @param int|null $duration Passing null will use the effect type's default duration * @param int|null $duration Passing null will use the effect type's default duration

View File

@ -34,9 +34,6 @@ use function spl_object_id;
class EffectManager{ class EffectManager{
/** @var Living */
private $entity;
/** @var EffectInstance[] */ /** @var EffectInstance[] */
protected $effects = []; protected $effects = [];
@ -56,8 +53,9 @@ class EffectManager{
*/ */
protected $effectRemoveHooks; protected $effectRemoveHooks;
public function __construct(Living $entity){ public function __construct(
$this->entity = $entity; private Living $entity
){
$this->bubbleColor = new Color(0, 0, 0, 0); $this->bubbleColor = new Color(0, 0, 0, 0);
$this->effectAddHooks = new ObjectSet(); $this->effectAddHooks = new ObjectSet();
$this->effectRemoveHooks = new ObjectSet(); $this->effectRemoveHooks = new ObjectSet();

View File

@ -30,9 +30,7 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\lang\Translatable; use pocketmine\lang\Translatable;
class PoisonEffect extends Effect{ class PoisonEffect extends Effect{
private bool $fatal;
/** @var bool */
private $fatal;
public function __construct(Translatable|string $name, Color $color, bool $isBad = false, int $defaultDuration = 600, bool $hasBubbles = true, bool $fatal = false){ public function __construct(Translatable|string $name, Color $color, bool $isBad = false, int $defaultDuration = 600, bool $hasBubbles = true, bool $fatal = false){
parent::__construct($name, $color, $isBad, $defaultDuration, $hasBubbles); parent::__construct($name, $color, $isBad, $defaultDuration, $hasBubbles);