Improved updates after first tick

This commit is contained in:
Shoghi Cervantes 2015-05-28 22:43:39 +02:00
parent 03f178379e
commit 75cab3dfc3
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
5 changed files with 77 additions and 75 deletions

View File

@ -184,7 +184,7 @@ abstract class Entity extends Location implements Metadatable{
public $isCollidedVertically = false; public $isCollidedVertically = false;
public $noDamageTicks; public $noDamageTicks;
private $justCreated; protected $justCreated;
protected $fireProof; protected $fireProof;
private $invulnerable; private $invulnerable;
@ -223,16 +223,15 @@ abstract class Entity extends Location implements Metadatable{
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation( $this->setPositionAndRotation(
new Vector3( $this->temporalVector->setComponents(
$this->namedtag["Pos"][0], $this->namedtag["Pos"][0],
$this->namedtag["Pos"][1], $this->namedtag["Pos"][1],
$this->namedtag["Pos"][2] $this->namedtag["Pos"][2]
), ),
$this->namedtag->Rotation[0], $this->namedtag->Rotation[0],
$this->namedtag->Rotation[1], $this->namedtag->Rotation[1]
true
); );
$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)){ if(!isset($this->namedtag->FallDistance)){
$this->namedtag->FallDistance = new Float("FallDistance", 0); $this->namedtag->FallDistance = new Float("FallDistance", 0);
@ -971,10 +970,8 @@ abstract class Entity extends Location implements Metadatable{
if($onGround === true){ if($onGround === true){
if($this->fallDistance > 0){ if($this->fallDistance > 0){
if($this instanceof Living){ if($this instanceof Living){
//TODO $this->fall($this->fallDistance);
} }
$this->fall($this->fallDistance);
$this->resetFallDistance(); $this->resetFallDistance();
} }
}elseif($distanceThisTick < 0){ }elseif($distanceThisTick < 0){
@ -1246,56 +1243,47 @@ abstract class Entity extends Location implements Metadatable{
} }
$pos = new Vector3( $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->y = $this->boundingBox->minY - $this->ySize;
$this->boundingBox->minY + $this->ySize, $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
);
$result = true; if($this instanceof Player){
if(!$this->onGround or $movY != 0){
if(!$this->setPosition($pos)){ $bb = clone $this->boundingBox;
$this->boundingBox->setBB($axisalignedbb); $bb->minY -= 1;
$result = false; if(count($this->level->getCollisionBlocks($bb)) > 0){
}else{ $this->onGround = true;
}else{
if($this instanceof Player){ $this->onGround = false;
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!) //TODO: vehicle collision events (first we need to spawn them!)
Timings::$entityMoveTimer->stopTiming(); Timings::$entityMoveTimer->stopTiming();
return $result; return true;
} }
} }
@ -1349,25 +1337,7 @@ abstract class Entity extends Location implements Metadatable{
$this->scheduleUpdate(); $this->scheduleUpdate();
} }
public function setPosition(Vector3 $pos){ protected function checkChunks(){
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);
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){ if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){
if($this->chunk !== null){ if($this->chunk !== null){
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
@ -1390,11 +1360,32 @@ abstract class Entity extends Location implements Metadatable{
} }
if($this->chunk === null){ if($this->chunk === null){
return true; return;
} }
$this->chunk->addEntity($this); $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; return true;
} }

View File

@ -89,7 +89,10 @@ class FallingSand extends Entity{
$this->timings->startTiming(); $this->timings->startTiming();
$tickDiff = max(1, $currentTick - $this->lastUpdate); $tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0 and !$this->justCreated){
return true;
}
$this->lastUpdate = $currentTick; $this->lastUpdate = $currentTick;
$hasUpdate = $this->entityBaseTick($tickDiff); $hasUpdate = $this->entityBaseTick($tickDiff);

View File

@ -81,8 +81,8 @@ class Item extends Entity{
} }
$tickDiff = $currentTick - $this->lastUpdate; $tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0){ if($tickDiff <= 0 and !$this->justCreated){
return false; return true;
} }
$this->lastUpdate = $currentTick; $this->lastUpdate = $currentTick;
@ -102,7 +102,9 @@ class Item extends Entity{
$this->motionY -= $this->gravity; $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); $this->move($this->motionX, $this->motionY, $this->motionZ);

View File

@ -78,7 +78,10 @@ class PrimedTNT extends Entity implements Explosive{
$this->timings->startTiming(); $this->timings->startTiming();
$tickDiff = max(1, $currentTick - $this->lastUpdate); $tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0 and !$this->justCreated){
return true;
}
$this->lastUpdate = $currentTick; $this->lastUpdate = $currentTick;
$hasUpdate = $this->entityBaseTick($tickDiff); $hasUpdate = $this->entityBaseTick($tickDiff);

View File

@ -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; $this->lastUpdate = $currentTick;
$hasUpdate = $this->entityBaseTick($tickDiff); $hasUpdate = $this->entityBaseTick($tickDiff);