Entity: rename movX/movY/movZ to wantedX/wantedY/wantedZ

this makes the code much easier to understand.
This commit is contained in:
Dylan K. Taylor 2021-09-05 14:06:53 +01:00
parent 73cc841d0b
commit d329bfb25d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 16 additions and 16 deletions

View File

@ -1087,9 +1087,9 @@ abstract class Entity{
Timings::$entityMove->startTiming(); Timings::$entityMove->startTiming();
$movX = $dx; $wantedX = $dx;
$movY = $dy; $wantedY = $dy;
$movZ = $dz; $wantedZ = $dz;
if($this->keepMovement){ if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz); $this->boundingBox->offset($dx, $dy, $dz);
@ -1108,7 +1108,7 @@ abstract class Entity{
$moveBB->offset(0, $dy, 0); $moveBB->offset(0, $dy, 0);
$fallingFlag = ($this->onGround or ($dy != $movY and $movY < 0)); $fallingFlag = ($this->onGround or ($dy != $wantedY and $wantedY < 0));
foreach($list as $bb){ foreach($list as $bb){
$dx = $bb->calculateXOffset($moveBB, $dx); $dx = $bb->calculateXOffset($moveBB, $dx);
@ -1122,13 +1122,13 @@ abstract class Entity{
$moveBB->offset(0, 0, $dz); $moveBB->offset(0, 0, $dz);
if($this->stepHeight > 0 and $fallingFlag and ($movX != $dx or $movZ != $dz)){ if($this->stepHeight > 0 and $fallingFlag and ($wantedX != $dx or $wantedZ != $dz)){
$cx = $dx; $cx = $dx;
$cy = $dy; $cy = $dy;
$cz = $dz; $cz = $dz;
$dx = $movX; $dx = $wantedX;
$dy = $this->stepHeight; $dy = $this->stepHeight;
$dz = $movZ; $dz = $wantedZ;
$stepBB = clone $this->boundingBox; $stepBB = clone $this->boundingBox;
@ -1182,13 +1182,13 @@ abstract class Entity{
$this->getWorld()->onEntityMoved($this); $this->getWorld()->onEntityMoved($this);
$this->checkBlockIntersections(); $this->checkBlockIntersections();
$this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz); $this->checkGroundState($wantedX, $wantedY, $wantedZ, $dx, $dy, $dz);
$this->updateFallState($dy, $this->onGround); $this->updateFallState($dy, $this->onGround);
$this->motion = $this->motion->withComponents( $this->motion = $this->motion->withComponents(
$movX != $dx ? 0 : null, $wantedX != $dx ? 0 : null,
$movY != $dy ? 0 : null, $wantedY != $dy ? 0 : null,
$movZ != $dz ? 0 : null $wantedZ != $dz ? 0 : null
); );
//TODO: vehicle collision events (first we need to spawn them!) //TODO: vehicle collision events (first we need to spawn them!)
@ -1196,11 +1196,11 @@ abstract class Entity{
Timings::$entityMove->stopTiming(); Timings::$entityMove->stopTiming();
} }
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{ protected function checkGroundState(float $wantedX, float $wantedY, float $wantedZ, float $dx, float $dy, float $dz) : void{
$this->isCollidedVertically = $movY != $dy; $this->isCollidedVertically = $wantedY != $dy;
$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); $this->isCollidedHorizontally = ($wantedX != $dx or $wantedZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
$this->onGround = ($movY != $dy and $movY < 0); $this->onGround = ($wantedY != $dy and $wantedY < 0);
} }
/** /**

View File

@ -1058,7 +1058,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return 0; return 0;
} }
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{ protected function checkGroundState(float $wantedX, float $wantedY, float $wantedZ, float $dx, float $dy, float $dz) : void{
if($this->isSpectator()){ if($this->isSpectator()){
$this->onGround = false; $this->onGround = false;
}else{ }else{