Replace disallowed operators in src/entity/

This commit is contained in:
Dylan K. Taylor
2022-01-20 19:14:28 +00:00
parent be1996752a
commit 8f525ab399
23 changed files with 105 additions and 105 deletions

View File

@ -166,7 +166,7 @@ class ExperienceOrb extends Entity{
}
$currentTarget = $this->getTargetPlayer();
if($currentTarget !== null and (!$currentTarget->isAlive() or !$currentTarget->getXpManager()->canAttractXpOrbs() or $currentTarget->location->distanceSquared($this->location) > self::MAX_TARGET_DISTANCE ** 2)){
if($currentTarget !== null && (!$currentTarget->isAlive() || !$currentTarget->getXpManager()->canAttractXpOrbs() || $currentTarget->location->distanceSquared($this->location) > self::MAX_TARGET_DISTANCE ** 2)){
$currentTarget = null;
}
@ -174,7 +174,7 @@ class ExperienceOrb extends Entity{
if($currentTarget === null){
$newTarget = $this->getWorld()->getNearestEntity($this->location, self::MAX_TARGET_DISTANCE, Human::class);
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator()) and $newTarget->getXpManager()->canAttractXpOrbs()){
if($newTarget instanceof Human && !($newTarget instanceof Player && $newTarget->isSpectator()) && $newTarget->getXpManager()->canAttractXpOrbs()){
$currentTarget = $newTarget;
}
}
@ -194,7 +194,7 @@ class ExperienceOrb extends Entity{
$this->motion = $this->motion->addVector($vector->normalize()->multiply(0.2 * (1 - sqrt($distance)) ** 2));
}
if($currentTarget->getXpManager()->canPickupXp() and $this->boundingBox->intersectsWith($currentTarget->getBoundingBox())){
if($currentTarget->getXpManager()->canPickupXp() && $this->boundingBox->intersectsWith($currentTarget->getBoundingBox())){
$this->flagForDespawn();
$currentTarget->getXpManager()->onPickupXp($this->getXpValue());

View File

@ -112,11 +112,11 @@ class FallingBlock extends Entity{
$blockTarget = $this->block->tickFalling();
}
if($this->onGround or $blockTarget !== null){
if($this->onGround || $blockTarget !== null){
$this->flagForDespawn();
$block = $world->getBlock($pos);
if(!$block->canBeReplaced() or !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) or ($this->onGround and abs($this->location->y - $this->location->getFloorY()) > 0.001)){
if(!$block->canBeReplaced() || !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) || ($this->onGround && abs($this->location->y - $this->location->getFloorY()) > 0.001)){
//FIXME: anvils are supposed to destroy torches
$world->dropItem($this->location, $this->block->asItem());
}else{

View File

@ -103,16 +103,16 @@ class ItemEntity extends Entity{
$hasUpdate = parent::entityBaseTick($tickDiff);
if(!$this->isFlaggedForDespawn() and $this->pickupDelay !== self::NEVER_DESPAWN){ //Infinite delay
if(!$this->isFlaggedForDespawn() && $this->pickupDelay !== self::NEVER_DESPAWN){ //Infinite delay
$this->pickupDelay -= $tickDiff;
if($this->pickupDelay < 0){
$this->pickupDelay = 0;
}
if($this->hasMovementUpdate() and $this->despawnDelay % self::MERGE_CHECK_PERIOD === 0){
if($this->hasMovementUpdate() && $this->despawnDelay % self::MERGE_CHECK_PERIOD === 0){
$mergeable = [$this]; //in case the merge target ends up not being this
$mergeTarget = $this;
foreach($this->getWorld()->getNearbyEntities($this->boundingBox->expandedCopy(0.5, 0.5, 0.5), $this) as $entity){
if(!$entity instanceof ItemEntity or $entity->isFlaggedForDespawn()){
if(!$entity instanceof ItemEntity || $entity->isFlaggedForDespawn()){
continue;
}
@ -151,7 +151,7 @@ class ItemEntity extends Entity{
*/
public function isMergeable(ItemEntity $entity) : bool{
$item = $entity->item;
return $entity !== $this && $entity->pickupDelay !== self::NEVER_DESPAWN and $item->canStackWith($this->item) and $item->getCount() + $this->item->getCount() <= $item->getMaxStackSize();
return $entity !== $this && $entity->pickupDelay !== self::NEVER_DESPAWN && $item->canStackWith($this->item) && $item->getCount() + $this->item->getCount() <= $item->getMaxStackSize();
}
/**
@ -238,7 +238,7 @@ class ItemEntity extends Entity{
* @throws \InvalidArgumentException
*/
public function setDespawnDelay(int $despawnDelay) : void{
if(($despawnDelay < 0 or $despawnDelay > self::MAX_DESPAWN_DELAY) and $despawnDelay !== self::NEVER_DESPAWN){
if(($despawnDelay < 0 || $despawnDelay > self::MAX_DESPAWN_DELAY) && $despawnDelay !== self::NEVER_DESPAWN){
throw new \InvalidArgumentException("Despawn ticker must be in range 0 ... " . self::MAX_DESPAWN_DELAY . " or " . self::NEVER_DESPAWN . ", got $despawnDelay");
}
$this->despawnDelay = $despawnDelay;
@ -291,13 +291,13 @@ class ItemEntity extends Entity{
$item = $this->getItem();
$playerInventory = match(true){
$player->getOffHandInventory()->getItem(0)->canStackWith($item) and $player->getOffHandInventory()->getAddableItemQuantity($item) > 0 => $player->getOffHandInventory(),
$player->getOffHandInventory()->getItem(0)->canStackWith($item) && $player->getOffHandInventory()->getAddableItemQuantity($item) > 0 => $player->getOffHandInventory(),
$player->getInventory()->getAddableItemQuantity($item) > 0 => $player->getInventory(),
default => null
};
$ev = new EntityItemPickupEvent($player, $this, $item, $playerInventory);
if($player->hasFiniteResources() and $playerInventory === null){
if($player->hasFiniteResources() && $playerInventory === null){
$ev->cancel();
}

View File

@ -107,7 +107,7 @@ class Painting extends Entity{
if($this->lastDamageCause instanceof EntityDamageByEntityEvent){
$killer = $this->lastDamageCause->getDamager();
if($killer instanceof Player and !$killer->hasFiniteResources()){
if($killer instanceof Player && !$killer->hasFiniteResources()){
$drops = false;
}
}
@ -212,7 +212,7 @@ class Painting extends Entity{
$pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h);
$block = $world->getBlockAt($pos->x, $pos->y, $pos->z);
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){
if($block->isSolid() || !$block->getSide($oppositeSide)->isSolid()){
return false;
}
}

View File

@ -58,7 +58,7 @@ class PrimedTNT extends Entity implements Explosive{
}
public function setFuse(int $fuse) : void{
if($fuse < 0 or $fuse > 32767){
if($fuse < 0 || $fuse > 32767){
throw new \InvalidArgumentException("Fuse must be in the range 0-32767");
}
$this->fuse = $fuse;
@ -112,7 +112,7 @@ class PrimedTNT extends Entity implements Explosive{
}
}
return $hasUpdate or $this->fuse >= 0;
return $hasUpdate || $this->fuse >= 0;
}
public function explode() : void{