mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Hinting up Entity API to PHP 7.2 standards
This commit is contained in:
@ -72,7 +72,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
|
||||
abstract public function getName() : string;
|
||||
|
||||
protected function initEntity(){
|
||||
protected function initEntity() : void{
|
||||
parent::initEntity();
|
||||
|
||||
$this->armorInventory = new ArmorInventory($this);
|
||||
@ -112,7 +112,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
}
|
||||
|
||||
protected function addAttributes(){
|
||||
protected function addAttributes() : void{
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH));
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::FOLLOW_RANGE));
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::KNOCKBACK_RESISTANCE));
|
||||
@ -121,7 +121,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION));
|
||||
}
|
||||
|
||||
public function setHealth(float $amount){
|
||||
public function setHealth(float $amount) : void{
|
||||
$wasAlive = $this->isAlive();
|
||||
parent::setHealth($amount);
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true);
|
||||
@ -134,7 +134,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
return (int) $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue();
|
||||
}
|
||||
|
||||
public function setMaxHealth(int $amount){
|
||||
public function setMaxHealth(int $amount) : void{
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount);
|
||||
}
|
||||
|
||||
@ -142,11 +142,11 @@ abstract class Living extends Entity implements Damageable{
|
||||
return $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue();
|
||||
}
|
||||
|
||||
public function setAbsorption(float $absorption){
|
||||
public function setAbsorption(float $absorption) : void{
|
||||
$this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption);
|
||||
}
|
||||
|
||||
public function saveNBT(){
|
||||
public function saveNBT() : void{
|
||||
parent::saveNBT();
|
||||
$this->namedtag->setFloat("Health", $this->getHealth(), true);
|
||||
|
||||
@ -186,7 +186,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
/**
|
||||
* Removes all effects from the mob.
|
||||
*/
|
||||
public function removeAllEffects(){
|
||||
public function removeAllEffects() : void{
|
||||
foreach($this->effects as $effect){
|
||||
$this->removeEffect($effect->getId());
|
||||
}
|
||||
@ -197,7 +197,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
*
|
||||
* @param int $effectId
|
||||
*/
|
||||
public function removeEffect(int $effectId){
|
||||
public function removeEffect(int $effectId) : void{
|
||||
if(isset($this->effects[$effectId])){
|
||||
$effect = $this->effects[$effectId];
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityEffectRemoveEvent($this, $effect));
|
||||
@ -221,7 +221,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
*
|
||||
* @return EffectInstance|null
|
||||
*/
|
||||
public function getEffect(int $effectId){
|
||||
public function getEffect(int $effectId) : ?EffectInstance{
|
||||
return $this->effects[$effectId] ?? null;
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
/**
|
||||
* Recalculates the mob's potion bubbles colour based on the active effects.
|
||||
*/
|
||||
protected function recalculateEffectColor(){
|
||||
protected function recalculateEffectColor() : void{
|
||||
/** @var Color[] $colors */
|
||||
$colors = [];
|
||||
$ambient = true;
|
||||
@ -323,7 +323,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
* Sends the mob's potion effects to the specified player.
|
||||
* @param Player $player
|
||||
*/
|
||||
public function sendPotionEffects(Player $player){
|
||||
public function sendPotionEffects(Player $player) : void{
|
||||
foreach($this->effects as $effect){
|
||||
$pk = new MobEffectPacket();
|
||||
$pk->entityRuntimeId = $this->id;
|
||||
@ -374,13 +374,13 @@ abstract class Living extends Entity implements Damageable{
|
||||
/**
|
||||
* Called when the entity jumps from the ground. This method adds upwards velocity to the entity.
|
||||
*/
|
||||
public function jump(){
|
||||
public function jump() : void{
|
||||
if($this->onGround){
|
||||
$this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground.
|
||||
}
|
||||
}
|
||||
|
||||
public function fall(float $fallDistance){
|
||||
public function fall(float $fallDistance) : void{
|
||||
$damage = ceil($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
|
||||
if($damage > 0){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
|
||||
@ -427,7 +427,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
return $this->armorInventory;
|
||||
}
|
||||
|
||||
public function setOnFire(int $seconds){
|
||||
public function setOnFire(int $seconds) : void{
|
||||
parent::setOnFire($seconds - (int) min($seconds, $seconds * $this->getHighestArmorEnchantmentLevel(Enchantment::FIRE_PROTECTION) * 0.15));
|
||||
}
|
||||
|
||||
@ -492,7 +492,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->armorInventory->setContents($armor);
|
||||
}
|
||||
|
||||
public function attack(EntityDamageEvent $source){
|
||||
public function attack(EntityDamageEvent $source) : void{
|
||||
if($this->attackTime > 0 or $this->noDamageTicks > 0){
|
||||
$lastCause = $this->getLastDamageCause();
|
||||
if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){
|
||||
@ -559,7 +559,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->broadcastEntityEvent(EntityEventPacket::HURT_ANIMATION);
|
||||
}
|
||||
|
||||
public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4){
|
||||
public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4) : void{
|
||||
$f = sqrt($x * $x + $z * $z);
|
||||
if($f <= 0){
|
||||
return;
|
||||
@ -583,12 +583,12 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->setMotion($motion);
|
||||
}
|
||||
|
||||
public function kill(){
|
||||
public function kill() : void{
|
||||
parent::kill();
|
||||
$this->onDeath();
|
||||
}
|
||||
|
||||
protected function onDeath(){
|
||||
protected function onDeath() : void{
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
|
||||
foreach($ev->getDrops() as $item){
|
||||
$this->getLevel()->dropItem($this, $item);
|
||||
@ -649,7 +649,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
protected function doEffectsTick(int $tickDiff = 1){
|
||||
protected function doEffectsTick(int $tickDiff = 1) : void{
|
||||
foreach($this->effects as $instance){
|
||||
$type = $instance->getType();
|
||||
if($type->canTick($instance)){
|
||||
@ -666,7 +666,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
* Ticks the entity's air supply when it cannot breathe.
|
||||
* @param int $tickDiff
|
||||
*/
|
||||
protected function doAirSupplyTick(int $tickDiff){
|
||||
protected function doAirSupplyTick(int $tickDiff) : void{
|
||||
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
|
||||
lcg_value() <= (1 / ($respirationLevel + 1))
|
||||
){
|
||||
@ -703,7 +703,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
*
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setBreathing(bool $value = true){
|
||||
public function setBreathing(bool $value = true) : void{
|
||||
$this->setGenericFlag(self::DATA_FLAG_BREATHING, $value);
|
||||
}
|
||||
|
||||
@ -721,7 +721,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
* Sets the number of air ticks left in the entity's air supply.
|
||||
* @param int $ticks
|
||||
*/
|
||||
public function setAirSupplyTicks(int $ticks){
|
||||
public function setAirSupplyTicks(int $ticks) : void{
|
||||
$this->propertyManager->setShort(self::DATA_AIR, $ticks);
|
||||
}
|
||||
|
||||
@ -737,7 +737,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
* Sets the maximum amount of air ticks the air supply can hold.
|
||||
* @param int $ticks
|
||||
*/
|
||||
public function setMaxAirSupplyTicks(int $ticks){
|
||||
public function setMaxAirSupplyTicks(int $ticks) : void{
|
||||
$this->propertyManager->setShort(self::DATA_MAX_AIR, $ticks);
|
||||
}
|
||||
|
||||
@ -745,7 +745,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
* Called when the entity's air supply ticks reaches -20 or lower. The entity will usually take damage at this point
|
||||
* and then the supply is reset to 0, so this method will be called roughly every second.
|
||||
*/
|
||||
public function onAirExpired(){
|
||||
public function onAirExpired() : void{
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
|
||||
$this->attack($ev);
|
||||
}
|
||||
@ -815,7 +815,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
*
|
||||
* @return Block|null
|
||||
*/
|
||||
public function getTargetBlock(int $maxDistance, array $transparent = []){
|
||||
public function getTargetBlock(int $maxDistance, array $transparent = []) : ?Block{
|
||||
$line = $this->getLineOfSight($maxDistance, 1, $transparent);
|
||||
if(!empty($line)){
|
||||
return array_shift($line);
|
||||
@ -849,7 +849,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->armorInventory->sendContents($player);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
public function close() : void{
|
||||
if(!$this->closed){
|
||||
if($this->armorInventory !== null){
|
||||
$this->armorInventory->removeAllViewers(true);
|
||||
|
Reference in New Issue
Block a user