pocketmine\entity\Living::entityBaseTick PHP Метод

entityBaseTick() публичный Метод

public entityBaseTick ( $tickDiff = 1, $EnchantL )
    public function entityBaseTick($tickDiff = 1, $EnchantL = 0)
    {
        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, 1200);
                } else {
                    $hasUpdate = true;
                    $airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff * (4 - $EnchantL);
                    if ($airTicks <= -80) {
                        $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 * (4 - $EnchantL);
                    if ($airTicks <= -80) {
                        $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, 1200);
                }
            }
        }
        if ($this->attackTime > 0) {
            $this->attackTime -= $tickDiff;
        }
        Timings::$timerLivingEntityBaseTick->stopTiming();
        return $hasUpdate;
    }

Usage Example

Пример #1
0
 public function onUpdate($tick)
 {
     if (!$this instanceof Human) {
         if ($this->attackingTick > 0) {
             $this->attackingTick--;
         }
         if (!$this->isAlive() and $this->hasSpawned) {
             ++$this->deadTicks;
             if ($this->deadTicks >= 20) {
                 $this->despawnFromAll();
             }
             return true;
         }
         if ($this->isAlive()) {
             $this->motionY -= $this->gravity;
             $this->move($this->motionX, $this->motionY, $this->motionZ);
             $friction = 1 - $this->drag;
             if ($this->onGround and (abs($this->motionX) > 1.0E-5 or abs($this->motionZ) > 1.0E-5)) {
                 $friction = $this->getLevel()->getBlock($this->temporalVector->setComponents((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z) - 1))->getFrictionFactor() * $friction;
             }
             $this->motionX *= $friction;
             $this->motionY *= 1 - $this->drag;
             $this->motionZ *= $friction;
             if ($this->onGround) {
                 $this->motionY *= -0.5;
             }
             $this->updateMovement();
         }
     }
     parent::entityBaseTick();
     return parent::onUpdate($tick);
 }