protected function checkNearEntities($tickDiff) { foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) { $entity->scheduleUpdate(); if (!$entity->isAlive()) { continue; } if ($entity instanceof Arrow and $entity->hadCollision) { $item = Item::get(Item::ARROW, 0, 1); if ($this->isSurvival() and !$this->inventory->canAddItem($item)) { continue; } $this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity)); if ($ev->isCancelled()) { continue; } $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $pk = new TakeItemEntityPacket(); $pk->eid = 0; $pk->target = $entity->getId(); $this->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $this->inventory->addItem(clone $item); $entity->kill(); } elseif ($entity instanceof DroppedItem) { if ($entity->getPickupDelay() <= 0) { $item = $entity->getItem(); if ($item instanceof Item) { if ($this->isSurvival() and !$this->inventory->canAddItem($item)) { continue; } $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity)); if ($ev->isCancelled()) { continue; } switch ($item->getId()) { case Item::WOOD: $this->awardAchievement("mineWood"); break; case Item::DIAMOND: $this->awardAchievement("diamond"); break; } $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $pk = new TakeItemEntityPacket(); $pk->eid = 0; $pk->target = $entity->getId(); $this->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $this->inventory->addItem(clone $item); $entity->kill(); } } } } }
public function onUpdate($currentTick) { if (!$this->loggedIn) { return \false; } if ($this->dead === \true and $this->spawned) { ++$this->deadTicks; if ($this->deadTicks >= 10) { $this->despawnFromAll(); } return $this->deadTicks < 10; } $this->timings->startTiming(); if ($this->spawned) { $this->processMovement($currentTick); $this->entityBaseTick(1); if ($this->onGround) { $this->inAirTicks = 0; } else { if ($this->inAirTicks > 20 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()) { $expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * \exp(-$this->drag * ($this->inAirTicks - 2)); $diff = ($this->speed->y - $expectedVelocity) ** 2; if ($diff > 0.6 and $expectedVelocity < $this->speed->y) { $this->kick("Disable fly mods."); } return \false; } else { ++$this->inAirTicks; } } foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) { if ($currentTick - $entity->lastUpdate > 1) { $entity->scheduleUpdate(); } if ($entity instanceof Arrow and $entity->hadCollision) { if ($entity->dead !== \true) { $item = Item::get(Item::ARROW, 0, 1); if ($this->isSurvival() and !$this->inventory->canAddItem($item)) { continue; } $this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity)); if ($ev->isCancelled()) { continue; } $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $this->inventory->addItem(clone $item); $entity->kill(); } } elseif ($entity instanceof DroppedItem) { if ($entity->dead !== \true and $entity->getPickupDelay() <= 0) { $item = $entity->getItem(); if ($item instanceof Item) { if ($this->isSurvival() and !$this->inventory->canAddItem($item)) { continue; } $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity)); if ($ev->isCancelled()) { continue; } switch ($item->getId()) { case Item::WOOD: $this->awardAchievement("mineWood"); break; case Item::DIAMOND: $this->awardAchievement("diamond"); break; } $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $this->inventory->addItem(clone $item); $entity->kill(); } } } } } if ($this->nextChunkOrderRun-- <= 0 or $this->chunk === \null) { $this->orderChunks(); } if (\count($this->loadQueue) > 0 or !$this->spawned) { $this->sendNextChunk(); } if (\count($this->moveToSend) > 0) { $pk = new MoveEntityPacket(); $pk->entities = $this->moveToSend; $this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT)); $this->moveToSend = []; } if (\count($this->motionToSend) > 0) { $pk = new SetEntityMotionPacket(); $pk->entities = $this->motionToSend; $this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT)); $this->motionToSend = []; } if (\count($this->batchedPackets) > 0) { foreach ($this->batchedPackets as $channel => $list) { $this->server->batchPackets([$this], $list, \false, $channel); } $this->batchedPackets = []; } $this->lastUpdate = $currentTick; $this->timings->stopTiming(); return \true; }