Example #1
0
 protected function processMovement($tickDiff)
 {
     if (!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null) {
         return;
         $this->setMoving(false);
     }
     $newPos = $this->newPosition;
     $distanceSquared = $newPos->distanceSquared($this);
     $revert = false;
     if ($distanceSquared / $tickDiff ** 2 > 200) {
         $revert = true;
     } else {
         if ($this->chunk === null or !$this->chunk->isGenerated()) {
             $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false);
             if ($chunk === null or !$chunk->isGenerated()) {
                 $revert = true;
                 $this->nextChunkOrderRun = 0;
             } else {
                 if ($this->chunk !== null) {
                     $this->chunk->removeEntity($this);
                 }
                 $this->chunk = $chunk;
             }
         }
     }
     if (!$revert and $distanceSquared != 0) {
         $dx = $newPos->x - $this->x;
         $dy = $newPos->y - $this->y;
         $dz = $newPos->z - $this->z;
         $this->move($dx, $dy, $dz);
         $diffX = $this->x - $newPos->x;
         $diffY = $this->y - $newPos->y;
         $diffZ = $this->z - $newPos->z;
         $yS = 0.5 + $this->ySize;
         if ($diffY >= -$yS or $diffY <= $yS) {
             $diffY = 0;
         }
         $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / $tickDiff ** 2;
         /*if($this->isSurvival()){
         				if(!$revert and !$this->isSleeping()){
         					if($diff > 0.0625){
         						$revert = true;
         						$this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()]));
         					}
         				}
         			}
         
         			if($diff > 0){
         				$this->x = $newPos->x;
         				$this->y = $newPos->y;
         				$this->z = $newPos->z;
         				$radius = $this->width / 2;
         				$this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius);
         			}*/
     }
     $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
     $to = $this->getLocation();
     $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2);
     $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
     if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) {
         $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null);
         $this->lastX = $to->x;
         $this->lastY = $to->y;
         $this->lastZ = $to->z;
         $this->lastYaw = $to->yaw;
         $this->lastPitch = $to->pitch;
         if (!$isFirst) {
             $ev = new PlayerMoveEvent($this, $from, $to);
             $this->setMoving(true);
             $this->server->getPluginManager()->callEvent($ev);
             if (!($revert = $ev->isCancelled())) {
                 //Yes, this is intended
                 //$teleported = false;
                 if ($this->server->netherEnabled) {
                     if ($this->isInsideOfPortal()) {
                         if ($this->portalTime == 0) {
                             $this->portalTime = $this->server->getTick();
                         }
                     } else {
                         $this->portalTime = 0;
                     }
                 }
                 //if($this->server->redstoneEnabled) $this->getLevel()->updateAround($ev->getTo()->round());
                 //	if(!$teleported){
                 if ($to->distanceSquared($ev->getTo()) > 0.2) {
                     //If plugins modify the destination
                     $this->teleport($ev->getTo());
                 } else {
                     $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
                 }
                 if ($this->fishingHook instanceof FishingHook) {
                     if ($this->distance($this->fishingHook) > 20 or $this->inventory->getItemInHand()->getId() !== Item::FISHING_ROD) {
                         $this->fishingHook->close();
                         $this->fishingHook = null;
                     }
                 }
                 //	}
                 /*if($this->server->expEnabled){
                 			/** @var \pocketmine\entity\ExperienceOrb $e *
                 			foreach($this->level->getNearbyExperienceOrb(new AxisAlignedBB($this->x - 1, $this->y - 1, $this->z - 1, $this->x + 1, $this->y + 2, $this->z + 1)) as $e){
                 				if($e->getExperience() > 0){
                 					$e->close();
                 					$this->addExperience($e->getExperience());
                 				}
                 			}
                 		}*/
             }
         }
         if (!$this->isSpectator()) {
             $this->checkNearEntities($tickDiff);
         }
         $this->speed = $from->subtract($to);
     } elseif ($distanceSquared == 0) {
         $this->speed = new Vector3(0, 0, 0);
         $this->setMoving(false);
     }
     if ($revert) {
         $this->lastX = $from->x;
         $this->lastY = $from->y;
         $this->lastZ = $from->z;
         $this->lastYaw = $from->yaw;
         $this->lastPitch = $from->pitch;
         $this->sendPosition($from, $from->yaw, $from->pitch, 1);
         $this->forceMovement = new Vector3($from->x, $from->y, $from->z);
     } else {
         $this->forceMovement = null;
         if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) {
             $this->nextChunkOrderRun = 20;
         }
     }
     $this->newPosition = null;
 }
