diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 60c2920450..75167523e8 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -166,6 +166,17 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->variant; } + /** + * Returns whether the given block has an equivalent type to this one. + * + * @param Block $other + * + * @return bool + */ + public function isSameType(Block $other) : bool{ + return $this->getId() === $other->getId() and $this->getVariant() === $other->getVariant(); + } + /** * AKA: Block->isPlaceable * @return bool diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index a4ccd0522f..323f9f5445 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -83,7 +83,7 @@ class Chest extends Transparent{ Bearing::toFacing(Bearing::rotate($player->getDirection(), 1)) ] as $side){ $c = $this->getSide($side); - if($c instanceof Chest and $c->getId() === $this->getId() and $c->facing === $this->facing){ + if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ $tile = $this->getLevel()->getTile($c); if($tile instanceof TileChest and !$tile->isPaired()){ $chest = $tile; diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 1d081680fa..68456e4e45 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -75,7 +75,7 @@ abstract class Door extends Transparent{ */ private function updateStateFromOtherHalf() : void{ $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); - if($other instanceof Door and $other->getId() === $this->getId()){ + if($other instanceof Door and $other->isSameType($this)){ if($this->top){ $this->facing = $other->facing; $this->open = $other->open; @@ -165,7 +165,7 @@ abstract class Door extends Transparent{ $next = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, false)); $next2 = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, true)); - if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge + if($next->isSameType($this) or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge $this->hingeRight = true; } @@ -185,7 +185,7 @@ abstract class Door extends Transparent{ $this->open = !$this->open; $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); - if($other instanceof Door and $this->getId() === $other->getId()){ + if($other instanceof Door and $other->isSameType($this)){ $other->open = $this->open; $this->level->setBlock($other, $other); } @@ -210,7 +210,7 @@ abstract class Door extends Transparent{ public function getAffectedBlocks() : array{ $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); - if($other->getId() === $this->getId()){ + if($other->isSameType($this)){ return [$this, $other]; } return parent::getAffectedBlocks(); diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index caecc5c0a2..fb4266c174 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -74,8 +74,7 @@ class DoublePlant extends Flowable{ return ( $other instanceof DoublePlant and - $other->getId() === $this->getId() and - $other->getVariant() === $this->variant and + $other->isSameType($this) and $other->top !== $this->top ); } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index ff8d20587a..caa43e6925 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -111,7 +111,7 @@ abstract class Liquid extends Transparent{ } protected function getEffectiveFlowDecay(Block $block) : int{ - if(!($block instanceof Liquid) or $block->getId() !== $this->getId()){ + if(!($block instanceof Liquid) or !$block->isSameType($this)){ return -1; } @@ -410,7 +410,7 @@ abstract class Liquid extends Transparent{ } private function getSmallestFlowDecay(Block $block, int $decay) : int{ - if(!($block instanceof Liquid) or $block->getId() !== $this->getId()){ + if(!($block instanceof Liquid) or !$block->isSameType($this)){ return $decay; } diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 8c52eb20dc..f138d1c972 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -66,7 +66,7 @@ abstract class Slab extends Transparent{ return true; } - if($blockReplace instanceof Slab and $blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){ + if($blockReplace instanceof Slab and $blockReplace->isSameType($this)){ if($blockReplace->top){ //Trying to combine with top slab return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP); }else{ @@ -79,11 +79,11 @@ abstract class Slab extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($face === Facing::DOWN){ - if($blockClicked instanceof Slab and $blockClicked->getId() === $this->getId() and $blockClicked->top and $blockClicked->getVariant() === $this->variant){ + if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and $blockClicked->top){ $this->getLevel()->setBlock($blockClicked, $this->getDouble()); return true; - }elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){ + }elseif($blockReplace->isSameType($this)){ $this->getLevel()->setBlock($blockReplace, $this->getDouble()); return true; @@ -91,11 +91,11 @@ abstract class Slab extends Transparent{ $this->top = true; } }elseif($face === Facing::UP){ - if($blockClicked instanceof Slab and $blockClicked->getId() === $this->getId() and !$blockClicked->top and $blockClicked->getVariant() === $this->variant){ + if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and !$blockClicked->top){ $this->getLevel()->setBlock($blockClicked, $this->getDouble()); return true; - }elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){ + }elseif($blockReplace->isSameType($this)){ $this->getLevel()->setBlock($blockReplace, $this->getDouble()); return true; diff --git a/src/pocketmine/block/Stem.php b/src/pocketmine/block/Stem.php index 9d105380fe..2722e6c834 100644 --- a/src/pocketmine/block/Stem.php +++ b/src/pocketmine/block/Stem.php @@ -45,8 +45,7 @@ abstract class Stem extends Crops{ }else{ $grow = $this->getPlant(); foreach(Facing::HORIZONTAL as $side){ - $b = $this->getSide($side); - if($b->getId() === $grow->getId()){ + if($this->getSide($side)->isSameType($grow)){ return; } } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 9209100dc4..2ab1cc9a63 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1671,7 +1671,7 @@ class Level implements ChunkManager, Metadatable{ foreach($tag as $v){ if($v instanceof StringTag){ $entry = ItemFactory::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock()->getId() === $target->getId()){ + if($entry->getId() > 0 and $entry->getBlock()->isSameType($target)){ $canBreak = true; break; } @@ -1833,7 +1833,7 @@ class Level implements ChunkManager, Metadatable{ foreach($tag as $v){ if($v instanceof StringTag){ $entry = ItemFactory::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock()->getId() === $blockClicked->getId()){ + if($entry->getId() > 0 and $entry->getBlock()->isSameType($blockClicked)){ $canPlace = true; break; }