pocketmine\entity\FallingSand::onUpdate PHP Method

onUpdate() public method

public onUpdate ( $currentTick )
    public function onUpdate($currentTick)
    {
        if ($this->closed) {
            return false;
        }
        $this->timings->startTiming();
        $tickDiff = $currentTick - $this->lastUpdate;
        if ($tickDiff <= 0 and !$this->justCreated) {
            return true;
        }
        $this->lastUpdate = $currentTick;
        $height = $this->fallDistance;
        $hasUpdate = $this->entityBaseTick($tickDiff);
        if ($this->isAlive()) {
            $pos = (new Vector3($this->x - 0.5, $this->y, $this->z - 0.5))->round();
            if ($this->ticksLived === 1) {
                $block = $this->level->getBlock($pos);
                if ($block->getId() !== $this->blockId) {
                    return true;
                }
                $this->level->setBlock($pos, Block::get(0), true);
            }
            $this->motionY -= $this->gravity;
            $this->move($this->motionX, $this->motionY, $this->motionZ);
            $friction = 1 - $this->drag;
            $this->motionX *= $friction;
            $this->motionY *= 1 - $this->drag;
            $this->motionZ *= $friction;
            $pos = (new Vector3($this->x - 0.5, $this->y, $this->z - 0.5))->round();
            if ($this->onGround) {
                $this->kill();
                $block = $this->level->getBlock($pos);
                if ($block->getId() > 0 and !$block->isSolid() and !$block instanceof Liquid) {
                    $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1));
                } else {
                    if ($block instanceof SnowLayer) {
                        $oldDamage = $block->getDamage();
                        $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage() + $oldDamage)));
                    } else {
                        $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
                    }
                    if (!$ev->isCancelled()) {
                        $this->getLevel()->setBlock($pos, $ev->getTo(), true);
                        if ($ev->getTo() instanceof Anvil) {
                            $sound = new AnvilFallSound($this);
                            $this->getLevel()->addSound($sound);
                            foreach ($this->level->getNearbyEntities($this->boundingBox->grow(0.1, 0.1, 0.1), $this) as $entity) {
                                $entity->scheduleUpdate();
                                if (!$entity->isAlive()) {
                                    continue;
                                }
                                if ($entity instanceof Living) {
                                    $damage = ($height - 1) * 2;
                                    if ($damage > 40) {
                                        $damage = 40;
                                    }
                                    $ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageByEntityEvent::CAUSE_FALL, $damage, 0.1);
                                    $entity->attack($damage, $ev);
                                }
                            }
                        }
                    }
                }
                $hasUpdate = true;
            }
            $this->updateMovement();
        }
        return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
    }