Example #2
0
 protected function processMovement($tickDiff)
 {
     if (!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null) {
         return;
     }
     $newPos = $this->newPosition;
     $distanceSquared = $newPos->distanceSquared($this);
     $revert = false;
     if ($distanceSquared / $tickDiff ** 2 > 100) {
         $revert = true;
     } else {
         if ($this->chunk === null or !$this->chunk->isGenerated()) {
             $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false);
             if ($chunk === null or !$chunk->isGenerated()) {
                 $revert = true;
                 $this->nextChunkOrderRun = 0;
             } else {
                 if ($this->chunk !== null) {
                     $this->chunk->removeEntity($this);
                 }
                 $this->chunk = $chunk;
             }
         }
     }
     if (!$revert and $distanceSquared != 0) {
         $dx = $newPos->x - $this->x;
         $dy = $newPos->y - $this->y;
         $dz = $newPos->z - $this->z;
         $this->move($dx, $dy, $dz);
         $diffX = $this->x - $newPos->x;
         $diffY = $this->y - $newPos->y;
         $diffZ = $this->z - $newPos->z;
         $yS = 0.5 + $this->ySize;
         if ($diffY >= -$yS or $diffY <= $yS) {
             $diffY = 0;
         }
         $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / $tickDiff ** 2;
         if ($this->isSurvival()) {
             if (!$revert and !$this->isSleeping()) {
                 if ($diff > 0.0625) {
                     $revert = true;
                     $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()]));
                 }
             }
         }
         if ($diff > 0) {
             $this->x = $newPos->x;
             $this->y = $newPos->y;
             $this->z = $newPos->z;
             $radius = $this->width / 2;
             $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius);
         }
     }
     $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
     $to = $this->getLocation();
     $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2);
     $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
     if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) {
         $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null);
         $this->lastX = $to->x;
         $this->lastY = $to->y;
         $this->lastZ = $to->z;
         $this->lastYaw = $to->yaw;
         $this->lastPitch = $to->pitch;
         if (!$isFirst) {
             $ev = new PlayerMoveEvent($this, $from, $to);
             $this->server->getPluginManager()->callEvent($ev);
             if (!($revert = $ev->isCancelled())) {
                 //Yes, this is intended
                 if ($to->distanceSquared($ev->getTo()) > 0.01) {
                     //If plugins modify the destination
                     $this->teleport($ev->getTo());
                 } else {
                     $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
                 }
             }
         }
         if (!$this->isSpectator()) {
             $this->checkNearEntities($tickDiff);
         }
         $this->speed = $from->subtract($to);
     } elseif ($distanceSquared == 0) {
         $this->speed = new Vector3(0, 0, 0);
     }
     if ($revert) {
         $this->lastX = $from->x;
         $this->lastY = $from->y;
         $this->lastZ = $from->z;
         $this->lastYaw = $from->yaw;
         $this->lastPitch = $from->pitch;
         $this->sendPosition($from, $from->yaw, $from->pitch, 1);
         $this->forceMovement = new Vector3($from->x, $from->y, $from->z);
     } else {
         $this->forceMovement = null;
         if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) {
             $this->nextChunkOrderRun = 20;
         }
     }
     $this->newPosition = null;
 }
