当前位置: 首页>>代码示例>>PHP>>正文


PHP Location::subtract方法代码示例

本文整理汇总了PHP中pocketmine\level\Location::subtract方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::subtract方法的具体用法?PHP Location::subtract怎么用?PHP Location::subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\level\Location的用法示例。


在下文中一共展示了Location::subtract方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processMovement


//.........这里部分代码省略.........
         $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;
 }
开发者ID:PepbookPvP,项目名称:Genisys,代码行数:101,代码来源:Player.php

示例2: processMovement

 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;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:100,代码来源:Player.php

示例3: processMovement

 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) {
//.........这里部分代码省略.........
开发者ID:ZenaGamingsky,项目名称:Steadfast2,代码行数:101,代码来源:Player.php


注:本文中的pocketmine\level\Location::subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。