mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-24 06:24:41 +00:00
Slab: slight reduction of code repetition
This commit is contained in:
parent
73f1480e10
commit
8910c93de1
@ -57,6 +57,10 @@ abstract class Slab extends Transparent{
|
|||||||
return $this->doubleId;
|
return $this->doubleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getDouble() : Block{
|
||||||
|
return BlockFactory::get($this->doubleId, $this->variant);
|
||||||
|
}
|
||||||
|
|
||||||
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
||||||
if(parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock)){
|
if(parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock)){
|
||||||
return true;
|
return true;
|
||||||
@ -76,11 +80,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->getId() === $this->getId() and $blockClicked->top and $blockClicked->getVariant() === $this->variant){
|
||||||
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->variant));
|
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->variant));
|
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
@ -88,18 +92,18 @@ abstract class Slab extends Transparent{
|
|||||||
}
|
}
|
||||||
}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->getId() === $this->getId() and !$blockClicked->top and $blockClicked->getVariant() === $this->variant){
|
||||||
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->variant));
|
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
}elseif($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->variant){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->variant));
|
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else{ //TODO: collision
|
}else{ //TODO: collision
|
||||||
if($blockReplace->getId() === $this->getId()){
|
if($blockReplace->getId() === $this->getId()){
|
||||||
if($blockReplace->getVariant() === $this->variant){
|
if($blockReplace->getVariant() === $this->variant){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->variant));
|
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user