diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 57669c18e..14a0ed730 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -90,120 +90,79 @@ abstract class Entity{ } /** @var Player[] */ - protected $hasSpawned = []; + protected array $hasSpawned = []; - /** @var int */ - protected $id; + protected int $id; private EntityMetadataCollection $networkProperties; - /** @var EntityDamageEvent|null */ - protected $lastDamageCause = null; + protected ?EntityDamageEvent $lastDamageCause = null; /** @var Block[]|null */ - protected $blocksAround; + protected ?array $blocksAround = null; - /** @var Location */ - protected $location; - /** @var Location */ - protected $lastLocation; - /** @var Vector3 */ - protected $motion; - /** @var Vector3 */ - protected $lastMotion; - /** @var bool */ - protected $forceMovementUpdate = false; + protected Location $location; + protected Location $lastLocation; + protected Vector3 $motion; + protected Vector3 $lastMotion; + protected bool $forceMovementUpdate = false; - /** @var AxisAlignedBB */ - public $boundingBox; - /** @var bool */ - public $onGround = false; + public AxisAlignedBB $boundingBox; + public bool $onGround = false; - /** @var EntitySizeInfo */ - public $size; + public EntitySizeInfo $size; private float $health = 20.0; private int $maxHealth = 20; - /** @var float */ - protected $ySize = 0.0; - /** @var float */ - protected $stepHeight = 0.0; - /** @var bool */ - public $keepMovement = false; + protected float $ySize = 0.0; + protected float $stepHeight = 0.0; + public bool $keepMovement = false; - /** @var float */ - public $fallDistance = 0.0; - /** @var int */ - public $ticksLived = 0; - /** @var int */ - public $lastUpdate; - /** @var int */ - protected $fireTicks = 0; + public float $fallDistance = 0.0; + public int $ticksLived = 0; + public int $lastUpdate; + protected int $fireTicks = 0; private bool $savedWithChunk = true; - /** @var bool */ - public $isCollided = false; - /** @var bool */ - public $isCollidedHorizontally = false; - /** @var bool */ - public $isCollidedVertically = false; + public bool $isCollided = false; + public bool $isCollidedHorizontally = false; + public bool $isCollidedVertically = false; - /** @var int */ - public $noDamageTicks = 0; - /** @var bool */ - protected $justCreated = true; + public int $noDamageTicks = 0; + protected bool $justCreated = true; - /** @var AttributeMap */ - protected $attributeMap; + protected AttributeMap $attributeMap; - /** @var float */ - protected $gravity; - /** @var float */ - protected $drag; - /** @var bool */ - protected $gravityEnabled = true; + protected float $gravity; + protected float $drag; + protected bool $gravityEnabled = true; - /** @var Server */ - protected $server; + protected Server $server; - /** @var bool */ - protected $closed = false; + protected bool $closed = false; private bool $closeInFlight = false; private bool $needsDespawn = false; - /** @var TimingsHandler */ - protected $timings; + protected TimingsHandler $timings; protected bool $networkPropertiesDirty = false; - /** @var string */ - protected $nameTag = ""; - /** @var bool */ - protected $nameTagVisible = true; - /** @var bool */ - protected $alwaysShowNameTag = false; - /** @var string */ - protected $scoreTag = ""; - /** @var float */ - protected $scale = 1.0; + protected string $nameTag = ""; + protected bool $nameTagVisible = true; + protected bool $alwaysShowNameTag = false; + protected string $scoreTag = ""; + protected float $scale = 1.0; - /** @var bool */ - protected $canClimb = false; - /** @var bool */ - protected $canClimbWalls = false; - /** @var bool */ - protected $immobile = false; - /** @var bool */ - protected $invisible = false; - /** @var bool */ - protected $silent = false; + protected bool $canClimb = false; + protected bool $canClimbWalls = false; + protected bool $immobile = false; + protected bool $invisible = false; + protected bool $silent = false; - /** @var int|null */ - protected $ownerId = null; - /** @var int|null */ - protected $targetId = null; + protected ?int $ownerId = null; + protected ?int $targetId = null; private bool $constructorCalled = false; diff --git a/src/entity/Human.php b/src/entity/Human.php index ac105df30..a486c9d99 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -74,28 +74,18 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; } - /** @var PlayerInventory */ - protected $inventory; + protected PlayerInventory $inventory; + protected PlayerOffHandInventory $offHandInventory; + protected PlayerEnderInventory $enderInventory; - /** @var PlayerOffHandInventory */ - protected $offHandInventory; + protected UuidInterface $uuid; - /** @var PlayerEnderInventory */ - protected $enderInventory; + protected Skin $skin; - /** @var UuidInterface */ - protected $uuid; + protected HungerManager $hungerManager; + protected ExperienceManager $xpManager; - /** @var Skin */ - protected $skin; - - /** @var HungerManager */ - protected $hungerManager; - /** @var ExperienceManager */ - protected $xpManager; - - /** @var int */ - protected $xpSeed; + protected int $xpSeed; public function __construct(Location $location, Skin $skin, ?CompoundTag $nbt = null){ $this->skin = $skin; @@ -383,9 +373,9 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ public function getDrops() : array{ return array_filter(array_merge( - $this->inventory !== null ? array_values($this->inventory->getContents()) : [], - $this->armorInventory !== null ? array_values($this->armorInventory->getContents()) : [], - $this->offHandInventory !== null ? array_values($this->offHandInventory->getContents()) : [], + array_values($this->inventory->getContents()), + array_values($this->armorInventory->getContents()), + array_values($this->offHandInventory->getContents()), ), function(Item $item) : bool{ return !$item->hasEnchantment(VanillaEnchantments::VANISHING()); }); } @@ -404,55 +394,51 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ $inventoryTag = new ListTag([], NBT::TAG_Compound); $nbt->setTag("Inventory", $inventoryTag); - if($this->inventory !== null){ - //Normal inventory - $slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize(); - for($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot){ - $item = $this->inventory->getItem($slot - 9); - if(!$item->isNull()){ - $inventoryTag->push($item->nbtSerialize($slot)); - } - } - //Armor - for($slot = 100; $slot < 104; ++$slot){ - $item = $this->armorInventory->getItem($slot - 100); - if(!$item->isNull()){ - $inventoryTag->push($item->nbtSerialize($slot)); - } + //Normal inventory + $slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize(); + for($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot){ + $item = $this->inventory->getItem($slot - 9); + if(!$item->isNull()){ + $inventoryTag->push($item->nbtSerialize($slot)); } - - $nbt->setInt("SelectedInventorySlot", $this->inventory->getHeldItemIndex()); } + + //Armor + for($slot = 100; $slot < 104; ++$slot){ + $item = $this->armorInventory->getItem($slot - 100); + if(!$item->isNull()){ + $inventoryTag->push($item->nbtSerialize($slot)); + } + } + + $nbt->setInt("SelectedInventorySlot", $this->inventory->getHeldItemIndex()); + $offHandItem = $this->offHandInventory->getItem(0); if(!$offHandItem->isNull()){ $nbt->setTag("OffHandItem", $offHandItem->nbtSerialize()); } - if($this->enderInventory !== null){ - /** @var CompoundTag[] $items */ - $items = []; + /** @var CompoundTag[] $items */ + $items = []; - $slotCount = $this->enderInventory->getSize(); - for($slot = 0; $slot < $slotCount; ++$slot){ - $item = $this->enderInventory->getItem($slot); - if(!$item->isNull()){ - $items[] = $item->nbtSerialize($slot); - } + $slotCount = $this->enderInventory->getSize(); + for($slot = 0; $slot < $slotCount; ++$slot){ + $item = $this->enderInventory->getItem($slot); + if(!$item->isNull()){ + $items[] = $item->nbtSerialize($slot); } - - $nbt->setTag("EnderChestInventory", new ListTag($items, NBT::TAG_Compound)); } - if($this->skin !== null){ - $nbt->setTag("Skin", CompoundTag::create() - ->setString("Name", $this->skin->getSkinId()) - ->setByteArray("Data", $this->skin->getSkinData()) - ->setByteArray("CapeData", $this->skin->getCapeData()) - ->setString("GeometryName", $this->skin->getGeometryName()) - ->setByteArray("GeometryData", $this->skin->getGeometryData()) - ); - } + $nbt->setTag("EnderChestInventory", new ListTag($items, NBT::TAG_Compound)); + + $nbt->setTag("Skin", CompoundTag::create() + ->setString("Name", $this->skin->getSkinId()) + ->setByteArray("Data", $this->skin->getSkinData()) + ->setByteArray("CapeData", $this->skin->getCapeData()) + ->setString("GeometryName", $this->skin->getGeometryName()) + ->setByteArray("GeometryData", $this->skin->getGeometryData()) + ); return $nbt; } @@ -512,11 +498,13 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ } protected function destroyCycles() : void{ - $this->inventory = null; - $this->offHandInventory = null; - $this->enderInventory = null; - $this->hungerManager = null; - $this->xpManager = null; + unset( + $this->inventory, + $this->offHandInventory, + $this->enderInventory, + $this->hungerManager, + $this->xpManager + ); parent::destroyCycles(); } } diff --git a/src/entity/Living.php b/src/entity/Living.php index 82cef8eb1..52dc02dbc 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -76,47 +76,30 @@ use const M_PI; abstract class Living extends Entity{ protected const DEFAULT_BREATH_TICKS = 300; - /** @var int */ - protected $attackTime = 0; + protected int $attackTime = 0; - /** @var int */ - public $deadTicks = 0; - /** @var int */ - protected $maxDeadTicks = 25; + public int $deadTicks = 0; + protected int $maxDeadTicks = 25; - /** @var float */ - protected $jumpVelocity = 0.42; + protected float $jumpVelocity = 0.42; - /** @var EffectManager */ - protected $effectManager; + protected EffectManager $effectManager; - /** @var ArmorInventory */ - protected $armorInventory; + protected ArmorInventory $armorInventory; - /** @var bool */ - protected $breathing = true; - /** @var int */ - protected $breathTicks = self::DEFAULT_BREATH_TICKS; - /** @var int */ - protected $maxBreathTicks = self::DEFAULT_BREATH_TICKS; + protected bool $breathing = true; + protected int $breathTicks = self::DEFAULT_BREATH_TICKS; + protected int $maxBreathTicks = self::DEFAULT_BREATH_TICKS; - /** @var Attribute */ - protected $healthAttr; - /** @var Attribute */ - protected $absorptionAttr; - /** @var Attribute */ - protected $knockbackResistanceAttr; - /** @var Attribute */ - protected $moveSpeedAttr; + protected Attribute $healthAttr; + protected Attribute $absorptionAttr; + protected Attribute $knockbackResistanceAttr; + protected Attribute $moveSpeedAttr; - /** @var bool */ - protected $sprinting = false; - /** @var bool */ - protected $sneaking = false; - /** @var bool */ - protected $gliding = false; - /** @var bool */ - protected $swimming = false; + protected bool $sprinting = false; + protected bool $sneaking = false; + protected bool $gliding = false; + protected bool $swimming = false; protected function getInitialDragMultiplier() : float{ return 0.02; } @@ -851,8 +834,10 @@ abstract class Living extends Entity{ } protected function destroyCycles() : void{ - $this->armorInventory = null; - $this->effectManager = null; + unset( + $this->armorInventory, + $this->effectManager + ); parent::destroyCycles(); } } diff --git a/src/entity/Squid.php b/src/entity/Squid.php index 5962ba1bb..697b4d8ee 100644 --- a/src/entity/Squid.php +++ b/src/entity/Squid.php @@ -39,10 +39,8 @@ class Squid extends WaterAnimal{ public static function getNetworkTypeId() : string{ return EntityIds::SQUID; } - /** @var Vector3|null */ - public $swimDirection = null; - /** @var float */ - public $swimSpeed = 0.1; + public ?Vector3 $swimDirection = null; + public float $swimSpeed = 0.1; private int $switchDirectionTicker = 0; diff --git a/src/entity/WaterAnimal.php b/src/entity/WaterAnimal.php index 5edae8ffd..9911e432b 100644 --- a/src/entity/WaterAnimal.php +++ b/src/entity/WaterAnimal.php @@ -28,8 +28,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; abstract class WaterAnimal extends Living implements Ageable{ - /** @var bool */ - protected $baby = false; + protected bool $baby = false; public function isBaby() : bool{ return $this->baby; diff --git a/src/entity/effect/EffectManager.php b/src/entity/effect/EffectManager.php index 910a88921..9eb8fc7c0 100644 --- a/src/entity/effect/EffectManager.php +++ b/src/entity/effect/EffectManager.php @@ -33,25 +33,22 @@ use function count; use function spl_object_id; class EffectManager{ - /** @var EffectInstance[] */ - protected $effects = []; + protected array $effects = []; - /** @var Color */ - protected $bubbleColor; - /** @var bool */ - protected $onlyAmbientEffects = false; + protected Color $bubbleColor; + protected bool $onlyAmbientEffects = false; /** * @var \Closure[]|ObjectSet * @phpstan-var ObjectSet<\Closure(EffectInstance, bool $replacesOldEffect) : void> */ - protected $effectAddHooks; + protected ObjectSet $effectAddHooks; /** * @var \Closure[]|ObjectSet * @phpstan-var ObjectSet<\Closure(EffectInstance) : void> */ - protected $effectRemoveHooks; + protected ObjectSet $effectRemoveHooks; public function __construct( private Living $entity diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index fc16c50f2..1c63b0ef3 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -78,23 +78,15 @@ class ExperienceOrb extends Entity{ return $result; } - /** @var int */ - protected $age = 0; + protected int $age = 0; - /** - * @var int - * Ticker used for determining interval in which to look for new target players. - */ - protected $lookForTargetTime = 0; + /** Ticker used for determining interval in which to look for new target players. */ + protected int $lookForTargetTime = 0; - /** - * @var int|null - * Runtime entity ID of the player this XP orb is targeting. - */ - protected $targetPlayerRuntimeId = null; + /** Runtime entity ID of the player this XP orb is targeting. */ + protected ?int $targetPlayerRuntimeId = null; - /** @var int */ - protected $xpValue; + protected int $xpValue; public function __construct(Location $location, int $xpValue, ?CompoundTag $nbt = null){ $this->xpValue = $xpValue; diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index 0dd8daebb..1a61a2fba 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -46,8 +46,7 @@ class FallingBlock extends Entity{ public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; } - /** @var Block */ - protected $block; + protected Block $block; public function __construct(Location $location, Block $block, ?CompoundTag $nbt = null){ $this->block = $block; diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 14b66c7d2..53b0b3383 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -50,17 +50,11 @@ class ItemEntity extends Entity{ public const NEVER_DESPAWN = -1; public const MAX_DESPAWN_DELAY = 32767 + self::DEFAULT_DESPAWN_DELAY; //max value storable by mojang NBT :( - /** @var string */ - protected $owner = ""; - /** @var string */ - protected $thrower = ""; - /** @var int */ - protected $pickupDelay = 0; - /** @var Item */ - protected $item; - - /** @var int */ - protected $despawnDelay = self::DEFAULT_DESPAWN_DELAY; + protected string $owner = ""; + protected string $thrower = ""; + protected int $pickupDelay = 0; + protected int $despawnDelay = self::DEFAULT_DESPAWN_DELAY; + protected Item $item; public function __construct(Location $location, Item $item, ?CompoundTag $nbt = null){ if($item->isNull()){ @@ -196,12 +190,8 @@ class ItemEntity extends Entity{ } $nbt->setShort("Age", $age); $nbt->setShort("PickupDelay", $this->pickupDelay); - if($this->owner !== null){ - $nbt->setString("Owner", $this->owner); - } - if($this->thrower !== null){ - $nbt->setString("Thrower", $this->thrower); - } + $nbt->setString("Owner", $this->owner); + $nbt->setString("Thrower", $this->thrower); return $nbt; } diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 16392dc74..4613af96c 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -56,12 +56,9 @@ class Painting extends Entity{ Facing::EAST => 3 ]; - /** @var Vector3 */ - protected $blockIn; - /** @var int */ - protected $facing = Facing::NORTH; - /** @var PaintingMotive */ - protected $motive; + protected Vector3 $blockIn; + protected int $facing; + protected PaintingMotive $motive; public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, ?CompoundTag $nbt = null){ $this->motive = $motive; diff --git a/src/entity/object/PaintingMotive.php b/src/entity/object/PaintingMotive.php index 28b52efe3..a2c6f221a 100644 --- a/src/entity/object/PaintingMotive.php +++ b/src/entity/object/PaintingMotive.php @@ -84,18 +84,11 @@ class PaintingMotive{ return self::$motives; } - /** @var string */ - protected $name; - /** @var int */ - protected $width; - /** @var int */ - protected $height; - - public function __construct(int $width, int $height, string $name){ - $this->name = $name; - $this->width = $width; - $this->height = $height; - } + public function __construct( + protected int $width, + protected int $height, + protected string $name + ){} public function getName() : string{ return $this->name; diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index 06dbf4e16..97f68e8de 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -41,9 +41,7 @@ class PrimedTNT extends Entity implements Explosive{ public static function getNetworkTypeId() : string{ return EntityIds::TNT; } - /** @var int */ - protected $fuse; - + protected int $fuse; protected bool $worksUnderwater = false; protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.98, 0.98); } diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index 73ee9599c..023ea5584 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -52,20 +52,11 @@ class Arrow extends Projectile{ private const TAG_PICKUP = "pickup"; //TAG_Byte public const TAG_CRIT = "crit"; //TAG_Byte - /** @var float */ - protected $damage = 2.0; - - /** @var int */ - protected $pickupMode = self::PICKUP_ANY; - - /** @var float */ - protected $punchKnockback = 0.0; - - /** @var int */ - protected $collideTicks = 0; - - /** @var bool */ - protected $critical = false; + protected float $damage = 2.0; + protected int $pickupMode = self::PICKUP_ANY; + protected float $punchKnockback = 0.0; + protected int $collideTicks = 0; + protected bool $critical = false; public function __construct(Location $location, ?Entity $shootingEntity, bool $critical, ?CompoundTag $nbt = null){ parent::__construct($location, $shootingEntity, $nbt); diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 1f652bda4..40e7cb45d 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -51,11 +51,8 @@ use const PHP_INT_MAX; abstract class Projectile extends Entity{ - /** @var float */ - protected $damage = 0.0; - - /** @var Block|null */ - protected $blockHit; + protected float $damage = 0.0; + protected ?Block $blockHit = null; public function __construct(Location $location, ?Entity $shootingEntity, ?CompoundTag $nbt = null){ parent::__construct($location, $nbt); diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index d35360f54..555a8d755 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -52,8 +52,7 @@ class SplashPotion extends Throwable{ public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; } - /** @var bool */ - protected $linger = false; + protected bool $linger = false; protected PotionType $potionType; public function __construct(Location $location, ?Entity $shootingEntity, PotionType $potionType, ?CompoundTag $nbt = null){ diff --git a/src/player/Player.php b/src/player/Player.php index e5d87793b..a120231e1 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -241,8 +241,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ protected ?float $lastMovementProcess = null; protected int $inAirTicks = 0; - /** @var float */ - protected $stepHeight = 0.6; + + protected float $stepHeight = 0.6; protected ?Vector3 $sleeping = null; private ?Position $spawnPosition = null; @@ -2217,16 +2217,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->getWorld()->dropItem($this->location, $item); } - if($this->inventory !== null){ - $this->inventory->setHeldItemIndex(0); - $this->inventory->clearAll(); - } - if($this->armorInventory !== null){ - $this->armorInventory->clearAll(); - } - if($this->offHandInventory !== null){ - $this->offHandInventory->clearAll(); - } + $this->inventory->setHeldItemIndex(0); + $this->inventory->clearAll(); + $this->armorInventory->clearAll(); + $this->offHandInventory->clearAll(); } if(!$ev->getKeepXp()){