Fixed entity partial block moving

This commit is contained in:
Shoghi Cervantes 2014-08-30 15:31:22 +02:00
parent 6477f4f077
commit 7a10f91330
2 changed files with 54 additions and 57 deletions

View File

@ -152,6 +152,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
protected $sleeping = false; protected $sleeping = false;
protected $clientID = null; protected $clientID = null;
protected $stepHeight = 0.5;
public $usedChunks = []; public $usedChunks = [];
protected $loadQueue = []; protected $loadQueue = [];
protected $chunkACK = []; protected $chunkACK = [];
@ -1347,7 +1349,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk = new MovePlayerPacket(); $pk = new MovePlayerPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y + $this->height; //teleport from head $pk->y = $this->y + 1.62;
$pk->z = $this->z; $pk->z = $this->z;
$pk->bodyYaw = $this->yaw; $pk->bodyYaw = $this->yaw;
$pk->pitch = $this->pitch; $pk->pitch = $this->pitch;
@ -1360,15 +1362,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$dz = $newPos->z - $this->z; $dz = $newPos->z - $this->z;
$this->setRotation($packet->yaw % 360, $packet->pitch % 360); $this->setRotation($packet->yaw % 360, $packet->pitch % 360);
$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); //$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
$this->move($dx + $this->motionX, $dy + $this->motionY, $dz + $this->motionZ); $this->move($dx, $dy, $dz);
$this->motionX = $this->motionY = $this->motionZ = 0;
if($this->x != $packet->x or $this->y != $packet->y or $this->z != $packet->z){ if($this->x != $newPos->x or $this->y != $newPos->y or $this->z != $newPos->z){
$pk = new MovePlayerPacket(); $pk = new MovePlayerPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y + $this->height; //teleport from head $pk->y = $this->y + 1.62;
$pk->z = $this->z; $pk->z = $this->z;
$pk->bodyYaw = $this->yaw; $pk->bodyYaw = $this->yaw;
$pk->pitch = $this->pitch; $pk->pitch = $this->pitch;

View File

@ -122,6 +122,10 @@ abstract class Entity extends Position implements Metadatable{
private $health = 20; private $health = 20;
private $maxHealth = 20; private $maxHealth = 20;
protected $ySize = 0;
protected $stepHeight = 0;
public $keepMovement = true;
public $fallDistance; public $fallDistance;
public $ticksLived; public $ticksLived;
public $lastUpdate; public $lastUpdate;
@ -713,23 +717,22 @@ abstract class Entity extends Position implements Metadatable{
} }
public function move($dx, $dy, $dz){ public function move($dx, $dy, $dz){
if($this->inBlock){ //$collision = [];
$this->boundingBox->offset($dx, $dy, $dz); //$this->checkBlockCollision($collision);
$this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; if($dx == 0 and $dz == 0 and $dy == 0){
$this->y = $this->boundingBox->minY/* + $this->height*/; return;
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; }
}else{
//$collision = []; //if($this->inBlock){ //TODO: noclip
//$this->checkBlockCollision($collision); // $this->boundingBox->offset($dx, $dy, $dz);
if($dx == 0 and $dz == 0 and $dy == 0){ // $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
return; // $this->y = $this->boundingBox->minY/* + $this->height*/;
} // $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
//}else{
Timings::$entityMoveTimer->startTiming(); Timings::$entityMoveTimer->startTiming();
$ox = $this->x; $this->ySize *= 0.4;
$oy = $this->y;
$oz = $this->z;
if($this->isColliding){ //With cobweb? if($this->isColliding){ //With cobweb?
$this->isColliding = false; $this->isColliding = false;
@ -773,7 +776,7 @@ abstract class Entity extends Position implements Metadatable{
//TODO: big messy loop //TODO: big messy loop
}*/ }*/
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($movX, $dy, $movZ)); $list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz));
foreach($list as $bb){ foreach($list as $bb){
@ -782,13 +785,13 @@ abstract class Entity extends Position implements Metadatable{
$this->boundingBox->offset(0, $dy, 0); $this->boundingBox->offset(0, $dy, 0);
if($movY != $dy){ if(!$this->keepMovement and $movY != $dy){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
} }
$fallingFlag = $this->onGround or ($dy != $movY and $movY < 0); $fallingFlag = ($this->onGround or $dy != $movY and $movY < 0);
foreach($list as $bb){ foreach($list as $bb){
$dx = $bb->calculateXOffset($this->boundingBox, $dx); $dx = $bb->calculateXOffset($this->boundingBox, $dx);
@ -796,7 +799,7 @@ abstract class Entity extends Position implements Metadatable{
$this->boundingBox->offset($dx, 0, 0); $this->boundingBox->offset($dx, 0, 0);
if($movX != $dx){ if(!$this->keepMovement and $movX != $dx){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
@ -808,28 +811,19 @@ abstract class Entity extends Position implements Metadatable{
$this->boundingBox->offset(0, 0, $dz); $this->boundingBox->offset(0, 0, $dz);
if($movZ != $dz){ if(!$this->keepMovement and $movZ != $dz){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
} }
if($movY != $dy){
$dy = 0;
foreach($list as $bb){
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
}
$this->boundingBox->offset(0, $dy, 0); if($this->stepHeight > 0 and $fallingFlag and $this->ySize < 0.05 and ($movX != $dx or $movZ != $dz)){
}
if($this->gravity > 0 and $fallingFlag /*and $sneak*/ and ($movX != $dx or $movZ != $dz)){
$cx = $dx; $cx = $dx;
$cy = $dy; $cy = $dy;
$cz = $dz; $cz = $dz;
$dx = $movX; $dx = $movX;
$dy = $this->gravity; $dy = $this->stepHeight;
$dz = $movZ; $dz = $movZ;
$axisalignedbb1 = clone $this->boundingBox; $axisalignedbb1 = clone $this->boundingBox;
@ -842,7 +836,8 @@ abstract class Entity extends Position implements Metadatable{
$dy = $bb->calculateYOffset($this->boundingBox, $dy); $dy = $bb->calculateYOffset($this->boundingBox, $dy);
} }
if($movY != $dy){ $this->boundingBox->offset(0, $dy, 0);
if(!$this->keepMovement and $movY != $dy){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
@ -853,7 +848,7 @@ abstract class Entity extends Position implements Metadatable{
} }
$this->boundingBox->offset($dx, 0, 0); $this->boundingBox->offset($dx, 0, 0);
if($movX != $dx){ if(!$this->keepMovement and $movX != $dx){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
@ -864,25 +859,25 @@ abstract class Entity extends Position implements Metadatable{
} }
$this->boundingBox->offset(0, 0, $dz); $this->boundingBox->offset(0, 0, $dz);
if($movZ != $dz){ if(!$this->keepMovement and $movZ != $dz){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
} }
if($movY != $dy){ if(!$this->keepMovement and $movY != $dy){
$dx = 0; $dx = 0;
$dy = 0; $dy = 0;
$dz = 0; $dz = 0;
}else{ }else{
$dy = -$this->gravity; $dy = -$this->stepHeight;
foreach($list as $bb){ foreach($list as $bb){
$dy = $bb->calculateYOffset($this->boundingBox, $dy); $dy = $bb->calculateYOffset($this->boundingBox, $dy);
} }
$this->boundingBox->offset(0, $dy, 0); $this->boundingBox->offset(0, $dy, 0);
} }
if($cx * $cx + $cz * $cz > $dx * $dx + $dz * $dz){ if(($cx * $cx + $cz * $cz) >= ($dx * $dx + $dz * $dz)){
$dx = $cx; $dx = $cx;
$dy = $cy; $dy = $cy;
$dz = $cz; $dz = $cz;
@ -894,33 +889,33 @@ abstract class Entity extends Position implements Metadatable{
$pos = new Vector3( $pos = new Vector3(
($this->boundingBox->minX + $this->boundingBox->maxX) / 2, ($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
$this->boundingBox->minY/* + $this->height*/, $this->boundingBox->minY - $this->ySize/* + $this->height*/,
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
); );
if(!$this->setPosition($pos)){ if(!$this->setPosition($pos)){
$this->boundingBox->setBB($axisalignedbb); $this->boundingBox->setBB($axisalignedbb);
} }else{
$this->onGround = ($movY != $dy and $movY < 0);
$this->updateFallState($dy, $this->onGround);
$this->onGround = $movY != $dy and $movY < 0; if($movX != $dx){
$this->updateFallState($dy, $this->onGround); $this->motionX = 0;
}
if($movX != $dx){ if($movY != $dy){
$this->motionX = 0; $this->motionY = 0;
} }
if($movY != $dy){ if($movZ != $dz){
$this->motionY = 0; $this->motionZ = 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();
} //}
} }
/** /**
@ -984,7 +979,7 @@ abstract class Entity extends Position implements Metadatable{
$this->z = $pos->z; $this->z = $pos->z;
$radius = $this->width / 2; $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->boundingBox->setBounds($pos->x - $radius, $pos->y + $this->ySize, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height + $this->ySize, $pos->z + $radius);
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) and $this->chunk->getZ() !== ($this->z >> 4))){ if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) and $this->chunk->getZ() !== ($this->z >> 4))){
@ -1062,6 +1057,7 @@ abstract class Entity extends Position implements Metadatable{
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
$this->ySize = 0;
$pos = $ev->getTo(); $pos = $ev->getTo();
$this->setMotion(new Vector3(0, 0, 0)); $this->setMotion(new Vector3(0, 0, 0));