From 75cab3dfc34b94b975cb1f53f235fd565df97801 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 28 May 2015 22:43:39 +0200 Subject: [PATCH] Improved updates after first tick --- src/pocketmine/entity/Entity.php | 129 ++++++++++++-------------- src/pocketmine/entity/FallingSand.php | 5 +- src/pocketmine/entity/Item.php | 8 +- src/pocketmine/entity/PrimedTNT.php | 5 +- src/pocketmine/entity/Projectile.php | 5 +- 5 files changed, 77 insertions(+), 75 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 1a193f40c..62151c67f 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -184,7 +184,7 @@ abstract class Entity extends Location implements Metadatable{ public $isCollidedVertically = false; public $noDamageTicks; - private $justCreated; + protected $justCreated; protected $fireProof; private $invulnerable; @@ -223,16 +223,15 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->setPositionAndRotation( - new Vector3( + $this->temporalVector->setComponents( $this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2] ), $this->namedtag->Rotation[0], - $this->namedtag->Rotation[1], - true + $this->namedtag->Rotation[1] ); - $this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); + $this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); if(!isset($this->namedtag->FallDistance)){ $this->namedtag->FallDistance = new Float("FallDistance", 0); @@ -971,10 +970,8 @@ abstract class Entity extends Location implements Metadatable{ if($onGround === true){ if($this->fallDistance > 0){ if($this instanceof Living){ - //TODO + $this->fall($this->fallDistance); } - - $this->fall($this->fallDistance); $this->resetFallDistance(); } }elseif($distanceThisTick < 0){ @@ -1246,56 +1243,47 @@ abstract class Entity extends Location implements Metadatable{ } - $pos = new Vector3( - ($this->boundingBox->minX + $this->boundingBox->maxX) / 2, - $this->boundingBox->minY + $this->ySize, - ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 - ); + $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; + $this->y = $this->boundingBox->minY - $this->ySize; + $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; - $result = true; - - if(!$this->setPosition($pos)){ - $this->boundingBox->setBB($axisalignedbb); - $result = false; - }else{ - - if($this instanceof Player){ - if(!$this->onGround or $movY != 0){ - $bb = clone $this->boundingBox; - $bb->minY -= 1; - if(count($this->level->getCollisionBlocks($bb)) > 0){ - $this->onGround = true; - }else{ - $this->onGround = false; - } + if($this instanceof Player){ + if(!$this->onGround or $movY != 0){ + $bb = clone $this->boundingBox; + $bb->minY -= 1; + if(count($this->level->getCollisionBlocks($bb)) > 0){ + $this->onGround = true; + }else{ + $this->onGround = false; } - $this->isCollided = $this->onGround; - }else{ - $this->isCollidedVertically = $movY != $dy; - $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); - $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); - $this->onGround = ($movY != $dy and $movY < 0); - } - $this->updateFallState($dy, $this->onGround); - - if($movX != $dx){ - $this->motionX = 0; - } - - if($movY != $dy){ - $this->motionY = 0; - } - - if($movZ != $dz){ - $this->motionZ = 0; } + $this->isCollided = $this->onGround; + }else{ + $this->isCollidedVertically = $movY != $dy; + $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); + $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); + $this->onGround = ($movY != $dy and $movY < 0); } + $this->updateFallState($dy, $this->onGround); + + if($movX != $dx){ + $this->motionX = 0; + } + + if($movY != $dy){ + $this->motionY = 0; + } + + if($movZ != $dz){ + $this->motionZ = 0; + } + //TODO: vehicle collision events (first we need to spawn them!) Timings::$entityMoveTimer->stopTiming(); - return $result; + return true; } } @@ -1349,25 +1337,7 @@ abstract class Entity extends Location implements Metadatable{ $this->scheduleUpdate(); } - public function setPosition(Vector3 $pos){ - if($this->closed){ - return false; - } - - if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){ - if($this->switchLevel($pos->getLevel()) === false){ - return false; - } - } - - $this->x = $pos->x; - $this->y = $pos->y; - $this->z = $pos->z; - - $radius = $this->width / 2; - $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius); - - + protected function checkChunks(){ if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){ if($this->chunk !== null){ $this->chunk->removeEntity($this); @@ -1390,11 +1360,32 @@ abstract class Entity extends Location implements Metadatable{ } if($this->chunk === null){ - return true; + return; } $this->chunk->addEntity($this); } + } + + public function setPosition(Vector3 $pos){ + if($this->closed){ + return false; + } + + if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){ + if($this->switchLevel($pos->getLevel()) === false){ + return false; + } + } + + $this->x = $pos->x; + $this->y = $pos->y; + $this->z = $pos->z; + + $radius = $this->width / 2; + $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius); + + $this->checkChunks(); return true; } diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 0bc6ba72f..4fcde0dd1 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -89,7 +89,10 @@ class FallingSand extends Entity{ $this->timings->startTiming(); - $tickDiff = max(1, $currentTick - $this->lastUpdate); + $tickDiff = $currentTick - $this->lastUpdate; + if($tickDiff <= 0 and !$this->justCreated){ + return true; + } $this->lastUpdate = $currentTick; $hasUpdate = $this->entityBaseTick($tickDiff); diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index bd58af67b..70f398330 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -81,8 +81,8 @@ class Item extends Entity{ } $tickDiff = $currentTick - $this->lastUpdate; - if($tickDiff <= 0){ - return false; + if($tickDiff <= 0 and !$this->justCreated){ + return true; } $this->lastUpdate = $currentTick; @@ -102,7 +102,9 @@ class Item extends Entity{ $this->motionY -= $this->gravity; - $this->checkObstruction($this->x, $this->y, $this->z); + if($this->checkObstruction($this->x, $this->y, $this->z)){ + $hasUpdate = true; + } $this->move($this->motionX, $this->motionY, $this->motionZ); diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index d25a52c00..ddc43b602 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -78,7 +78,10 @@ class PrimedTNT extends Entity implements Explosive{ $this->timings->startTiming(); - $tickDiff = max(1, $currentTick - $this->lastUpdate); + $tickDiff = $currentTick - $this->lastUpdate; + if($tickDiff <= 0 and !$this->justCreated){ + return true; + } $this->lastUpdate = $currentTick; $hasUpdate = $this->entityBaseTick($tickDiff); diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index a7c01dd6f..6c3755624 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -83,7 +83,10 @@ abstract class Projectile extends Entity{ } - $tickDiff = max(1, $currentTick - $this->lastUpdate); + $tickDiff = $currentTick - $this->lastUpdate; + if($tickDiff <= 0 and !$this->justCreated){ + return true; + } $this->lastUpdate = $currentTick; $hasUpdate = $this->entityBaseTick($tickDiff);