From 8f525ab3998e708ec298c95e436dec70b35a47a2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 20 Jan 2022 19:14:28 +0000 Subject: [PATCH] Replace disallowed operators in src/entity/ --- src/entity/Attribute.php | 8 +-- src/entity/AttributeMap.php | 2 +- src/entity/Entity.php | 68 +++++++++++++------------- src/entity/EntityDataHelper.php | 6 +-- src/entity/ExperienceManager.php | 6 +-- src/entity/Human.php | 12 ++--- src/entity/HungerManager.php | 8 +-- src/entity/Living.php | 26 +++++----- src/entity/Location.php | 2 +- src/entity/Skin.php | 2 +- src/entity/Squid.php | 2 +- src/entity/Villager.php | 2 +- src/entity/effect/EffectInstance.php | 4 +- src/entity/effect/EffectManager.php | 6 +-- src/entity/effect/PoisonEffect.php | 2 +- src/entity/object/ExperienceOrb.php | 6 +-- src/entity/object/FallingBlock.php | 4 +- src/entity/object/ItemEntity.php | 14 +++--- src/entity/object/Painting.php | 4 +- src/entity/object/PrimedTNT.php | 4 +- src/entity/projectile/Arrow.php | 6 +-- src/entity/projectile/Projectile.php | 10 ++-- src/entity/projectile/SplashPotion.php | 6 +-- 23 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/entity/Attribute.php b/src/entity/Attribute.php index 589a5da47f..3f9bc7faf0 100644 --- a/src/entity/Attribute.php +++ b/src/entity/Attribute.php @@ -65,7 +65,7 @@ class Attribute{ protected $desynchronized = true; public function __construct(string $id, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true){ - if($minValue > $maxValue or $defaultValue > $maxValue or $defaultValue < $minValue){ + if($minValue > $maxValue || $defaultValue > $maxValue || $defaultValue < $minValue){ throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue"); } $this->id = $id; @@ -123,7 +123,7 @@ class Attribute{ * @return $this */ public function setDefaultValue(float $defaultValue){ - if($defaultValue > $this->getMaxValue() or $defaultValue < $this->getMinValue()){ + if($defaultValue > $this->getMaxValue() || $defaultValue < $this->getMinValue()){ throw new \InvalidArgumentException("Default $defaultValue is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue()); } @@ -146,7 +146,7 @@ class Attribute{ * @return $this */ public function setValue(float $value, bool $fit = false, bool $forceSend = false){ - if($value > $this->getMaxValue() or $value < $this->getMinValue()){ + if($value > $this->getMaxValue() || $value < $this->getMinValue()){ if(!$fit){ throw new \InvalidArgumentException("Value $value is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue()); } @@ -172,7 +172,7 @@ class Attribute{ } public function isDesynchronized() : bool{ - return $this->shouldSend and $this->desynchronized; + return $this->shouldSend && $this->desynchronized; } public function markSynchronized(bool $synced = true) : void{ diff --git a/src/entity/AttributeMap.php b/src/entity/AttributeMap.php index 0a4a11d3de..cc427d9296 100644 --- a/src/entity/AttributeMap.php +++ b/src/entity/AttributeMap.php @@ -49,7 +49,7 @@ class AttributeMap{ */ public function needSend() : array{ return array_filter($this->attributes, function(Attribute $attribute) : bool{ - return $attribute->isSyncable() and $attribute->isDesynchronized(); + return $attribute->isSyncable() && $attribute->isDesynchronized(); }); } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index d720a3a135..417253b988 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -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); diff --git a/src/entity/EntityDataHelper.php b/src/entity/EntityDataHelper.php index 928ebcdc43..f01a10bb73 100644 --- a/src/entity/EntityDataHelper.php +++ b/src/entity/EntityDataHelper.php @@ -46,7 +46,7 @@ final class EntityDataHelper{ $pos = self::parseVec3($nbt, "Pos", false); $yawPitch = $nbt->getTag("Rotation"); - if(!($yawPitch instanceof ListTag) or $yawPitch->getTagType() !== NBT::TAG_Float){ + if(!($yawPitch instanceof ListTag) || $yawPitch->getTagType() !== NBT::TAG_Float){ throw new SavedDataLoadingException("'Rotation' should be a List"); } /** @var FloatTag[] $values */ @@ -63,10 +63,10 @@ final class EntityDataHelper{ */ public static function parseVec3(CompoundTag $nbt, string $tagName, bool $optional) : Vector3{ $pos = $nbt->getTag($tagName); - if($pos === null and $optional){ + if($pos === null && $optional){ return new Vector3(0, 0, 0); } - if(!($pos instanceof ListTag) or ($pos->getTagType() !== NBT::TAG_Double && $pos->getTagType() !== NBT::TAG_Float)){ + if(!($pos instanceof ListTag) || ($pos->getTagType() !== NBT::TAG_Double && $pos->getTagType() !== NBT::TAG_Float)){ throw new SavedDataLoadingException("'$tagName' should be a List or List"); } /** @var DoubleTag[]|FloatTag[] $values */ diff --git a/src/entity/ExperienceManager.php b/src/entity/ExperienceManager.php index c91f9ffeea..4ed1c5486a 100644 --- a/src/entity/ExperienceManager.php +++ b/src/entity/ExperienceManager.php @@ -252,14 +252,14 @@ class ExperienceManager{ /** @var Durable[] $equipment */ $equipment = []; - if(($item = $this->entity->getInventory()->getItemInHand()) instanceof Durable and $item->hasEnchantment(VanillaEnchantments::MENDING())){ + if(($item = $this->entity->getInventory()->getItemInHand()) instanceof Durable && $item->hasEnchantment(VanillaEnchantments::MENDING())){ $equipment[$mainHandIndex] = $item; } - if(($item = $this->entity->getOffHandInventory()->getItem(0)) instanceof Durable and $item->hasEnchantment(VanillaEnchantments::MENDING())){ + if(($item = $this->entity->getOffHandInventory()->getItem(0)) instanceof Durable && $item->hasEnchantment(VanillaEnchantments::MENDING())){ $equipment[$offHandIndex] = $item; } foreach($this->entity->getArmorInventory()->getContents() as $k => $armorItem){ - if($armorItem instanceof Durable and $armorItem->hasEnchantment(VanillaEnchantments::MENDING())){ + if($armorItem instanceof Durable && $armorItem->hasEnchantment(VanillaEnchantments::MENDING())){ $equipment[$k] = $armorItem; } } diff --git a/src/entity/Human.php b/src/entity/Human.php index 7aebc89c34..56da6570eb 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -166,7 +166,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ } public function consumeObject(Consumable $consumable) : bool{ - if($consumable instanceof FoodSource && $consumable->requiresHunger() and !$this->hungerManager->isHungry()){ + if($consumable instanceof FoodSource && $consumable->requiresHunger() && !$this->hungerManager->isHungry()){ return false; } @@ -266,11 +266,11 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ /** @var CompoundTag $item */ foreach($inventoryTag as $i => $item){ $slot = $item->getByte("Slot"); - if($slot >= 0 and $slot < 9){ //Hotbar + if($slot >= 0 && $slot < 9){ //Hotbar //Old hotbar saving stuff, ignore it - }elseif($slot >= 100 and $slot < 104){ //Armor + }elseif($slot >= 100 && $slot < 104){ //Armor $armorInventoryItems[$slot - 100] = Item::nbtDeserialize($item); - }elseif($slot >= 9 and $slot < $this->inventory->getSize() + 9){ + }elseif($slot >= 9 && $slot < $this->inventory->getSize() + 9){ $inventoryItems[$slot - 9] = Item::nbtDeserialize($item); } } @@ -340,8 +340,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ parent::applyDamageModifiers($source); $type = $source->getCause(); - if($type !== EntityDamageEvent::CAUSE_SUICIDE and $type !== EntityDamageEvent::CAUSE_VOID - and ($this->inventory->getItemInHand() instanceof Totem || $this->offHandInventory->getItem(0) instanceof Totem)){ + if($type !== EntityDamageEvent::CAUSE_SUICIDE && $type !== EntityDamageEvent::CAUSE_VOID + && ($this->inventory->getItemInHand() instanceof Totem || $this->offHandInventory->getItem(0) instanceof Totem)){ $compensation = $this->getHealth() - $source->getFinalDamage() - 1; if($compensation < 0){ diff --git a/src/entity/HungerManager.php b/src/entity/HungerManager.php index f0e0e9d8e0..4b95751a00 100644 --- a/src/entity/HungerManager.php +++ b/src/entity/HungerManager.php @@ -182,7 +182,7 @@ class HungerManager{ } public function tick(int $tickDiff = 1) : void{ - if(!$this->entity->isAlive() or !$this->enabled){ + if(!$this->entity->isAlive() || !$this->enabled){ return; } $food = $this->getFood(); @@ -194,12 +194,12 @@ class HungerManager{ $this->foodTickTimer = 0; } - if($difficulty === World::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){ + if($difficulty === World::DIFFICULTY_PEACEFUL && $this->foodTickTimer % 10 === 0){ if($food < $this->getMaxFood()){ $this->addFood(1.0); $food = $this->getFood(); } - if($this->foodTickTimer % 20 === 0 and $health < $this->entity->getMaxHealth()){ + if($this->foodTickTimer % 20 === 0 && $health < $this->entity->getMaxHealth()){ $this->entity->heal(new EntityRegainHealthEvent($this->entity, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); } } @@ -211,7 +211,7 @@ class HungerManager{ $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); } }elseif($food <= 0){ - if(($difficulty === World::DIFFICULTY_EASY and $health > 10) or ($difficulty === World::DIFFICULTY_NORMAL and $health > 1) or $difficulty === World::DIFFICULTY_HARD){ + if(($difficulty === World::DIFFICULTY_EASY && $health > 10) || ($difficulty === World::DIFFICULTY_NORMAL && $health > 1) || $difficulty === World::DIFFICULTY_HARD){ $this->entity->attack(new EntityDamageEvent($this->entity, EntityDamageEvent::CAUSE_STARVATION, 1)); } } diff --git a/src/entity/Living.php b/src/entity/Living.php index a5b6101c96..d5f169b11a 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -187,7 +187,7 @@ abstract class Living extends Entity{ $wasAlive = $this->isAlive(); parent::setHealth($amount); $this->healthAttr->setValue(ceil($this->getHealth()), true); - if($this->isAlive() and !$wasAlive){ + if($this->isAlive() && !$wasAlive){ $this->broadcastAnimation(new RespawnAnimation($this)); } } @@ -407,7 +407,7 @@ abstract class Living extends Entity{ * to effects or armour. */ public function applyDamageModifiers(EntityDamageEvent $source) : void{ - if($this->lastDamageCause !== null and $this->attackTime > 0){ + if($this->lastDamageCause !== null && $this->attackTime > 0){ if($this->lastDamageCause->getBaseDamage() >= $source->getBaseDamage()){ $source->cancel(); } @@ -419,7 +419,7 @@ abstract class Living extends Entity{ } $cause = $source->getCause(); - if(($resistance = $this->effectManager->get(VanillaEffects::RESISTANCE())) !== null and $cause !== EntityDamageEvent::CAUSE_VOID and $cause !== EntityDamageEvent::CAUSE_SUICIDE){ + if(($resistance = $this->effectManager->get(VanillaEffects::RESISTANCE())) !== null && $cause !== EntityDamageEvent::CAUSE_VOID && $cause !== EntityDamageEvent::CAUSE_SUICIDE){ $source->setModifier(-$source->getFinalDamage() * min(1, 0.2 * $resistance->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE); } @@ -443,10 +443,10 @@ abstract class Living extends Entity{ $this->setAbsorption(max(0, $this->getAbsorption() + $source->getModifier(EntityDamageEvent::MODIFIER_ABSORPTION))); $this->damageArmor($source->getBaseDamage()); - if($source instanceof EntityDamageByEntityEvent and ($attacker = $source->getDamager()) !== null){ + if($source instanceof EntityDamageByEntityEvent && ($attacker = $source->getDamager()) !== null){ $damage = 0; foreach($this->armorInventory->getContents() as $k => $item){ - if($item instanceof Armor and ($thornsLevel = $item->getEnchantmentLevel(VanillaEnchantments::THORNS())) > 0){ + if($item instanceof Armor && ($thornsLevel = $item->getEnchantmentLevel(VanillaEnchantments::THORNS())) > 0){ if(mt_rand(0, 99) < $thornsLevel * 15){ $this->damageItem($item, 3); $damage += ($thornsLevel > 10 ? $thornsLevel - 10 : 1 + mt_rand(0, 3)); @@ -493,10 +493,10 @@ abstract class Living extends Entity{ $source->cancel(); } - if($this->effectManager->has(VanillaEffects::FIRE_RESISTANCE()) and ( + if($this->effectManager->has(VanillaEffects::FIRE_RESISTANCE()) && ( $source->getCause() === EntityDamageEvent::CAUSE_FIRE - or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK - or $source->getCause() === EntityDamageEvent::CAUSE_LAVA + || $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK + || $source->getCause() === EntityDamageEvent::CAUSE_LAVA ) ){ $source->cancel(); @@ -504,8 +504,8 @@ abstract class Living extends Entity{ $this->applyDamageModifiers($source); - if($source instanceof EntityDamageByEntityEvent and ( - $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION or + if($source instanceof EntityDamageByEntityEvent && ( + $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) ){ //TODO: knockback should not just apply for entity damage sources @@ -642,7 +642,7 @@ abstract class Living extends Entity{ if(!$this->canBreathe()){ $this->setBreathing(false); - if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(VanillaEnchantments::RESPIRATION())) <= 0 or + if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(VanillaEnchantments::RESPIRATION())) <= 0 || lcg_value() <= (1 / ($respirationLevel + 1)) ){ $ticks -= $tickDiff; @@ -672,7 +672,7 @@ abstract class Living extends Entity{ * Returns whether the entity can currently breathe. */ public function canBreathe() : bool{ - return $this->effectManager->has(VanillaEffects::WATER_BREATHING()) or $this->effectManager->has(VanillaEffects::CONDUIT_POWER()) or !$this->isUnderwater(); + return $this->effectManager->has(VanillaEffects::WATER_BREATHING()) || $this->effectManager->has(VanillaEffects::CONDUIT_POWER()) || !$this->isUnderwater(); } /** @@ -767,7 +767,7 @@ abstract class Living extends Entity{ $block = $this->getWorld()->getBlockAt($vector3->x, $vector3->y, $vector3->z); $blocks[$nextIndex++] = $block; - if($maxLength !== 0 and count($blocks) > $maxLength){ + if($maxLength !== 0 && count($blocks) > $maxLength){ array_shift($blocks); --$nextIndex; } diff --git a/src/entity/Location.php b/src/entity/Location.php index c04ac9acbd..2ebbb26619 100644 --- a/src/entity/Location.php +++ b/src/entity/Location.php @@ -68,7 +68,7 @@ class Location extends Position{ public function equals(Vector3 $v) : bool{ if($v instanceof Location){ - return parent::equals($v) and $v->yaw == $this->yaw and $v->pitch == $this->pitch; + return parent::equals($v) && $v->yaw == $this->yaw && $v->pitch == $this->pitch; } return parent::equals($v); } diff --git a/src/entity/Skin.php b/src/entity/Skin.php index 604d6f6a28..786a6e7118 100644 --- a/src/entity/Skin.php +++ b/src/entity/Skin.php @@ -68,7 +68,7 @@ final class Skin{ if(!in_array($len, self::ACCEPTED_SKIN_SIZES, true)){ throw new InvalidSkinException("Invalid skin data size $len bytes (allowed sizes: " . implode(", ", self::ACCEPTED_SKIN_SIZES) . ")"); } - if($capeData !== "" and strlen($capeData) !== 8192){ + if($capeData !== "" && strlen($capeData) !== 8192){ throw new InvalidSkinException("Invalid cape data size " . strlen($capeData) . " bytes (must be exactly 8192 bytes)"); } diff --git a/src/entity/Squid.php b/src/entity/Squid.php index 1010c5d78d..063e87b16b 100644 --- a/src/entity/Squid.php +++ b/src/entity/Squid.php @@ -95,7 +95,7 @@ class Squid extends WaterAnimal{ if($this->isAlive()){ - if($this->location->y > 62 and $this->swimDirection !== null){ + if($this->location->y > 62 && $this->swimDirection !== null){ $this->swimDirection = $this->swimDirection->withComponents(null, -0.5, null); } diff --git a/src/entity/Villager.php b/src/entity/Villager.php index d43e4faf9b..7e1c081ccd 100644 --- a/src/entity/Villager.php +++ b/src/entity/Villager.php @@ -57,7 +57,7 @@ class Villager extends Living implements Ageable{ /** @var int $profession */ $profession = $nbt->getInt("Profession", self::PROFESSION_FARMER); - if($profession > 4 or $profession < 0){ + if($profession > 4 || $profession < 0){ $profession = self::PROFESSION_FARMER; } diff --git a/src/entity/effect/EffectInstance.php b/src/entity/effect/EffectInstance.php index c908c7ec7a..566ca1e5e0 100644 --- a/src/entity/effect/EffectInstance.php +++ b/src/entity/effect/EffectInstance.php @@ -77,7 +77,7 @@ class EffectInstance{ * @return $this */ public function setDuration(int $duration) : EffectInstance{ - if($duration < 0 or $duration > Limits::INT32_MAX){ + if($duration < 0 || $duration > Limits::INT32_MAX){ throw new \InvalidArgumentException("Effect duration must be in range 0 - " . Limits::INT32_MAX . ", got $duration"); } $this->duration = $duration; @@ -118,7 +118,7 @@ class EffectInstance{ * @return $this */ public function setAmplifier(int $amplifier) : EffectInstance{ - if($amplifier < 0 or $amplifier > 255){ + if($amplifier < 0 || $amplifier > 255){ throw new \InvalidArgumentException("Amplifier must be in range 0 - 255, got $amplifier"); } $this->amplifier = $amplifier; diff --git a/src/entity/effect/EffectManager.php b/src/entity/effect/EffectManager.php index 17bdb89471..ee561229ff 100644 --- a/src/entity/effect/EffectManager.php +++ b/src/entity/effect/EffectManager.php @@ -91,7 +91,7 @@ class EffectManager{ $ev = new EntityEffectRemoveEvent($this->entity, $effect); $ev->call(); if($ev->isCancelled()){ - if($hasExpired and !$ev->getEffect()->hasExpired()){ //altered duration of an expired effect to make it not get removed + if($hasExpired && !$ev->getEffect()->hasExpired()){ //altered duration of an expired effect to make it not get removed foreach($this->effectAddHooks as $hook){ $hook($ev->getEffect(), true); } @@ -140,7 +140,7 @@ class EffectManager{ $oldEffect = $this->effects[$index]; if( abs($effect->getAmplifier()) < $oldEffect->getAmplifier() - or (abs($effect->getAmplifier()) === abs($oldEffect->getAmplifier()) and $effect->getDuration() < $oldEffect->getDuration()) + || (abs($effect->getAmplifier()) === abs($oldEffect->getAmplifier()) && $effect->getDuration() < $oldEffect->getDuration()) ){ $cancelled = true; } @@ -180,7 +180,7 @@ class EffectManager{ $colors = []; $ambient = true; foreach($this->effects as $effect){ - if($effect->isVisible() and $effect->getType()->hasBubbles()){ + if($effect->isVisible() && $effect->getType()->hasBubbles()){ $level = $effect->getEffectLevel(); $color = $effect->getColor(); for($i = 0; $i < $level; ++$i){ diff --git a/src/entity/effect/PoisonEffect.php b/src/entity/effect/PoisonEffect.php index e3b1618b5f..166be76c62 100644 --- a/src/entity/effect/PoisonEffect.php +++ b/src/entity/effect/PoisonEffect.php @@ -47,7 +47,7 @@ class PoisonEffect extends Effect{ } public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{ - if($entity->getHealth() > 1 or $this->fatal){ + if($entity->getHealth() > 1 || $this->fatal){ $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); $entity->attack($ev); } diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index ef26ffb0e7..274abf379b 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -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()); diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index 9957453b63..cb2551349a 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -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{ diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 248b09d1e2..73d67a1928 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -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(); } diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index a95560e243..ff59de0430 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -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; } } diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index f3ed921b89..70d58dafa8 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -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{ diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index ca194d2c56..47924c8cb3 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -176,16 +176,16 @@ class Arrow extends Projectile{ $item = VanillaItems::ARROW(); $playerInventory = match(true){ !$player->hasFiniteResources() => null, //arrows are not picked up in creative - $player->getOffHandInventory()->getItem(0)->canStackWith($item) and $player->getOffHandInventory()->canAddItem($item) => $player->getOffHandInventory(), + $player->getOffHandInventory()->getItem(0)->canStackWith($item) && $player->getOffHandInventory()->canAddItem($item) => $player->getOffHandInventory(), $player->getInventory()->canAddItem($item) => $player->getInventory(), default => null }; $ev = new EntityItemPickupEvent($player, $this, $item, $playerInventory); - if($player->hasFiniteResources() and $playerInventory === null){ + if($player->hasFiniteResources() && $playerInventory === null){ $ev->cancel(); } - if($this->pickupMode === self::PICKUP_NONE or ($this->pickupMode === self::PICKUP_CREATIVE and !$player->isCreative())){ + if($this->pickupMode === self::PICKUP_NONE || ($this->pickupMode === self::PICKUP_CREATIVE && !$player->isCreative())){ $ev->cancel(); } diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index cf700b052a..1fa1071f92 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -78,7 +78,7 @@ abstract class Projectile extends Entity{ $this->damage = $nbt->getDouble("damage", $this->damage); (function() use ($nbt) : void{ - if(($tileXTag = $nbt->getTag("tileX")) instanceof IntTag and ($tileYTag = $nbt->getTag("tileY")) instanceof IntTag and ($tileZTag = $nbt->getTag("tileZ")) instanceof IntTag){ + if(($tileXTag = $nbt->getTag("tileX")) instanceof IntTag && ($tileYTag = $nbt->getTag("tileY")) instanceof IntTag && ($tileZTag = $nbt->getTag("tileZ")) instanceof IntTag){ $blockPos = new Vector3($tileXTag->getValue(), $tileYTag->getValue(), $tileZTag->getValue()); }else{ return; @@ -102,7 +102,7 @@ abstract class Projectile extends Entity{ } public function canCollideWith(Entity $entity) : bool{ - return $entity instanceof Living and !$this->onGround; + return $entity instanceof Living && !$this->onGround; } public function canBeCollidedWith() : bool{ @@ -155,7 +155,7 @@ abstract class Projectile extends Entity{ } public function onNearbyBlockChange() : void{ - if($this->blockHit !== null and $this->getWorld()->isInLoadedTerrain($this->blockHit->getPosition()) and !$this->blockHit->isSameState($this->getWorld()->getBlock($this->blockHit->getPosition()))){ + if($this->blockHit !== null && $this->getWorld()->isInLoadedTerrain($this->blockHit->getPosition()) && !$this->blockHit->isSameState($this->getWorld()->getBlock($this->blockHit->getPosition()))){ $this->blockHit = null; } @@ -163,7 +163,7 @@ abstract class Projectile extends Entity{ } public function hasMovementUpdate() : bool{ - return $this->blockHit === null and parent::hasMovementUpdate(); + return $this->blockHit === null && parent::hasMovementUpdate(); } protected function move(float $dx, float $dy, float $dz) : void{ @@ -194,7 +194,7 @@ abstract class Projectile extends Entity{ $newDiff = $end->subtractVector($start); foreach($this->getWorld()->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){ - if($entity->getId() === $this->getOwningEntityId() and $this->ticksLived < 5){ + if($entity->getId() === $this->getOwningEntityId() && $this->ticksLived < 5){ continue; } diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index a7ecfa47a3..364ded7c27 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -99,14 +99,14 @@ class SplashPotion extends Throwable{ if($hasEffects){ if(!$this->willLinger()){ foreach($this->getWorld()->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){ - if($entity instanceof Living and $entity->isAlive()){ + if($entity instanceof Living && $entity->isAlive()){ $distanceSquared = $entity->getEyePos()->distanceSquared($this->location); if($distanceSquared > 16){ //4 blocks continue; } $distanceMultiplier = 1 - (sqrt($distanceSquared) / 4); - if($event instanceof ProjectileHitEntityEvent and $entity === $event->getEntityHit()){ + if($event instanceof ProjectileHitEntityEvent && $entity === $event->getEntityHit()){ $distanceMultiplier = 1.0; } @@ -129,7 +129,7 @@ class SplashPotion extends Throwable{ }else{ //TODO: lingering potions } - }elseif($event instanceof ProjectileHitBlockEvent and $this->getPotionType()->equals(PotionType::WATER())){ + }elseif($event instanceof ProjectileHitBlockEvent && $this->getPotionType()->equals(PotionType::WATER())){ $blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace()); if($blockIn->getId() === BlockLegacyIds::FIRE){