Typehinted up entity API

Did you guys think ALPHA7 changes were done?!
Sone stuff still needs some work, most notably data-properties can't be typed yet because they are just mushed into a couple of methods.
This commit is contained in:
Dylan K. Taylor 2017-08-16 19:03:39 +01:00
parent ea414ea72d
commit 741394dab1
23 changed files with 197 additions and 149 deletions

View File

@ -35,7 +35,7 @@ interface IPlayer extends ServerOperator{
/**
* @return string
*/
public function getName();
public function getName() : string;
/**
* @return bool

View File

@ -55,7 +55,7 @@ class OfflinePlayer implements IPlayer, Metadatable{
return $this->getPlayer() !== null;
}
public function getName(){
public function getName() : string{
return $this->name;
}

View File

@ -487,7 +487,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return false;
}
@ -756,7 +756,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return $this->inAirTicks;
}
protected function switchLevel(Level $targetLevel){
protected function switchLevel(Level $targetLevel) : bool{
$oldLevel = $this->level;
if(parent::switchLevel($targetLevel)){
foreach($this->usedChunks as $index => $d){
@ -1398,7 +1398,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return [];
}
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){
if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox;
$bb->minY = $this->y - 0.01;
@ -1643,7 +1643,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if(!$this->loggedIn){
return false;
}
@ -3549,10 +3549,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/**
* Gets the username
*
* @return string
*/
public function getName(){
public function getName() : string{
return $this->username;
}

View File

@ -42,7 +42,7 @@ interface CommandSender extends Permissible{
/**
* @return string
*/
public function getName();
public function getName() : string;
/**
* Returns the line height of the command-sender's screen. Used for determining sizes for command output pagination

View File

@ -124,7 +124,7 @@ class ConsoleCommandSender implements CommandSender{
/**
* @return string
*/
public function getName(){
public function getName() : string{
return "CONSOLE";
}

View File

@ -44,7 +44,7 @@ class RemoteConsoleCommandSender extends ConsoleCommandSender{
return $this->messages;
}
public function getName(){
public function getName() : string{
return "Rcon";
}

View File

@ -25,5 +25,5 @@ namespace pocketmine\entity;
interface Ageable{
public function isBaby();
public function isBaby() : bool;
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\entity;
abstract class Animal extends Creature implements Ageable{
public function isBaby(){
public function isBaby() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY);
}
}

View File

@ -62,7 +62,7 @@ class Arrow extends Projectile{
}
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;
}

View File

@ -82,6 +82,10 @@ class Effect{
}
}
/**
* @param string $internalName
* @param Effect $effect
*/
public static function registerEffect(string $internalName, Effect $effect){
self::$effects[$effect->getId()] = $effect;
self::$effects[$internalName] = $effect;
@ -92,9 +96,9 @@ class Effect{
*
* @return Effect|null
*/
public static function getEffect($id){
public static function getEffect(int $id){
if(isset(self::$effects[$id])){
return clone self::$effects[(int) $id];
return clone self::$effects[$id];
}
return null;
}
@ -104,7 +108,7 @@ class Effect{
*
* @return Effect|null
*/
public static function getEffectByName($name){
public static function getEffectByName(string $name){
if(isset(self::$effects[$name])){
return clone self::$effects[$name];
}
@ -113,23 +117,23 @@ class Effect{
/** @var int */
protected $id;
/** @var string */
protected $name;
/** @var int */
protected $duration;
/** @var int */
protected $amplifier = 0;
/** @var int[] */
protected $color;
protected $show = true;
/** @var bool */
protected $visible = true;
/** @var bool */
protected $ambient = false;
/** @var bool */
protected $bad;
/** @var int */
protected $defaultDuration = 300 * 20;
/** @var bool */
protected $hasBubbles = true;
/**
@ -142,10 +146,10 @@ class Effect{
* @param int $defaultDuration Duration in ticks the effect will last for by default if applied without a duration.
* @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles)
*/
public function __construct($id, $name, $r, $g, $b, $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){
public function __construct(int $id, string $name, int $r, int $g, int $b, bool $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){
$this->id = $id;
$this->name = $name;
$this->bad = (bool) $isBad;
$this->bad = $isBad;
$this->setColor($r, $g, $b);
$this->defaultDuration = $defaultDuration;
$this->duration = $defaultDuration;
@ -156,7 +160,7 @@ class Effect{
* Returns the translation key used to translate this effect's name.
* @return string
*/
public function getName(){
public function getName() : string{
return $this->name;
}
@ -164,7 +168,7 @@ class Effect{
* Returns the effect ID as per Minecraft PE
* @return int
*/
public function getId(){
public function getId() : int{
return $this->id;
}
@ -186,7 +190,7 @@ class Effect{
* Returns the duration remaining of the effect in ticks.
* @return int
*/
public function getDuration(){
public function getDuration() : int{
return $this->duration;
}
@ -212,18 +216,19 @@ class Effect{
*
* @return bool
*/
public function isVisible(){
return $this->show;
public function isVisible() : bool{
return $this->visible;
}
/**
* Changes the visibility of the effect.
*
* @param bool $bool
*
* @return $this
*/
public function setVisible($bool){
$this->show = (bool) $bool;
public function setVisible(bool $bool){
$this->visible = $bool;
return $this;
}
@ -238,10 +243,9 @@ class Effect{
/**
* Returns the amplifier of this effect.
*
* @return int
*/
public function getAmplifier(){
public function getAmplifier() : int{
return $this->amplifier;
}
@ -259,18 +263,19 @@ class Effect{
* Returns whether the effect is ambient.
* @return bool
*/
public function isAmbient(){
public function isAmbient() : bool{
return $this->ambient;
}
/**
* Sets the ambiency of this effect.
*
* @param bool $ambient
*
* @return $this
*/
public function setAmbient($ambient = true){
$this->ambient = (bool) $ambient;
public function setAmbient(bool $ambient = true){
$this->ambient = $ambient;
return $this;
}
@ -280,7 +285,7 @@ class Effect{
*
* @return bool
*/
public function isBad(){
public function isBad() : bool{
return $this->bad;
}
@ -289,7 +294,7 @@ class Effect{
*
* @return bool
*/
public function canTick(){
public function canTick() : bool{
switch($this->id){
case Effect::POISON:
if(($interval = (25 >> $this->amplifier)) > 0){
@ -370,9 +375,9 @@ class Effect{
/**
* Returns an RGB color array of this effect's color.
* @return array
* @return int[]
*/
public function getColor(){
public function getColor() : array{
return [$this->color >> 16, ($this->color >> 8) & 0xff, $this->color & 0xff];
}
@ -382,8 +387,10 @@ class Effect{
* @param int $r
* @param int $g
* @param int $b
*
* @return int
*/
public function setColor($r, $g, $b){
public function setColor(int $r, int $g, int $b) {
$this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff);
}
@ -394,7 +401,7 @@ class Effect{
* @param bool $modify
* @param Effect|null $oldEffect
*/
public function add(Entity $entity, $modify = false, Effect $oldEffect = null){
public function add(Entity $entity, bool $modify = false, Effect $oldEffect = null){
$entity->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($entity, $this, $modify, $oldEffect));
if($ev->isCancelled()){
return;

View File

@ -222,6 +222,7 @@ abstract class Entity extends Location implements Metadatable{
*/
protected $hasSpawned = [];
/** @var int */
protected $id;
protected $dataProperties = [
@ -241,85 +242,121 @@ abstract class Entity extends Location implements Metadatable{
/** @var Chunk */
public $chunk;
/** @var EntityDamageEvent|null */
protected $lastDamageCause = null;
/** @var Block[] */
private $blocksAround = [];
/** @var float|null */
public $lastX = null;
/** @var float|null */
public $lastY = null;
/** @var float|null */
public $lastZ = null;
/** @var float */
public $motionX;
/** @var float */
public $motionY;
/** @var float */
public $motionZ;
/** @var Vector3 */
public $temporalVector;
/** @var float */
public $lastMotionX;
/** @var float */
public $lastMotionY;
/** @var float */
public $lastMotionZ;
/** @var float */
public $lastYaw;
/** @var float */
public $lastPitch;
/** @var AxisAlignedBB */
public $boundingBox;
/** @var bool */
public $onGround;
public $inBlock = false;
public $positionChanged;
public $motionChanged;
/** @var int */
public $deadTicks = 0;
/** @var int */
protected $age = 0;
public $height;
/** @var float */
public $eyeHeight = null;
/** @var float */
public $height;
/** @var float */
public $width;
/** @var float */
public $length;
/** @var float */
protected $baseOffset = 0.0;
/** @var int */
private $health = 20;
private $maxHealth = 20;
protected $ySize = 0;
protected $stepHeight = 0;
/** @var float */
protected $ySize = 0.0;
/** @var float */
protected $stepHeight = 0.0;
/** @var bool */
public $keepMovement = false;
/** @var float */
public $fallDistance = 0.0;
/** @var int */
public $ticksLived = 0;
/** @var int */
public $lastUpdate;
/** @var int */
public $maxFireTicks;
/** @var int */
public $fireTicks = 0;
/** @var CompoundTag */
public $namedtag;
/** @var bool */
public $canCollide = true;
/** @var bool */
protected $isStatic = false;
/** @var bool */
public $isCollided = false;
/** @var bool */
public $isCollidedHorizontally = false;
/** @var bool */
public $isCollidedVertically = false;
/** @var int */
public $noDamageTicks;
protected $justCreated;
/** @var bool */
protected $justCreated = true;
/** @var bool */
private $invulnerable;
/** @var AttributeMap */
protected $attributeMap;
/** @var float */
protected $gravity;
/** @var float */
protected $drag;
/** @var Server */
protected $server;
/** @var bool */
public $closed = false;
/** @var TimingsHandler */
protected $timings;
/** @var bool */
protected $isPlayer = false;
@ -335,7 +372,6 @@ abstract class Entity extends Location implements Metadatable{
}
$this->id = Entity::$entityCount++;
$this->justCreated = true;
$this->namedtag = $nbt;
$this->chunk = $level->getChunk($this->namedtag["Pos"][0] >> 4, $this->namedtag["Pos"][2] >> 4, true);
@ -372,7 +408,7 @@ abstract class Entity extends Location implements Metadatable{
if(!isset($this->namedtag->Fire)){
$this->namedtag->Fire = new ShortTag("Fire", 0);
}
$this->fireTicks = $this->namedtag["Fire"];
$this->fireTicks = (int) $this->namedtag["Fire"];
if(!isset($this->namedtag->Air)){
$this->namedtag->Air = new ShortTag("Air", 300);
@ -412,14 +448,14 @@ abstract class Entity extends Location implements Metadatable{
/**
* @return bool
*/
public function isNameTagVisible(){
public function isNameTagVisible() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG);
}
/**
* @return bool
*/
public function isNameTagAlwaysVisible(){
public function isNameTagAlwaysVisible() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG);
}
@ -434,14 +470,14 @@ abstract class Entity extends Location implements Metadatable{
/**
* @param bool $value
*/
public function setNameTagVisible($value = true){
public function setNameTagVisible(bool $value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value);
}
/**
* @param bool $value
*/
public function setNameTagAlwaysVisible($value = true){
public function setNameTagAlwaysVisible(bool $value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
}
@ -480,21 +516,21 @@ abstract class Entity extends Location implements Metadatable{
}
public function isSneaking(){
public function isSneaking() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING);
}
public function setSneaking($value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, (bool) $value);
public function setSneaking(bool $value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, $value);
}
public function isSprinting(){
public function isSprinting() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING);
}
public function setSprinting($value = true){
public function setSprinting(bool $value = true){
if($value !== $this->isSprinting()){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value);
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, $value);
$attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true);
}
@ -504,7 +540,7 @@ abstract class Entity extends Location implements Metadatable{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE);
}
public function setImmobile($value = true){
public function setImmobile(bool $value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value);
}
@ -544,7 +580,7 @@ abstract class Entity extends Location implements Metadatable{
/**
* Returns the entity ID of the owning entity, or null if the entity doesn't have an owner.
* @return int|string|null
* @return int|null
*/
public function getOwningEntityId(){
return $this->getDataProperty(self::DATA_OWNER_EID);
@ -580,7 +616,7 @@ abstract class Entity extends Location implements Metadatable{
/**
* Returns the entity ID of the entity's target, or null if it doesn't have a target.
* @return int|string|null
* @return int|null
*/
public function getTargetEntityId(){
return $this->getDataProperty(self::DATA_TARGET_EID);
@ -689,7 +725,7 @@ abstract class Entity extends Location implements Metadatable{
return null;
}
public static function registerEntity($className, $force = false){
public static function registerEntity($className, bool $force = false) : bool{
$class = new \ReflectionClass($className);
if(is_a($className, Entity::class, true) and !$class->isAbstract()){
if($className::NETWORK_ID !== -1){
@ -771,7 +807,7 @@ abstract class Entity extends Location implements Metadatable{
/**
* @return Player[]
*/
public function getViewers(){
public function getViewers() : array{
return $this->hasSpawned;
}
@ -884,7 +920,7 @@ abstract class Entity extends Location implements Metadatable{
return $this->health;
}
public function isAlive(){
public function isAlive() : bool{
return $this->health > 0;
}
@ -950,11 +986,11 @@ abstract class Entity extends Location implements Metadatable{
$this->maxHealth = (int) $amount;
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return !$this->justCreated and $entity !== $this;
}
protected function checkObstruction($x, $y, $z){
protected function checkObstruction(float $x, float $y, float $z) : bool{
if(count($this->level->getCollisionCubes($this, $this->getBoundingBox(), false)) === 0){
return false;
}
@ -1049,7 +1085,7 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
public function entityBaseTick($tickDiff = 1){
public function entityBaseTick(int $tickDiff = 1) : bool{
//TODO: check vehicles
$this->blocksAround = null;
@ -1156,7 +1192,7 @@ abstract class Entity extends Location implements Metadatable{
/**
* @return Vector3
*/
public function getDirectionVector(){
public function getDirectionVector() : Vector3{
$y = -sin(deg2rad($this->pitch));
$xz = cos(deg2rad($this->pitch));
$x = -$xz * sin(deg2rad($this->yaw));
@ -1165,11 +1201,11 @@ abstract class Entity extends Location implements Metadatable{
return $this->temporalVector->setComponents($x, $y, $z)->normalize();
}
public function getDirectionPlane(){
public function getDirectionPlane() : Vector2{
return (new Vector2(-cos(deg2rad($this->yaw) - M_PI_2), -sin(deg2rad($this->yaw) - M_PI_2)))->normalize();
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;
}
@ -1212,11 +1248,11 @@ abstract class Entity extends Location implements Metadatable{
$this->level->updateEntities[$this->id] = $this;
}
public function isOnFire(){
public function isOnFire() : bool{
return $this->fireTicks > 0;
}
public function setOnFire($seconds){
public function setOnFire(int $seconds){
$ticks = $seconds * 20;
if($ticks > $this->fireTicks){
$this->fireTicks = $ticks;
@ -1234,6 +1270,9 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
/**
* @return int|null
*/
public function getDirection(){
$rotation = ($this->yaw - 90) % 360;
if($rotation < 0){
@ -1252,9 +1291,7 @@ abstract class Entity extends Location implements Metadatable{
}
}
public function canTriggerWalking(){
public function canTriggerWalking() : bool{
return true;
}
@ -1267,7 +1304,7 @@ abstract class Entity extends Location implements Metadatable{
* @param bool $onGround
*/
protected function updateFallState(float $distanceThisTick, bool $onGround){
if($onGround === true){
if($onGround){
if($this->fallDistance > 0){
$this->fall($this->fallDistance);
$this->resetFallDistance();
@ -1290,7 +1327,7 @@ abstract class Entity extends Location implements Metadatable{
}
public function getEyeHeight(){
public function getEyeHeight() : float{
return $this->eyeHeight;
}
@ -1302,7 +1339,7 @@ abstract class Entity extends Location implements Metadatable{
}
protected function switchLevel(Level $targetLevel){
protected function switchLevel(Level $targetLevel) : bool{
if($this->closed){
return false;
}
@ -1327,15 +1364,15 @@ abstract class Entity extends Location implements Metadatable{
return true;
}
public function getPosition(){
return new Position($this->x, $this->y, $this->z, $this->level);
public function getPosition() : Position{
return $this->asPosition();
}
public function getLocation(){
return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->level);
public function getLocation() : Location{
return $this->asLocation();
}
public function isInsideOfWater(){
public function isInsideOfWater() : bool{
$block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
if($block instanceof Water){
@ -1346,7 +1383,7 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
public function isInsideOfSolid(){
public function isInsideOfSolid() : bool{
$block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$bb = $block->getBoundingBox();
@ -1357,7 +1394,7 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
public function fastMove($dx, $dy, $dz){
public function fastMove(float $dx, float $dy, float $dz) : bool{
if($dx == 0 and $dz == 0 and $dy == 0){
return true;
}
@ -1396,7 +1433,7 @@ abstract class Entity extends Location implements Metadatable{
return true;
}
public function move($dx, $dy, $dz){
public function move(float $dx, float $dy, float $dz) : bool{
if($dx == 0 and $dz == 0 and $dy == 0){
return true;
@ -1557,14 +1594,17 @@ abstract class Entity extends Location implements Metadatable{
}
}
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){
$this->isCollidedVertically = $movY != $dy;
$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
$this->onGround = ($movY != $dy and $movY < 0);
}
public function getBlocksAround(){
/**
* @return Block[]
*/
public function getBlocksAround() : array{
if($this->blocksAround === null){
$minX = Math::floorFloat($this->boundingBox->minX);
$minY = Math::floorFloat($this->boundingBox->minY);
@ -1607,7 +1647,7 @@ abstract class Entity extends Location implements Metadatable{
}
}
public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch){
public function setPositionAndRotation(Vector3 $pos, float $yaw, float $pitch) : bool{
if($this->setPosition($pos) === true){
$this->setRotation($yaw, $pitch);
@ -1617,7 +1657,7 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
public function setRotation($yaw, $pitch){
public function setRotation(float $yaw, float $pitch){
$this->yaw = $yaw;
$this->pitch = $pitch;
$this->scheduleUpdate();
@ -1681,7 +1721,7 @@ abstract class Entity extends Location implements Metadatable{
list($this->lastMotionX, $this->lastMotionY, $this->lastMotionZ) = [$this->motionX, $this->motionY, $this->motionZ];
}
public function getMotion(){
public function getMotion() : Vector3{
return new Vector3($this->motionX, $this->motionY, $this->motionZ);
}
@ -1704,7 +1744,7 @@ abstract class Entity extends Location implements Metadatable{
return true;
}
public function isOnGround(){
public function isOnGround() : bool{
return $this->onGround === true;
}
@ -1754,7 +1794,7 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
public function getId(){
public function getId() : int{
return $this->id;
}
@ -1813,7 +1853,7 @@ abstract class Entity extends Location implements Metadatable{
*
* @return bool
*/
public function setDataProperty($id, $type, $value, bool $send = true){
public function setDataProperty(int $id, int $type, $value, bool $send = true) : bool{
if($this->getDataProperty($id) !== $value){
$this->dataProperties[$id] = [$type, $value];
if($send){
@ -1831,7 +1871,7 @@ abstract class Entity extends Location implements Metadatable{
*
* @return mixed
*/
public function getDataProperty($id){
public function getDataProperty(int $id){
return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null;
}
@ -1840,32 +1880,32 @@ abstract class Entity extends Location implements Metadatable{
*
* @return int|null
*/
public function getDataPropertyType($id){
public function getDataPropertyType(int $id){
return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][0] : null;
}
/**
* @param int $propertyId
* @param int $id
* @param int $flagId
* @param bool $value
* @param int $type
* @param int $propertyType
*/
public function setDataFlag($propertyId, $id, $value = true, $type = self::DATA_TYPE_LONG){
if($this->getDataFlag($propertyId, $id) !== $value){
public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = self::DATA_TYPE_LONG){
if($this->getDataFlag($propertyId, $flagId) !== $value){
$flags = (int) $this->getDataProperty($propertyId);
$flags ^= 1 << $id;
$this->setDataProperty($propertyId, $type, $flags);
$flags ^= 1 << $flagId;
$this->setDataProperty($propertyId, $propertyType, $flags);
}
}
/**
* @param int $propertyId
* @param int $id
* @param int $flagId
*
* @return bool
*/
public function getDataFlag($propertyId, $id){
return (((int) $this->getDataProperty($propertyId)) & (1 << $id)) > 0;
public function getDataFlag(int $propertyId, int $flagId) : bool{
return (((int) $this->getDataProperty($propertyId)) & (1 << $flagId)) > 0;
}
public function __destruct(){

View File

@ -70,7 +70,7 @@ class FallingSand extends Entity{
$this->setDataProperty(self::DATA_VARIANT, self::DATA_TYPE_INT, $this->getBlock() | ($this->getDamage() << 8));
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return false;
}
@ -80,7 +80,7 @@ class FallingSand extends Entity{
}
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;

View File

@ -378,7 +378,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXPERIENCE));
}
public function entityBaseTick($tickDiff = 1){
public function entityBaseTick(int $tickDiff = 1) : bool{
$hasUpdate = parent::entityBaseTick($tickDiff);
$this->doFoodTick($tickDiff);
@ -427,7 +427,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
}
public function getName(){
public function getName() : string{
return $this->getNameTag();
}

View File

@ -98,7 +98,7 @@ class Item extends Entity{
}
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;
}
@ -181,53 +181,53 @@ class Item extends Entity{
/**
* @return ItemItem
*/
public function getItem(){
public function getItem() : ItemItem{
return $this->item;
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return false;
}
/**
* @return int
*/
public function getPickupDelay(){
public function getPickupDelay() : int{
return $this->pickupDelay;
}
/**
* @param int $delay
*/
public function setPickupDelay($delay){
public function setPickupDelay(int $delay){
$this->pickupDelay = $delay;
}
/**
* @return string
*/
public function getOwner(){
public function getOwner() : string{
return $this->owner;
}
/**
* @param string $owner
*/
public function setOwner($owner){
public function setOwner(string $owner){
$this->owner = $owner;
}
/**
* @return string
*/
public function getThrower(){
public function getThrower() : string{
return $this->thrower;
}
/**
* @param string $thrower
*/
public function setThrower($thrower){
public function setThrower(string $thrower){
$this->thrower = $thrower;
}

View File

@ -57,7 +57,7 @@ abstract class Living extends Entity implements Damageable{
/** @var Effect[] */
protected $effects = [];
abstract public function getName();
abstract public function getName() : string;
protected function initEntity(){
parent::initEntity();
@ -151,7 +151,7 @@ abstract class Living extends Entity implements Damageable{
}
public function hasLineOfSight(Entity $entity){
public function hasLineOfSight(Entity $entity) : bool{
//TODO: head height
return true;
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
@ -377,7 +377,7 @@ abstract class Living extends Entity implements Damageable{
$this->attackTime = 10; //0.5 seconds cooldown
}
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4){
$f = sqrt($x * $x + $z * $z);
if($f <= 0){
return;
@ -416,7 +416,7 @@ abstract class Living extends Entity implements Damageable{
}
}
public function entityBaseTick($tickDiff = 1){
public function entityBaseTick(int $tickDiff = 1) : bool{
Timings::$timerLivingEntityBaseTick->startTiming();
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BREATHING, !$this->isInsideOfWater());
@ -505,7 +505,7 @@ abstract class Living extends Entity implements Damageable{
*
* @return Block[]
*/
public function getLineOfSight($maxDistance, $maxLength = 0, array $transparent = []){
public function getLineOfSight(int $maxDistance, int $maxLength = 0, array $transparent = []) : array{
if($maxDistance > 120){
$maxDistance = 120;
}
@ -551,7 +551,7 @@ abstract class Living extends Entity implements Damageable{
*
* @return Block|null
*/
public function getTargetBlock($maxDistance, array $transparent = []){
public function getTargetBlock(int $maxDistance, array $transparent = []){
try{
$block = $this->getLineOfSight($maxDistance, 1, $transparent)[0];
if($block instanceof Block){

View File

@ -70,7 +70,7 @@ class PrimedTNT extends Entity implements Explosive{
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return false;
}
@ -79,7 +79,7 @@ class PrimedTNT extends Entity implements Explosive{
$this->namedtag->Fuse = new ByteTag("Fuse", $this->fuse);
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;

View File

@ -65,7 +65,7 @@ abstract class Projectile extends Entity{
}
}
public function canCollideWith(Entity $entity){
public function canCollideWith(Entity $entity) : bool{
return $entity instanceof Living and !$this->onGround;
}
@ -108,7 +108,7 @@ abstract class Projectile extends Entity{
$this->namedtag->Age = new ShortTag("Age", $this->age);
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;
}

View File

@ -42,7 +42,7 @@ class Snowball extends Projectile{
parent::__construct($level, $nbt, $shootingEntity);
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed){
return false;
}

View File

@ -49,7 +49,7 @@ class Squid extends WaterAnimal{
parent::initEntity();
}
public function getName(){
public function getName() : string{
return "Squid";
}
@ -73,12 +73,12 @@ class Squid extends WaterAnimal{
}
}
private function generateRandomDirection(){
private function generateRandomDirection() : Vector3{
return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000);
}
public function onUpdate($currentTick){
public function onUpdate(int $currentTick) : bool{
if($this->closed !== false){
return false;
}

View File

@ -41,7 +41,7 @@ class Villager extends Creature implements NPC, Ageable{
public $length = 0.6;
public $height = 1.8;
public function getName(){
public function getName() : string{
return "Villager";
}
@ -73,17 +73,17 @@ class Villager extends Creature implements NPC, Ageable{
/**
* Sets the villager profession
*
* @param $profession
* @param int $profession
*/
public function setProfession($profession){
public function setProfession(int $profession){
$this->namedtag->Profession = new IntTag("Profession", $profession);
}
public function getProfession(){
return $this->namedtag["Profession"];
public function getProfession() : int{
return (int) $this->namedtag["Profession"];
}
public function isBaby(){
public function isBaby() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY);
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\entity;
abstract class WaterAnimal extends Creature implements Ageable{
public function isBaby(){
public function isBaby() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY);
}
}

View File

@ -35,7 +35,7 @@ class Zombie extends Monster{
public $length = 0.6;
public $height = 1.8;
public function getName(){
public function getName() : string{
return "Zombie";
}

View File

@ -27,7 +27,9 @@ use pocketmine\math\Vector3;
class Location extends Position{
/** @var float */
public $yaw;
/** @var float */
public $pitch;
/**