Example #3
0
 protected function processMovement($currentTick)
 {
     if ($this->dead or !$this->spawned or !$this->newPosition instanceof Vector3) {
         $diff = $currentTick - $this->lastSpeedTick;
         if ($diff >= 10) {
             $this->speed = new Vector3(0, 0, 0);
         } elseif ($diff > 5 and $this->speedTicks < 20) {
             ++$this->speedTicks;
         }
         return;
     }
     $distanceSquared = $this->newPosition->distanceSquared($this);
     $revert = false;
     if ($distanceSquared > 100) {
         $revert = true;
     } else {
         if ($this->chunk === null or !$this->chunk->isGenerated()) {
             $chunk = $this->level->getChunk($this->newPosition->x >> 4, $this->newPosition->z >> 4);
             if (!$chunk instanceof FullChunk or !$chunk->isGenerated()) {
                 $revert = true;
                 $this->nextChunkOrderRun = 0;
             } else {
                 if ($this->chunk instanceof FullChunk) {
                     $this->chunk->removeEntity($this);
                 }
                 $this->chunk = $chunk;
             }
         }
     }
     if (!$revert and $distanceSquared != 0) {
         $dx = $this->newPosition->x - $this->x;
         $dy = $this->newPosition->y - $this->y;
         $dz = $this->newPosition->z - $this->z;
         $this->fastMove($dx, $dy, $dz);
         $diffX = $this->x - $this->newPosition->x;
         $diffY = $this->y - $this->newPosition->y;
         $diffZ = $this->z - $this->newPosition->z;
         $yS = 0.5 + $this->ySize;
         if ($diffY > -0.5 or $diffY < 0.5) {
             $diffY = 0;
         }
         $diff = $diffX ** 2 + $diffY ** 2 + $diffZ ** 2;
         if ($this->isSurvival()) {
             if (!$revert and !$this->isSleeping()) {
                 if ($diff > 0.0625 and $this->checkMovement) {
                     $revert = true;
                     $this->server->getLogger()->warning($this->getName() . " moved wrongly!");
                 } elseif ($diff > 0 or !$this->checkMovement) {
                     $this->x = $this->newPosition->x;
                     $this->y = $this->newPosition->y;
                     $this->z = $this->newPosition->z;
                     $radius = $this->width / 2;
                     $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius);
                 }
             }
         } elseif ($diff > 0) {
             $this->x = $this->newPosition->x;
             $this->y = $this->newPosition->y;
             $this->z = $this->newPosition->z;
             $radius = $this->width / 2;
             $this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius);
         }
     }
     $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
     $to = $this->getLocation();
     $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2);
     $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
     if (!$revert and ($delta > 1 / 16 or $deltaAngle > 10)) {
         $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null);
         $this->lastX = $to->x;
         $this->lastY = $to->y;
         $this->lastZ = $to->z;
         $this->lastYaw = $to->yaw;
         $this->lastPitch = $to->pitch;
         if (!$isFirst) {
             $ev = new PlayerMoveEvent($this, $from, $to);
             $this->server->getPluginManager()->callEvent($ev);
             if (!($revert = $ev->isCancelled())) {
                 //Yes, this is intended
                 if ($to->distanceSquared($ev->getTo()) > 0.01) {
                     //If plugins modify the destination
                     $this->teleport($ev->getTo());
                 } else {
                     foreach ($this->hasSpawned as $player) {
                         $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
                     }
                 }
             }
         }
         $ticks = min(20, $currentTick - $this->lastSpeedTick + 0.5);
         if ($this->speedTicks > 0) {
             $ticks += $this->speedTicks;
         }
         $this->speed = $from->subtract($to)->divide($ticks);
         $this->lastSpeedTick = $currentTick;
     } elseif ($distanceSquared == 0) {
         $this->speed = new Vector3(0, 0, 0);
         $this->lastSpeedTick = $currentTick;
     }
     if ($this->speedTicks > 0) {
         --$this->speedTicks;
     }
     if ($revert) {
         $this->lastX = $from->x;
         $this->lastY = $from->y;
         $this->lastZ = $from->z;
         $this->lastYaw = $from->yaw;
         $this->lastPitch = $from->pitch;
         $pk = new MoveEntityPacket();
         $pk->eid = 0;
         $pk->x = $from->x;
         $pk->y = $from->y + $this->getEyeHeight();
         $pk->z = $from->z;
         $pk->bodyYaw = $from->yaw;
         $pk->pitch = $from->pitch;
         $pk->yaw = $from->yaw;
         $pk->teleport = true;
         $this->directDataPacket($pk);
         $this->forceMovement = new Vector3($from->x, $from->y, $from->z);
     } else {
         $this->forceMovement = null;
         if ($distanceSquared != 0 and $this->nextChunkOrderRun > 20) {
             $this->nextChunkOrderRun = 20;
         }
     }
     $this->newPosition = null;
 }