Block: fixed LSP violations in blocks using BlockIdentifierFlattened

a property's type can't be changed by a subclass
This commit is contained in:
Dylan K. Taylor 2021-05-22 23:40:54 +01:00
parent 285ad25168
commit 73c229a236
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
11 changed files with 48 additions and 37 deletions

View File

@ -39,17 +39,18 @@ class DaylightSensor extends Transparent{
use AnalogRedstoneSignalEmitterTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var bool */
protected $inverted = false;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->inverted ? $this->idInfo->getSecondId() : parent::getId();
return $this->inverted ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
protected function writeStateToMeta() : int{
@ -58,7 +59,7 @@ class DaylightSensor extends Transparent{
public function readStateFromData(int $id, int $stateMeta) : void{
$this->signalStrength = BlockDataSerializer::readBoundedInt("signalStrength", $stateMeta, 0, 15);
$this->inverted = $id === $this->idInfo->getSecondId();
$this->inverted = $id === $this->idInfoFlattened->getSecondId();
}
public function getStateBitmask() : int{

View File

@ -37,16 +37,17 @@ use function rad2deg;
final class FloorCoralFan extends BaseCoral{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
private int $axis = Axis::X;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->dead = $id === $this->idInfo->getSecondId();
$this->dead = $id === $this->idInfoFlattened->getSecondId();
$this->axis = ($stateMeta >> 3) === BlockLegacyMetadata::CORAL_FAN_EAST_WEST ? Axis::X : Axis::Z;
$coralType = CoralTypeIdMap::getInstance()->fromId($stateMeta & BlockLegacyMetadata::CORAL_FAN_TYPE_MASK);
if($coralType === null){
@ -56,7 +57,7 @@ final class FloorCoralFan extends BaseCoral{
}
public function getId() : int{
return $this->dead ? $this->idInfo->getSecondId() : parent::getId();
return $this->dead ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function asItem() : Item{

View File

@ -37,22 +37,23 @@ class Furnace extends Opaque{
}
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var bool */
protected $lit = false; //this is set based on the blockID
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->lit ? $this->idInfo->getSecondId() : parent::getId();
return $this->lit ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->readFacingStateFromData($id, $stateMeta);
$this->lit = $id === $this->idInfo->getSecondId();
$this->lit = $id === $this->idInfoFlattened->getSecondId();
}
public function getLightLevel() : int{

View File

@ -40,7 +40,7 @@ use function min;
abstract class Liquid extends Transparent{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var int */
public $adjacentSources = 0;
@ -63,11 +63,12 @@ abstract class Liquid extends Transparent{
protected $still = false;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->still ? $this->idInfo->getSecondId() : parent::getId();
return $this->still ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
protected function writeStateToMeta() : int{
@ -77,7 +78,7 @@ abstract class Liquid extends Transparent{
public function readStateFromData(int $id, int $stateMeta) : void{
$this->decay = BlockDataSerializer::readBoundedInt("decay", $stateMeta & 0x07, 0, 7);
$this->falling = ($stateMeta & BlockLegacyMetadata::LIQUID_FLAG_FALLING) !== 0;
$this->still = $id === $this->idInfo->getSecondId();
$this->still = $id === $this->idInfoFlattened->getSecondId();
}
public function getStateBitmask() : int{

View File

@ -42,23 +42,24 @@ class RedstoneComparator extends Flowable{
use PoweredByRedstoneTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var bool */
protected $isSubtractMode = false;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->powered ? $this->idInfo->getSecondId() : parent::getId();
return $this->powered ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
$this->isSubtractMode = ($stateMeta & BlockLegacyMetadata::REDSTONE_COMPARATOR_FLAG_SUBTRACT) !== 0;
$this->powered = ($id === $this->idInfo->getSecondId() or ($stateMeta & BlockLegacyMetadata::REDSTONE_COMPARATOR_FLAG_POWERED) !== 0);
$this->powered = ($id === $this->idInfoFlattened->getSecondId() or ($stateMeta & BlockLegacyMetadata::REDSTONE_COMPARATOR_FLAG_POWERED) !== 0);
}
public function writeStateToMeta() : int{

View File

@ -29,18 +29,19 @@ class RedstoneLamp extends Opaque{
use PoweredByRedstoneTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->powered ? $this->idInfo->getSecondId() : parent::getId();
return $this->powered ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->powered = $id === $this->idInfo->getSecondId();
$this->powered = $id === $this->idInfoFlattened->getSecondId();
}
public function getLightLevel() : int{

View File

@ -31,21 +31,22 @@ use function mt_rand;
class RedstoneOre extends Opaque{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var bool */
protected $lit = false;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->lit ? $this->idInfo->getSecondId() : parent::getId();
return $this->lit ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->lit = $id === $this->idInfo->getSecondId();
$this->lit = $id === $this->idInfoFlattened->getSecondId();
}
public function isLit() : bool{

View File

@ -38,23 +38,24 @@ class RedstoneRepeater extends Flowable{
use PoweredByRedstoneTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var int */
protected $delay = 1;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->powered ? $this->idInfo->getSecondId() : parent::getId();
return $this->powered ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
$this->delay = BlockDataSerializer::readBoundedInt("delay", ($stateMeta >> 2) + 1, 1, 4);
$this->powered = $id === $this->idInfo->getSecondId();
$this->powered = $id === $this->idInfoFlattened->getSecondId();
}
public function writeStateToMeta() : int{

View File

@ -26,22 +26,23 @@ namespace pocketmine\block;
class RedstoneTorch extends Torch{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var bool */
protected $lit = true;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
public function getId() : int{
return $this->lit ? parent::getId() : $this->idInfo->getSecondId();
return $this->lit ? parent::getId() : $this->idInfoFlattened->getSecondId();
}
public function readStateFromData(int $id, int $stateMeta) : void{
parent::readStateFromData($id, $stateMeta);
$this->lit = $id !== $this->idInfo->getSecondId();
$this->lit = $id !== $this->idInfoFlattened->getSecondId();
}
public function isLit() : bool{

View File

@ -33,18 +33,19 @@ use pocketmine\world\BlockTransaction;
class Slab extends Transparent{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
/** @var SlabType */
protected $slabType;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name . " Slab", $breakInfo);
$this->slabType = SlabType::BOTTOM();
}
public function getId() : int{
return $this->slabType->equals(SlabType::DOUBLE()) ? $this->idInfo->getSecondId() : parent::getId();
return $this->slabType->equals(SlabType::DOUBLE()) ? $this->idInfoFlattened->getSecondId() : parent::getId();
}
protected function writeStateToMeta() : int{
@ -55,7 +56,7 @@ class Slab extends Transparent{
}
public function readStateFromData(int $id, int $stateMeta) : void{
if($id === $this->idInfo->getSecondId()){
if($id === $this->idInfoFlattened->getSecondId()){
$this->slabType = SlabType::DOUBLE();
}else{
$this->slabType = ($stateMeta & BlockLegacyMetadata::SLAB_FLAG_UPPER) !== 0 ? SlabType::TOP() : SlabType::BOTTOM();

View File

@ -42,9 +42,10 @@ final class WallCoralFan extends BaseCoral{
use HorizontalFacingTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $idInfoFlattened;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->idInfoFlattened = $idInfo;
parent::__construct($idInfo, $name, $breakInfo);
}
@ -54,13 +55,13 @@ final class WallCoralFan extends BaseCoral{
$coralTypeFlag = $stateMeta & BlockLegacyMetadata::CORAL_FAN_HANG_TYPE_MASK;
switch($id){
case $this->idInfo->getBlockId():
case $this->idInfoFlattened->getBlockId():
$this->coralType = $coralTypeFlag === BlockLegacyMetadata::CORAL_FAN_HANG_TUBE ? CoralType::TUBE() : CoralType::BRAIN();
break;
case $this->idInfo->getAdditionalId(0):
case $this->idInfoFlattened->getAdditionalId(0):
$this->coralType = $coralTypeFlag === BlockLegacyMetadata::CORAL_FAN_HANG2_BUBBLE ? CoralType::BUBBLE() : CoralType::FIRE();
break;
case $this->idInfo->getAdditionalId(1):
case $this->idInfoFlattened->getAdditionalId(1):
if($coralTypeFlag !== BlockLegacyMetadata::CORAL_FAN_HANG3_HORN){
throw new InvalidBlockStateException("Invalid CORAL_FAN_HANG3 type");
}
@ -73,11 +74,11 @@ final class WallCoralFan extends BaseCoral{
public function getId() : int{
if($this->coralType->equals(CoralType::TUBE()) || $this->coralType->equals(CoralType::BRAIN())){
return $this->idInfo->getBlockId();
return $this->idInfoFlattened->getBlockId();
}elseif($this->coralType->equals(CoralType::BUBBLE()) || $this->coralType->equals(CoralType::FIRE())){
return $this->idInfo->getAdditionalId(0);
return $this->idInfoFlattened->getAdditionalId(0);
}elseif($this->coralType->equals(CoralType::HORN())){
return $this->idInfo->getAdditionalId(1);
return $this->idInfoFlattened->getAdditionalId(1);
}
throw new AssumptionFailedError("All types of coral should be covered");
}