entityBaseTick() public method

public entityBaseTick ( $tickDiff = 1 )
Example #1
0
 public function entityBaseTick($tickDiff = 1)
 {
     Timings::$timerEntityBaseTick->startTiming();
     if (!$this->isCreated()) {
         return false;
     }
     $hasUpdate = Entity::entityBaseTick($tickDiff);
     if ($this->attackTime > 0) {
         $this->attackTime -= $tickDiff;
     }
     if ($this->isInsideOfSolid()) {
         $hasUpdate = true;
         $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
         $this->attack($ev->getFinalDamage(), $ev);
     }
     if ($this instanceof Enderman) {
         if ($this->level->getBlock(new Vector3(Math::floorFloat($this->x), (int) $this->y, Math::floorFloat($this->z))) instanceof Water) {
             $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
             $this->attack($ev->getFinalDamage(), $ev);
             $this->move(mt_rand(-20, 20), mt_rand(-20, 20), mt_rand(-20, 20));
         }
     } else {
         if (!$this->hasEffect(Effect::WATER_BREATHING) && $this->isInsideOfWater()) {
             $hasUpdate = true;
             $airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
             if ($airTicks <= -20) {
                 $airTicks = 0;
                 $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
                 $this->attack($ev->getFinalDamage(), $ev);
             }
             $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
         } else {
             $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
         }
     }
     Timings::$timerEntityBaseTick->stopTiming();
     return $hasUpdate;
 }
Example #2
0
 public function entityBaseTick($tickDiff = 1)
 {
     Timings::$timerLivingEntityBaseTick->startTiming();
     $hasUpdate = parent::entityBaseTick($tickDiff);
     if ($this->isAlive()) {
         if ($this->isInsideOfSolid()) {
             $hasUpdate = true;
             $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
             $this->attack($ev->getFinalDamage(), $ev);
         }
         if (!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()) {
             if ($this instanceof WaterAnimal) {
                 $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
             } else {
                 $hasUpdate = true;
                 $airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
                 if ($airTicks <= -20) {
                     $airTicks = 0;
                     $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
                     $this->attack($ev->getFinalDamage(), $ev);
                 }
                 $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
             }
         } else {
             if ($this instanceof WaterAnimal) {
                 $hasUpdate = true;
                 $airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
                 if ($airTicks <= -20) {
                     $airTicks = 0;
                     $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
                     $this->attack($ev->getFinalDamage(), $ev);
                 }
                 $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
             } else {
                 $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
             }
         }
     }
     if ($this->attackTime > 0) {
         $this->attackTime -= $tickDiff;
     }
     Timings::$timerLivingEntityBaseTick->stopTiming();
     return $hasUpdate;
 }
Example #3
0
 public function entityBaseTick($tickDiff = 1)
 {
     Timings::$timerEntityBaseTick->startTiming();
     if ($this->dead === true) {
         ++$this->deadTicks;
         if ($this->deadTicks >= 10) {
             $this->despawnFromAll();
             if (!$this instanceof Player) {
                 $this->close();
             }
         }
         Timings::$timerEntityBaseTick->stopTiming();
         return $this->deadTicks < 10;
     }
     parent::entityBaseTick($tickDiff);
     if ($this->dead !== true and $this->isInsideOfSolid()) {
         $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
         $this->attack($ev->getFinalDamage(), $ev);
     }
     if ($this->dead !== true and $this->isInsideOfWater()) {
         $this->airTicks -= $tickDiff;
         if ($this->airTicks <= -20) {
             $this->airTicks = 0;
             $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
             $this->attack($ev->getFinalDamage(), $ev);
         }
     } else {
         $this->airTicks = 300;
     }
     if ($this->attackTime > 0) {
         $this->attackTime -= $tickDiff;
     }
     Timings::$timerEntityBaseTick->stopTiming();
 }
Example #4
0
 public function entityBaseTick()
 {
     Timings::$timerEntityBaseTick->startTiming();
     parent::entityBaseTick();
     if ($this->dead !== true and $this->isInsideOfSolid()) {
         $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1));
         if (!$ev->isCancelled()) {
             $this->attack($ev->getFinalDamage(), $ev);
         }
     }
     if ($this->dead !== true and $this->isInsideOfWater()) {
         --$this->airTicks;
         if ($this->airTicks <= -20) {
             $this->airTicks = 0;
             $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2));
             if (!$ev->isCancelled()) {
                 $this->attack($ev->getFinalDamage(), $ev);
             }
         }
         $this->extinguish();
     } else {
         $this->airTicks = 300;
     }
     if ($this->attackTime > 0) {
         --$this->attackTime;
     }
     Timings::$timerEntityBaseTick->stopTiming();
 }