pocketmine\entity\Entity::entityBaseTick PHP Method

entityBaseTick() public method

public entityBaseTick ( $tickDiff = 1 )
    public function entityBaseTick($tickDiff = 1)
    {
        Timings::$timerEntityBaseTick->startTiming();
        //TODO: check vehicles
        $this->blocksAround = null;
        $this->justCreated = false;
        if (!$this->isAlive()) {
            $this->removeAllEffects();
            $this->despawnFromAll();
            if (!$this->isPlayer) {
                $this->close();
            }
            Timings::$timerEntityBaseTick->stopTiming();
            return false;
        }
        if (count($this->effects) > 0) {
            foreach ($this->effects as $effect) {
                if ($effect->canTick()) {
                    $effect->applyEffect($this);
                }
                $effect->setDuration($effect->getDuration() - $tickDiff);
                if ($effect->getDuration() <= 0) {
                    $this->removeEffect($effect->getId());
                }
            }
        }
        $hasUpdate = false;
        $this->checkBlockCollision();
        if ($this->y <= -16 and $this->isAlive()) {
            $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
            $this->attack($ev->getFinalDamage(), $ev);
            $hasUpdate = true;
        }
        if ($this->fireTicks > 0) {
            if ($this->fireProof) {
                $this->fireTicks -= 4 * $tickDiff;
                if ($this->fireTicks < 0) {
                    $this->fireTicks = 0;
                }
            } else {
                if (!$this->hasEffect(Effect::FIRE_RESISTANCE) and ($this->fireTicks % 20 === 0 or $tickDiff > 20)) {
                    $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
                    $this->attack($ev->getFinalDamage(), $ev);
                }
                $this->fireTicks -= $tickDiff;
            }
            if ($this->fireTicks <= 0 && $this->fireTicks > -10) {
                $this->extinguish();
            } else {
                $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, true);
                $hasUpdate = true;
            }
        }
        if ($this->noDamageTicks > 0) {
            $this->noDamageTicks -= $tickDiff;
            if ($this->noDamageTicks < 0) {
                $this->noDamageTicks = 0;
            }
        }
        $this->age += $tickDiff;
        $this->ticksLived += $tickDiff;
        Timings::$timerEntityBaseTick->stopTiming();
        return $hasUpdate;
    }

Usage Example

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;
 }
All Usage Examples Of pocketmine\entity\Entity::entityBaseTick