mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Replace disallowed operators in src/entity/
This commit is contained in:
@ -227,9 +227,9 @@ abstract class Entity{
|
||||
|
||||
$this->location = $location->asLocation();
|
||||
assert(
|
||||
!is_nan($this->location->x) and !is_infinite($this->location->x) and
|
||||
!is_nan($this->location->y) and !is_infinite($this->location->y) and
|
||||
!is_nan($this->location->z) and !is_infinite($this->location->z)
|
||||
!is_nan($this->location->x) && !is_infinite($this->location->x) &&
|
||||
!is_nan($this->location->y) && !is_infinite($this->location->y) &&
|
||||
!is_nan($this->location->z) && !is_infinite($this->location->z)
|
||||
);
|
||||
|
||||
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||
@ -590,7 +590,7 @@ abstract class Entity{
|
||||
$this->health = 0;
|
||||
}
|
||||
}
|
||||
}elseif($amount <= $this->getMaxHealth() or $amount < $this->health){
|
||||
}elseif($amount <= $this->getMaxHealth() || $amount < $this->health){
|
||||
$this->health = $amount;
|
||||
}else{
|
||||
$this->health = $this->getMaxHealth();
|
||||
@ -641,13 +641,13 @@ abstract class Entity{
|
||||
|
||||
$this->checkBlockIntersections();
|
||||
|
||||
if($this->location->y <= World::Y_MIN - 16 and $this->isAlive()){
|
||||
if($this->location->y <= World::Y_MIN - 16 && $this->isAlive()){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
|
||||
$this->attack($ev);
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
if($this->isOnFire() and $this->doOnFireTick($tickDiff)){
|
||||
if($this->isOnFire() && $this->doOnFireTick($tickDiff)){
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
@ -683,7 +683,7 @@ abstract class Entity{
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setFireTicks(int $fireTicks) : void{
|
||||
if($fireTicks < 0 or $fireTicks > 0x7fff){
|
||||
if($fireTicks < 0 || $fireTicks > 0x7fff){
|
||||
throw new \InvalidArgumentException("Fire ticks must be in range 0 ... " . 0x7fff . ", got $fireTicks");
|
||||
}
|
||||
$this->fireTicks = $fireTicks;
|
||||
@ -700,13 +700,13 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
protected function doOnFireTick(int $tickDiff = 1) : bool{
|
||||
if($this->isFireProof() and $this->fireTicks > 1){
|
||||
if($this->isFireProof() && $this->fireTicks > 1){
|
||||
$this->fireTicks = 1;
|
||||
}else{
|
||||
$this->fireTicks -= $tickDiff;
|
||||
}
|
||||
|
||||
if(($this->fireTicks % 20 === 0) or $tickDiff > 20){
|
||||
if(($this->fireTicks % 20 === 0) || $tickDiff > 20){
|
||||
$this->dealFireDamage();
|
||||
}
|
||||
|
||||
@ -728,7 +728,7 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
public function canCollideWith(Entity $entity) : bool{
|
||||
return !$this->justCreated and $entity !== $this;
|
||||
return !$this->justCreated && $entity !== $this;
|
||||
}
|
||||
|
||||
public function canBeCollidedWith() : bool{
|
||||
@ -748,13 +748,13 @@ abstract class Entity{
|
||||
$this->setImmobile($still);
|
||||
}
|
||||
|
||||
if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0 or (!$wasStill and $still)){
|
||||
if($teleport || $diffPosition > 0.0001 || $diffRotation > 1.0 || (!$wasStill && $still)){
|
||||
$this->lastLocation = $this->location->asLocation();
|
||||
|
||||
$this->broadcastMovement($teleport);
|
||||
}
|
||||
|
||||
if($diffMotion > 0.0025 or $wasStill !== $still){ //0.05 ** 2
|
||||
if($diffMotion > 0.0025 || $wasStill !== $still){ //0.05 ** 2
|
||||
$this->lastMotion = clone $this->motion;
|
||||
|
||||
$this->broadcastMotion();
|
||||
@ -853,27 +853,27 @@ abstract class Entity{
|
||||
$direction = Facing::WEST;
|
||||
}
|
||||
|
||||
if($eastNonSolid and 1 - $diffX < $limit){
|
||||
if($eastNonSolid && 1 - $diffX < $limit){
|
||||
$limit = 1 - $diffX;
|
||||
$direction = Facing::EAST;
|
||||
}
|
||||
|
||||
if($downNonSolid and $diffY < $limit){
|
||||
if($downNonSolid && $diffY < $limit){
|
||||
$limit = $diffY;
|
||||
$direction = Facing::DOWN;
|
||||
}
|
||||
|
||||
if($upNonSolid and 1 - $diffY < $limit){
|
||||
if($upNonSolid && 1 - $diffY < $limit){
|
||||
$limit = 1 - $diffY;
|
||||
$direction = Facing::UP;
|
||||
}
|
||||
|
||||
if($northNonSolid and $diffZ < $limit){
|
||||
if($northNonSolid && $diffZ < $limit){
|
||||
$limit = $diffZ;
|
||||
$direction = Facing::NORTH;
|
||||
}
|
||||
|
||||
if($southNonSolid and 1 - $diffZ < $limit){
|
||||
if($southNonSolid && 1 - $diffZ < $limit){
|
||||
$direction = Facing::SOUTH;
|
||||
}
|
||||
|
||||
@ -903,13 +903,13 @@ abstract class Entity{
|
||||
$angle += 360.0;
|
||||
}
|
||||
|
||||
if((0 <= $angle and $angle < 45) or (315 <= $angle and $angle < 360)){
|
||||
if((0 <= $angle && $angle < 45) || (315 <= $angle && $angle < 360)){
|
||||
return Facing::SOUTH;
|
||||
}
|
||||
if(45 <= $angle and $angle < 135){
|
||||
if(45 <= $angle && $angle < 135){
|
||||
return Facing::WEST;
|
||||
}
|
||||
if(135 <= $angle and $angle < 225){
|
||||
if(135 <= $angle && $angle < 225){
|
||||
return Facing::NORTH;
|
||||
}
|
||||
|
||||
@ -964,7 +964,7 @@ abstract class Entity{
|
||||
abs($this->motion->z) <= self::MOTION_THRESHOLD ? 0 : null
|
||||
);
|
||||
|
||||
if($this->motion->x != 0 or $this->motion->y != 0 or $this->motion->z != 0){
|
||||
if($this->motion->x != 0 || $this->motion->y != 0 || $this->motion->z != 0){
|
||||
$this->move($this->motion->x, $this->motion->y, $this->motion->z);
|
||||
}
|
||||
|
||||
@ -980,7 +980,7 @@ abstract class Entity{
|
||||
$this->timings->stopTiming();
|
||||
|
||||
//if($this->isStatic())
|
||||
return ($hasUpdate or $this->hasMovementUpdate());
|
||||
return ($hasUpdate || $this->hasMovementUpdate());
|
||||
//return !($this instanceof Player);
|
||||
}
|
||||
|
||||
@ -1019,10 +1019,10 @@ abstract class Entity{
|
||||
*/
|
||||
public function hasMovementUpdate() : bool{
|
||||
return (
|
||||
$this->forceMovementUpdate or
|
||||
$this->motion->x != 0 or
|
||||
$this->motion->y != 0 or
|
||||
$this->motion->z != 0 or
|
||||
$this->forceMovementUpdate ||
|
||||
$this->motion->x != 0 ||
|
||||
$this->motion->y != 0 ||
|
||||
$this->motion->z != 0 ||
|
||||
!$this->onGround
|
||||
);
|
||||
}
|
||||
@ -1095,7 +1095,7 @@ abstract class Entity{
|
||||
public function isInsideOfSolid() : bool{
|
||||
$block = $this->getWorld()->getBlockAt((int) floor($this->location->x), (int) floor($y = ($this->location->y + $this->getEyeHeight())), (int) floor($this->location->z));
|
||||
|
||||
return $block->isSolid() and !$block->isTransparent() and $block->collidesWithBB($this->getBoundingBox());
|
||||
return $block->isSolid() && !$block->isTransparent() && $block->collidesWithBB($this->getBoundingBox());
|
||||
}
|
||||
|
||||
protected function move(float $dx, float $dy, float $dz) : void{
|
||||
@ -1114,7 +1114,7 @@ abstract class Entity{
|
||||
|
||||
$moveBB = clone $this->boundingBox;
|
||||
|
||||
assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
|
||||
assert(abs($dx) <= 20 && abs($dy) <= 20 && abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
|
||||
|
||||
$list = $this->getWorld()->getCollisionBoxes($this, $moveBB->addCoord($dx, $dy, $dz), false);
|
||||
|
||||
@ -1124,7 +1124,7 @@ abstract class Entity{
|
||||
|
||||
$moveBB->offset(0, $dy, 0);
|
||||
|
||||
$fallingFlag = ($this->onGround or ($dy != $wantedY and $wantedY < 0));
|
||||
$fallingFlag = ($this->onGround || ($dy != $wantedY && $wantedY < 0));
|
||||
|
||||
foreach($list as $bb){
|
||||
$dx = $bb->calculateXOffset($moveBB, $dx);
|
||||
@ -1138,7 +1138,7 @@ abstract class Entity{
|
||||
|
||||
$moveBB->offset(0, 0, $dz);
|
||||
|
||||
if($this->stepHeight > 0 and $fallingFlag and ($wantedX != $dx or $wantedZ != $dz)){
|
||||
if($this->stepHeight > 0 && $fallingFlag && ($wantedX != $dx || $wantedZ != $dz)){
|
||||
$cx = $dx;
|
||||
$cy = $dy;
|
||||
$cz = $dz;
|
||||
@ -1214,9 +1214,9 @@ abstract class Entity{
|
||||
|
||||
protected function checkGroundState(float $wantedX, float $wantedY, float $wantedZ, float $dx, float $dy, float $dz) : void{
|
||||
$this->isCollidedVertically = $wantedY != $dy;
|
||||
$this->isCollidedHorizontally = ($wantedX != $dx or $wantedZ != $dz);
|
||||
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
|
||||
$this->onGround = ($wantedY != $dy and $wantedY < 0);
|
||||
$this->isCollidedHorizontally = ($wantedX != $dx || $wantedZ != $dz);
|
||||
$this->isCollided = ($this->isCollidedHorizontally || $this->isCollidedVertically);
|
||||
$this->onGround = ($wantedY != $dy && $wantedY < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1455,7 +1455,7 @@ abstract class Entity{
|
||||
//TODO: this will cause some visible lag during chunk resends; if the player uses a spawn egg in a chunk, the
|
||||
//created entity won't be visible until after the resend arrives. However, this is better than possibly crashing
|
||||
//the player by sending them entities too early.
|
||||
if(!isset($this->hasSpawned[$id]) and $player->getWorld() === $this->getWorld() and $player->hasReceivedChunk($this->location->getFloorX() >> Chunk::COORD_BIT_SIZE, $this->location->getFloorZ() >> Chunk::COORD_BIT_SIZE)){
|
||||
if(!isset($this->hasSpawned[$id]) && $player->getWorld() === $this->getWorld() && $player->hasReceivedChunk($this->location->getFloorX() >> Chunk::COORD_BIT_SIZE, $this->location->getFloorZ() >> Chunk::COORD_BIT_SIZE)){
|
||||
$this->hasSpawned[$id] = $player;
|
||||
|
||||
$this->sendSpawnPacket($player);
|
||||
|
Reference in New Issue
Block a user