mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-19 20:24:29 +00:00
Clean up abhorrent mess of Slab placement code
This commit is contained in:
parent
35d51570be
commit
e038c4295d
@ -78,48 +78,25 @@ 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->isSameType($this) and $blockClicked->top){
|
||||
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||
/* note these conditions can't be merged, since one targets clicked and the other replace */
|
||||
|
||||
return true;
|
||||
}elseif($blockReplace->isSameType($this)){
|
||||
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||
|
||||
return true;
|
||||
}else{
|
||||
$this->top = true;
|
||||
}
|
||||
}elseif($face === Facing::UP){
|
||||
if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and !$blockClicked->top){
|
||||
$this->getLevel()->setBlock($blockClicked, $this->getDouble());
|
||||
|
||||
return true;
|
||||
}elseif($blockReplace->isSameType($this)){
|
||||
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||
|
||||
return true;
|
||||
}
|
||||
}else{ //TODO: collision
|
||||
if($blockReplace->getId() === $this->getId()){
|
||||
if($blockReplace->getVariant() === $this->variant){
|
||||
$this->getLevel()->setBlock($blockReplace, $this->getDouble());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}else{
|
||||
if($clickVector->y > 0.5){
|
||||
$this->top = true;
|
||||
}
|
||||
}
|
||||
if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and (
|
||||
($face === Facing::DOWN and $blockClicked->top) or //Bottom face of top slab
|
||||
($face === Facing::UP and !$blockClicked->top) //Top face of bottom slab
|
||||
)){
|
||||
return $this->level->setBlock($blockClicked, $this->getDouble());
|
||||
}
|
||||
|
||||
if($blockReplace->getId() === $this->getId() and $blockClicked->getVariant() !== $this->variant){
|
||||
return false;
|
||||
if($blockReplace instanceof Slab and $blockReplace->isSameType($this) and (
|
||||
($blockReplace->top and $clickVector->y <= 0.5) or
|
||||
(!$blockReplace->top and $clickVector->y >= 0.5)
|
||||
)){
|
||||
//Clicked in empty half of existing slab
|
||||
return $this->level->setBlock($blockReplace, $this->getDouble());
|
||||
}
|
||||
|
||||
$this->top = ($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN;
|
||||
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user