diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 70525303a..3bb151290 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1167,6 +1167,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return true; } + $this->timings->startTiming(); + $this->processMovement(); $hasUpdate = $this->entityBaseTick(); @@ -1232,6 +1234,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } + $this->timings->stopTiming(); + return true; } diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 491880341..b8cf0c6ed 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -65,87 +65,97 @@ class Arrow extends Projectile{ } public function onUpdate(){ - $this->entityBaseTick(); - - if($this->closed !== false){ + if($this->closed){ return false; } - $movingObjectPosition = null; + $this->timings->startTiming(); - $this->motionY -= $this->gravity; + $this->entityBaseTick(); - $this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); + if(!$this->dead){ - $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); + $movingObjectPosition = null; - $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); + $this->motionY -= $this->gravity; - $nearDistance = PHP_INT_MAX; - $nearEntity = null; + $this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - foreach($list as $entity){ - if(/*!$entity->canCollideWith($this) or */($entity === $this->shootingEntity and $this->ticksLived < 5)){ - continue; - } + $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); - $axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3); - $ob = $axisalignedbb->calculateIntercept($this, $moveVector); + $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); - if($ob === null){ - continue; - } + $nearDistance = PHP_INT_MAX; + $nearEntity = null; - $distance = $this->distance($ob->hitVector); + foreach($list as $entity){ + if(/*!$entity->canCollideWith($this) or */ + ($entity === $this->shootingEntity and $this->ticksLived < 5) + ){ + continue; + } - if($distance < $nearDistance){ - $nearDistance = $distance; - $nearEntity = $entity; - } - } + $axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3); + $ob = $axisalignedbb->calculateIntercept($this, $moveVector); - if($nearEntity !== null){ - $movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity); - } + if($ob === null){ + continue; + } - if($movingObjectPosition !== null){ - if($movingObjectPosition->entityHit !== null){ - $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); - $damage = ceil($motion * $this->damage); + $distance = $this->distance($ob->hitVector); - - $ev = new EntityDamageByEntityEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); - - $this->server->getPluginManager()->callEvent($ev); - - if(!$ev->isCancelled()){ - $movingObjectPosition->entityHit->attack($damage, $ev); - if($this->fireTicks > 0){ - $movingObjectPosition->entityHit->setOnFire(5); - } - $this->kill(); + if($distance < $nearDistance){ + $nearDistance = $distance; + $nearEntity = $entity; } } + + if($nearEntity !== null){ + $movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity); + } + + if($movingObjectPosition !== null){ + if($movingObjectPosition->entityHit !== null){ + $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); + $damage = ceil($motion * $this->damage); + + + $ev = new EntityDamageByEntityEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + + $this->server->getPluginManager()->callEvent($ev); + + if(!$ev->isCancelled()){ + $movingObjectPosition->entityHit->attack($damage, $ev); + if($this->fireTicks > 0){ + $movingObjectPosition->entityHit->setOnFire(5); + } + $this->kill(); + } + } + } + + $this->move($this->motionX, $this->motionY, $this->motionZ); + + if($this->onGround){ + $this->motionX = 0; + $this->motionY = 0; + $this->motionZ = 0; + } + + if($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ + $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); + $this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI); + $this->pitch = (atan2($this->motionY, $f) * 180 / M_PI); + } + + if($this->age > 1200){ + $this->kill(); + } + $this->updateMovement(); + } - $this->move($this->motionX, $this->motionY, $this->motionZ); - - if($this->onGround){ - $this->motionX = 0; - $this->motionY = 0; - $this->motionZ = 0; - } - - if($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ - $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); - $this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI); - $this->pitch = (atan2($this->motionY, $f) * 180 / M_PI); - } - - if($this->age > 1200){ - $this->kill(); - } - $this->updateMovement(); + $this->timings->stopTiming(); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); } diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/DroppedItem.php index 811efb826..06b1a358b 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/DroppedItem.php @@ -66,40 +66,47 @@ class DroppedItem extends Entity{ } public function onUpdate(){ - $this->entityBaseTick(); - if($this->closed !== false){ return false; } - if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay - --$this->pickupDelay; + $this->timings->startTiming(); + + $this->entityBaseTick(); + + if(!$this->dead){ + + if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay + --$this->pickupDelay; + } + + $this->motionY -= $this->gravity; + + $this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); + $this->move($this->motionX, $this->motionY, $this->motionZ); + + $friction = 1 - $this->drag; + + if($this->onGround){ + $friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction; + } + + $this->motionX *= $friction; + $this->motionY *= 1 - $this->drag; + $this->motionZ *= $friction; + + if($this->onGround){ + $this->motionY *= -0.5; + } + + if($this->age > 6000){ + $this->kill(); + } + + $this->updateMovement(); } - $this->motionY -= $this->gravity; - - $this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - $this->move($this->motionX, $this->motionY, $this->motionZ); - - $friction = 1 - $this->drag; - - if($this->onGround){ - $friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction; - } - - $this->motionX *= $friction; - $this->motionY *= 1 - $this->drag; - $this->motionZ *= $friction; - - if($this->onGround){ - $this->motionY *= -0.5; - } - - if($this->age > 6000){ - $this->kill(); - } - - $this->updateMovement(); + $this->timings->stopTiming(); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 45f4e1f7a..c7f19a533 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -152,12 +152,17 @@ abstract class Entity extends Position implements Metadatable{ public $closed = false; + /** @var \pocketmine\event\TimingsHandler */ + protected $timings; + public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ throw new \Exception("Invalid garbage Chunk given to Entity"); } + $this->timings = Timings::getEntityTimings($this); + if($this->eyeHeight === null){ $this->eyeHeight = $this->height; } @@ -533,7 +538,7 @@ abstract class Entity extends Position implements Metadatable{ } foreach($this->hasSpawned as $player){ - $player->directDataPacket($pk); + $player->dataPacket($pk); } } @@ -575,11 +580,14 @@ abstract class Entity extends Position implements Metadatable{ if($this->closed !== false){ return false; } + $this->timings->startTiming(); $hasUpdate = $this->entityBaseTick(); $this->updateMovement(); + $this->timings->stopTiming(); + //if($this->isStatic()) return true; //return !($this instanceof Player); diff --git a/src/pocketmine/entity/FallingBlock.php b/src/pocketmine/entity/FallingBlock.php index 8b4830572..e9851daa9 100644 --- a/src/pocketmine/entity/FallingBlock.php +++ b/src/pocketmine/entity/FallingBlock.php @@ -63,45 +63,51 @@ class FallingBlock extends Entity{ } public function onUpdate(){ - $this->entityBaseTick(); - if($this->closed or $this->dead){ + if($this->closed){ return false; } - if($this->ticksLived === 1){ - $block = $this->level->getBlock($this->floor()); - if($block->getID() != $this->blockId){ + $this->timings->startTiming(); + + $this->entityBaseTick(); + + if(!$this->dead){ + if($this->ticksLived === 1){ + $block = $this->level->getBlock($this->floor()); + if($block->getID() != $this->blockId){ + $this->kill(); + return true; + } + $this->level->setBlock($this->floor(), 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 = $this->floor(); + + if($this->onGround){ $this->kill(); - return true; + $block = $this->level->getBlock($pos); + if(!$block->isFullBlock){ + $this->getLevel()->dropItem($this, Item::get($this->getBlock(), 0, 1)); + }else{ + $this->getLevel()->setBlock($pos, Block::get($this->getBlock(), 0), true); + } } - $this->level->setBlock($this->floor(), Block::get(0, true)); + $this->updateMovement(); } - $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 = $this->floor(); - - if($this->onGround){ - $this->kill(); - $block = $this->level->getBlock($pos); - if(!$block->isFullBlock){ - $this->getLevel()->dropItem($this, Item::get($this->getBlock(), 0, 1)); - }else{ - $this->getLevel()->setBlock($pos, Block::get($this->getBlock(), 0), true); - } - } - - $this->updateMovement(); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7d5996729..488d3b886 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -742,7 +742,11 @@ class Level implements ChunkManager, Metadatable{ * @return bool */ public function isFullBlock(Vector3 $pos){ - $bb = $this->getBlock($pos)->getBoundingBox(); + if($pos instanceof Block){ + $bb = $pos->getBoundingBox(); + }else{ + $bb = $this->getBlock($pos)->getBoundingBox(); + } return $bb instanceof AxisAlignedBB and $bb->getAverageEdgeLength() >= 1; } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 9632d51d4..147d759b6 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -170,6 +170,8 @@ class Furnace extends Tile implements InventoryHolder, Container{ return false; } + $this->timings->startTiming(); + $ret = false; $fuel = $this->inventory->getFuel(); @@ -248,6 +250,8 @@ class Furnace extends Tile implements InventoryHolder, Container{ $this->lastUpdate = microtime(true); + $this->timings->stopTiming(); + return $ret; } } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 39b5ac059..0f70dae26 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -54,6 +54,7 @@ abstract class Tile extends Position{ public $namedtag; protected $lastUpdate; protected $server; + protected $timings; /** @var \pocketmine\event\TimingsHandler */ public $tickTimer; @@ -63,6 +64,8 @@ abstract class Tile extends Position{ throw new \Exception("Invalid garbage Chunk given to Tile"); } + $this->timings = Timings::getTileEntityTimings($this); + $this->server = $chunk->getProvider()->getLevel()->getServer(); $this->chunk = $chunk; $this->setLevel($chunk->getProvider()->getLevel());