mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Add and make use of Block->isSameType()
This commit is contained in:
parent
8910c93de1
commit
35d51570be
@ -166,6 +166,17 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
return $this->variant;
|
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
|
* AKA: Block->isPlaceable
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -83,7 +83,7 @@ class Chest extends Transparent{
|
|||||||
Bearing::toFacing(Bearing::rotate($player->getDirection(), 1))
|
Bearing::toFacing(Bearing::rotate($player->getDirection(), 1))
|
||||||
] as $side){
|
] as $side){
|
||||||
$c = $this->getSide($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);
|
$tile = $this->getLevel()->getTile($c);
|
||||||
if($tile instanceof TileChest and !$tile->isPaired()){
|
if($tile instanceof TileChest and !$tile->isPaired()){
|
||||||
$chest = $tile;
|
$chest = $tile;
|
||||||
|
@ -75,7 +75,7 @@ abstract class Door extends Transparent{
|
|||||||
*/
|
*/
|
||||||
private function updateStateFromOtherHalf() : void{
|
private function updateStateFromOtherHalf() : void{
|
||||||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
$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){
|
if($this->top){
|
||||||
$this->facing = $other->facing;
|
$this->facing = $other->facing;
|
||||||
$this->open = $other->open;
|
$this->open = $other->open;
|
||||||
@ -165,7 +165,7 @@ abstract class Door extends Transparent{
|
|||||||
$next = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, false));
|
$next = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, false));
|
||||||
$next2 = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, true));
|
$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;
|
$this->hingeRight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ abstract class Door extends Transparent{
|
|||||||
$this->open = !$this->open;
|
$this->open = !$this->open;
|
||||||
|
|
||||||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
$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;
|
$other->open = $this->open;
|
||||||
$this->level->setBlock($other, $other);
|
$this->level->setBlock($other, $other);
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ abstract class Door extends Transparent{
|
|||||||
|
|
||||||
public function getAffectedBlocks() : array{
|
public function getAffectedBlocks() : array{
|
||||||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
||||||
if($other->getId() === $this->getId()){
|
if($other->isSameType($this)){
|
||||||
return [$this, $other];
|
return [$this, $other];
|
||||||
}
|
}
|
||||||
return parent::getAffectedBlocks();
|
return parent::getAffectedBlocks();
|
||||||
|
@ -74,8 +74,7 @@ class DoublePlant extends Flowable{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
$other instanceof DoublePlant and
|
$other instanceof DoublePlant and
|
||||||
$other->getId() === $this->getId() and
|
$other->isSameType($this) and
|
||||||
$other->getVariant() === $this->variant and
|
|
||||||
$other->top !== $this->top
|
$other->top !== $this->top
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ abstract class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function getEffectiveFlowDecay(Block $block) : int{
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +410,7 @@ abstract class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getSmallestFlowDecay(Block $block, int $decay) : int{
|
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;
|
return $decay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ abstract class Slab extends Transparent{
|
|||||||
return true;
|
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
|
if($blockReplace->top){ //Trying to combine with top slab
|
||||||
return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP);
|
return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP);
|
||||||
}else{
|
}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{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||||
if($face === Facing::DOWN){
|
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());
|
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
}elseif($blockReplace->isSameType($this)){
|
||||||
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -91,11 +91,11 @@ abstract class Slab extends Transparent{
|
|||||||
$this->top = true;
|
$this->top = true;
|
||||||
}
|
}
|
||||||
}elseif($face === Facing::UP){
|
}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());
|
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
}elseif($blockReplace->isSameType($this)){
|
||||||
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -45,8 +45,7 @@ abstract class Stem extends Crops{
|
|||||||
}else{
|
}else{
|
||||||
$grow = $this->getPlant();
|
$grow = $this->getPlant();
|
||||||
foreach(Facing::HORIZONTAL as $side){
|
foreach(Facing::HORIZONTAL as $side){
|
||||||
$b = $this->getSide($side);
|
if($this->getSide($side)->isSameType($grow)){
|
||||||
if($b->getId() === $grow->getId()){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1671,7 +1671,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
foreach($tag as $v){
|
foreach($tag as $v){
|
||||||
if($v instanceof StringTag){
|
if($v instanceof StringTag){
|
||||||
$entry = ItemFactory::fromString($v->getValue());
|
$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;
|
$canBreak = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1833,7 +1833,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
foreach($tag as $v){
|
foreach($tag as $v){
|
||||||
if($v instanceof StringTag){
|
if($v instanceof StringTag){
|
||||||
$entry = ItemFactory::fromString($v->getValue());
|
$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;
|
$canPlace = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user